Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
日本語の概要は準備中です。原文の説明を表示しています。
Nonlinear optimization with CasADi and IPOPT solver. Use when building and solving NLP problems: defining symbolic variables, adding nonlinear constraints, setting solver options, handling multiple initializations, and extracting solutions. Covers power systems optimization patterns including per-unit scaling and complex number formulations.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
CasADi is a symbolic framework for nonlinear optimization. IPOPT is an interior-point solver for large-scale NLP.
apt-get update -qq && apt-get install -y -qq libgfortran5
pip install numpy==1.26.4 casadi==3.6.7
import casadi as ca
n_bus, n_gen = 100, 20
Vm = ca.MX.sym("Vm", n_bus) # Voltage magnitudes
Va = ca.MX.sym("Va", n_bus) # Voltage angles (radians)
Pg = ca.MX.sym("Pg", n_gen) # Real power
Qg = ca.MX.sym("Qg", n_gen) # Reactive power
# Stack into single vector for solver
x = ca.vertcat(Vm, Va, Pg, Qg)
Build symbolic expression:
# Quadratic cost: sum of c2*P^2 + c1*P + c0
obj = ca.MX(0)
for k in range(n_gen):
obj += c2[k] * Pg[k]**2 + c1[k] * Pg[k] + c0[k]
Collect constraints in lists with bounds:
g_expr = [] # Constraint expressions
lbg = [] # Lower bounds
ubg = [] # Upper bounds
# Equality constraint: g(x) = 0
g_expr.append(some_expression)
lbg.append(0.0)
ubg.append(0.0)
# Inequality constraint: g(x) <= limit
g_expr.append(another_expression)
lbg.append(-ca.inf)
ubg.append(limit)
# Two-sided: lo <= g(x) <= hi
g_expr.append(bounded_expression)
lbg.append(lo)
ubg.append(hi)
g = ca.vertcat(*g_expr)
# Stack bounds matching variable order
lbx = np.concatenate([Vm_min, Va_min, Pg_min, Qg_min]).tolist()
ubx = np.concatenate([Vm_max, Va_max, Pg_max, Qg_max]).tolist()
nlp = {"x": x, "f": obj, "g": g}
opts = {
"ipopt.print_level": 0,
"ipopt.max_iter": 2000,
"ipopt.tol": 1e-7,
"ipopt.acceptable_tol": 1e-5,
"ipopt.mu_strategy": "adaptive",
"print_time": False,
}
solver = ca.nlpsol("solver", "ipopt", nlp, opts)
sol = solver(x0=x0, lbx=lbx, ubx=ubx, lbg=lbg, ubg=ubg)
x_opt = np.array(sol["x"]).flatten()
obj_val = float(sol["f"])
| Option | Default | Recommendation | Notes |
|---|---|---|---|
tol | 1e-8 | 1e-7 | Convergence tolerance |
acceptable_tol | 1e-6 | 1e-5 | Fallback if tol not reached |
max_iter | 3000 | 2000 | Increase for hard problems |
mu_strategy | monotone | adaptive | Better for nonconvex |
print_level | 5 | 0 | Quiet output |
Nonlinear solvers are sensitive to starting points. Use multiple initializations:
initializations = [x0_from_data, x0_flat_start]
best_sol = None
for x0 in initializations:
try:
sol = solver(x0=x0, lbx=lbx, ubx=ubx, lbg=lbg, ubg=ubg)
if best_sol is None or float(sol["f"]) < float(best_sol["f"]):
best_sol = sol
except Exception:
continue
if best_sol is None:
raise RuntimeError("Solver failed from all initializations")
Good initialization strategies:
x_opt = np.array(sol["x"]).flatten()
# Unpack by slicing (must match variable order)
Vm_sol = x_opt[:n_bus]
Va_sol = x_opt[n_bus:2*n_bus]
Pg_sol = x_opt[2*n_bus:2*n_bus+n_gen]
Qg_sol = x_opt[2*n_bus+n_gen:]
Work in per-unit internally, convert for output:
baseMVA = 100.0
Pg_pu = Pg_MW / baseMVA # Input conversion
Pg_MW = Pg_pu * baseMVA # Output conversion
Cost functions often expect MW, not per-unit - check the formulation.
Power system bus numbers may not be contiguous:
bus_id_to_idx = {int(bus[i, 0]): i for i in range(n_bus)}
gen_bus_idx = bus_id_to_idx[int(gen_row[0])]
Pg_bus = [ca.MX(0) for _ in range(n_bus)]
for k in range(n_gen):
bus_idx = gen_bus_idx[k]
Pg_bus[bus_idx] += Pg[k]
tap=0 to mean 1.0, not zeroまだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
日本語の概要は準備中です。原文の説明を表示しています。
AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields. Use when computing branch flows in either direction, aggregating bus injections for nodal balance, checking MVA (rateA) limits, computing branch loading %, or debugging sign/units issues in AC power flow.
日本語の概要は準備中です。原文の説明を表示しています。
Redact text from PDF documents for blind review anonymization
日本語の概要は準備中です。原文の説明を表示しています。
Use when checking simplified ADA-derived plan-view bathroom accessibility constraints such as turning space, door clear width, toilet centerline, grab bars, and lavatory knee/toe clearance.
日本語の概要は準備中です。原文の説明を表示しています。
Analyze failed GitHub Action jobs for a pull request.
日本語の概要は準備中です。原文の説明を表示しています。
Use when extracting plan-view architectural geometry from DXF files with semantic CAD layers, especially when outputs must normalize rooms, doors, fixtures, clearances, and grab bars into machine-checkable JSON.
日本語の概要は準備中です。原文の説明を表示しています。