ConvexOptimization[f,cons,vars]
凸制約条件 cons に従って凸目的関数 f を最小にする変数 vars の値を求める.
ConvexOptimization[…,"prop"]
解のどの特性"prop"を返すべきかを指定する.
ConvexOptimization
ConvexOptimization[f,cons,vars]
凸制約条件 cons に従って凸目的関数 f を最小にする変数 vars の値を求める.
ConvexOptimization[…,"prop"]
解のどの特性"prop"を返すべきかを指定する.
詳細とオプション
- 凸最適化は凸制約条件を持つ凸関数のための大域的非線形最適化である.凸問題については,大域的解が求まる.
- 凸最適化には,線形計画法,線形分数最適化,二次計画法,二次錐計画問題,半正定値計画問題,円錐最適化を含む,最適化の多くの形が含まれる.
が凸なら,ConvexOptimization[-g,cons,vars]は g を最大にする.- 凸最適化は次の問題を解く
を求める. -
最小化 
制約条件 
ただし 
- cons には
の形式の等式条件が含まれるかもしれない. - 混合整数凸最適化は,問題を解く
および
を求める. -
最小化 
制約条件 
ただし 
- 目的関数が実数値のとき,ConvexOptimizationは
の問題をまず実変数
に変換することで解く.ただし,
かつ
である. - 変数指定 vars は,次の形のいずれかで変数を与える要素のリストでなければならない.
-
v
という名前の変数と推測される次元v∈Reals 実数のスカラー変数 v∈Integers 整数のスカラー変数 v∈Complexes 複素数のスカラー変数 v∈ℛ 幾何学領域
に制限されたベクトル変数v∈Vectors[n,dom]
,
または
のベクトル変数v∈Matrices[{m,n},dom]
,
,
の行列変数 - ConvexOptimizationは,最小化問題を解くための効率的なメソッドを見付けるために必要な変換を自動的に行う.
- 解かれた主最小化問題には関連する最大化問題(ラグランジュ双対問題)がある.双対最大値は常に主最小値以下であるので,下限を与える.双対マキシマイザは,最小値の制約上限に対する感度を含む,主問題についての情報を与える.
- 次は,可能な解の特性"prop" である.
-
"PrimalMinimizer" 
を最小化する変数値のリスト"PrimalMinimizerRules" 
を最小化する変数の値 vars={v1,…}"PrimalMinimizerVector" 
を最小化するベクトル"PrimalMinimumValue" 
最小値
"DualMaximizer" 
双対問題を最大にするベクトル "DualMaximumValue" 双対最大値 "DualityGap" 
双対最適値と主最適値の差 "Slack" 
不等式制約を等式に変換するベクトル {"prop1","prop2",…} いくつかの解の特性 - 次のオプションが使用できる.
-
MaxIterations Automatic 使用する最大反復回数 Method Automatic 使用するメソッド PerformanceGoal $PerformanceGoal 最適化しようとするパフォーマンスの局面 Tolerance Automatic 内部の比較で使用する許容度 WorkingPrecision MachinePrecision 内部計算で使用する精度 - オプションMethodmethod を使って使用するメソッドが指定できる.以下は使用可能なメソッドである.
-
Automatic メソッドを自動選択する solver 可能な場合は,問題を解くために solver が使えるようにするために問題を変換する "SCS" SCS(分割円錐ソルバ)ライブラリ "CSDP" CSDP(COIN半定値計画)ライブラリ "DSDP" DSDP(半定値計画)ライブラリ "MOSEK" 商用MOSEK凸最適化ソルバ "Gurobi" 商用Gurobi線形・二次最適化ソルバ "Xpress" 商用Xpress形・二次最適化ソルバ - Methodsolver を使って,使われる双対形式が solver についてドキュメントされている形式と一致するように,特定のソルバを使うように指定してもよい.使用可能なソルバは,LinearOptimization,LinearFractionalOptimization,QuadraticOptimization,SecondOrderConeOptimization,SemidefiniteOptimization,ConicOptimization,GeometricOptimizationである.
例題
すべて開く すべて閉じる例 (2)
ConvexOptimization[Abs[x + 2 y], {x + y == 1., x - y ≤ 2}, {x, y}]いくつかの要素についての制約条件に従って行列のノルムを最小化する:
ConvexOptimization[Norm[x], {Indexed[x, {1, 2}] == 1, Indexed[x, {2, 3}] == 2, Indexed[x, {1, 1}] ≤ Indexed[3x, {2, 1}] + Indexed[2x, {1, 3}], Indexed[x, {2, 2}] == Indexed[x, {1, 1}] + 7}, {x∈Matrices[{2, 3}, Reals]}]スコープ (28)
基本的な用法 (12)
ConvexOptimization[x^2 + y^2, {x + y == 1, x ^ 2 + 5y ^ 2 < 1}, {x, y}]線形不等式条件の中にはVectorGreaterEqualで表せるものがある:
ConvexOptimization[x + y, VectorGreaterEqual[{{x + 2y, x}, {3, -1}}], {x, y}]
v>=
または\[VectorGreaterEqual]を使ってベクトル不等式の符号を入力する:
ConvexOptimization[x + y, {x + 2y, x}{3, -1}, {x, y}]ConvexOptimization[x + y, {x + 2y ≥ 3, x ≥ -1}, {x, y}]ConvexOptimization[{1, 1}.v, {{1, 2}, {1, 0}}.v{3, -1}, v]
に縫い込まれている可能性があるので,不等式
は
と同じではないかもしれない:
ConvexOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x + {-3, 1}0, x]ConvexOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x{3, -1}, x]
への意図しない縫込みを避けるためにはInactive[Plus]を使うとよい:
ConvexOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x + {-3, 1}0, x]パラメータが一定の等式を使って意図しない
への縫込みを避ける:
parEqs = {a == {{1, 2}, {1, 0}}, b == {3, -1}};ConvexOptimization[{1, 1}.x, {parEqs, a.x + b0}, x]VectorGreaterEqualは"NonNegativeCone"についての円錐不等式を表す:
constraint = VectorGreaterEqual[{{{1, 2}, {1, 0}}.v, {3, -1}}, "NonNegativeCone"]円錐の次元を明示的に指定するためには{"NonNegativeCone",n}を使う:
constraint = VectorGreaterEqual[{{{1, 2}, {1, 0}}.v, {3, -1}}, {"NonNegativeCone", 2}]ConvexOptimization[{1, 1}.v, constraint, v]ConvexOptimization[x + 2y, x^2 + y^2 ≤ 9, {x, y}]"NormCone"の錐不等式を使うことで制約条件
を指定する:
VectorGreaterEqual[{{x, y, 3}, 0}, {"NormCone", 3}]ConvexOptimization[x + 2y, {x, y, 3}Underscript[, {"NormCone", 3}]0, {x, y}]constraint = VectorGreaterEqual[{{{x, 1}, {1, y}}, 0}, {"SemidefiniteCone", 2}]ConvexOptimization[x + 2y, constraint, {x, y}]ベクトル変数
とIndexed[x,i]を使って個々の成分を指定する:
ConvexOptimization[{1, 2}.x, (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x]ベクトル変数の次元が曖昧なときは,Vectors[n,Reals]を使って指定する:
ConvexOptimization[Indexed[x, {1}] + 2Indexed[x, {2}], (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x]ConvexOptimization[Indexed[x, {1}] + Indexed[2x, {2}], (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x∈Vectors[2, Reals]]NonNegativeReals (
)を使って非負の制約条件を指定する:
ConvexOptimization[{-1, -2}.x, Norm[x] ≤ 1, x∈Vectors[2, NonNegativeReals]]ConvexOptimization[{-1, -2}.x, {Norm[x] ≤ 1, x0}, x]周囲長が最大で1で縦が最大で横の半分である長方形の面積を最大にする:
ConvexOptimization[(1/w h), {2w + 2h ≤ 1, h ≤ (1/2)w}, {h, w}]
と
が正なら,この問題はGeometricOptimization法で解くことができる:
ConvexOptimization[(1/w h), {2w + 2h ≤ 1, h ≤ (1/2)w, h ≥ 0, w ≥ 0}, {h, w}]正であると暗黙のうちに仮定してGeometricOptimization法を使う:
ConvexOptimization[(1/w h), {2w + 2h ≤ 1, h ≤ (1/2)w}, {h, w}, Method -> GeometricOptimization]整数変数 (4)
Integersを使って整数変数を指定する:
ConvexOptimization[x ^ 2 + y ^ 2, {x + 2y ≥ 2}, {x∈Integers, y∈Integers}]Vectors[n,Integers]を使ってベクトル変数上に整数領域を指定する:
ConvexOptimization[Total[x], {a == {{1, 2}, {1, 0}}, b == {3, -2},
a.xb}, {x∈Vectors[2, Integers]}]NonNegativeIntegers (
)を使って非負の整数領域条件を指定する:
ConvexOptimization[x + 2y, {x^2 + 2y^2 ≤ 3, x + y == 2, x∈NonNegativeIntegers}, {x, y}]NonPositiveIntegers (
)を使って非正の整数領域条件を指定する:
ConvexOptimization[-x + y, {x + 2y ≥ 3, x∈NonPositiveIntegers}, {x, y}]複素変数 (8)
Complexesを使って複素変数を指定する:
ConvexOptimization[Re[z] + Im[z], Abs[z] ≤ 2, z∈ Complexes]constraints = VectorGreaterEqual[{(-1 + 2I) z, -3}] && VectorGreaterEqual[{z, I}]VectorGreaterEqual /@ ComplexExpand[constraints[[All, 1]] /. z -> x + I y]realConstraints = -x - 2y ≥ -3 && 2 x - y ≥ 0 && x ≥ 0 && y ≥ 1;RegionPlot[realConstraints, {x, 0.5, 1}, {y, 1, 1.2}]ConvexOptimization[Re[z], constraints, Element[z, Complexes]]ConvexOptimization[x, realConstraints, {x, y}]二次目的関数
をエルミート行列
および実数値変数と一緒に使う:
{q, c} = {{{2, 1 + I}, {1 - I, 1}}, {2, 3}};
ConvexOptimization[(1 / 2) * x.q.x + c.x, {}, x∈Vectors[2, Reals]]目的関数(1/2)Inactive[Dot][Conjugate[x],q,x]をエルミート行列
および複素変数と一緒に使う:
q = {{1, I}, {-I, 2}};
ConvexOptimization[(1 / 2) * Inactive[Dot][Conjugate[x], q, x] , {{1, I}.x1 + I}, x∈Vectors[2, Complexes]]{q, c} = {{{2, 1 + I}, {1 - I, 1}}, {2, 3}};
ConvexOptimization[{1, 2}.x, (1 / 2) * x.q.x + c.x1, x∈Vectors[2, Reals]]制約条件(1/2)Inactive[Dot][Conjugate[x],q,x]d をエルミート行列
および複素変数と一緒に使う:
q = {{3, 1 + I}, {1 - I, 2}};
ConvexOptimization[{1, 2}.Re[x], {(1 / 2) * Inactive[Dot][Conjugate[x], q, x]5}, x∈Vectors[2, Complexes]]行列
が半正定値になるような,最小で2ノルム(最大特異値)のエルミート行列を求める:
ConvexOptimization[Norm[x], VectorGreaterEqual[{x, {{1, I}, {-I, 1}}}, "SemidefiniteCone"], Element[x, Matrices[{2, 2}, Complexes, Hermitian]]]Norm[x] /. %線形行列不等式制約
をエルミート行列あるいは実数対称行列と一緒に使う:
Subscript[a, 0] = (| | |
| ----- | ----- |
| 0 | 1 + I |
| 1 - I | 0 |);Subscript[a, 1] = (| | |
| - | - |
| 1 | 0 |
| 0 | 0 |);Subscript[a, 2] = (| | |
| - | - |
| 0 | 0 |
| 0 | 1 |);線形行列不等式の変数は,総和がエルミートのままであるためには実数でなければならない:
c = {1, 2};
ConvexOptimization[c.v, {Subscript[a, 1], Subscript[a, 2]}.vUnderscript[, {"SemidefiniteCone", 2}]-Subscript[a, 0], v∈Vectors[2, Reals]]主モデル特性 (1)
triangle = {x ≥ 0, y ≥ 0, x + 2y ≤ 2};
disk = x ^ 2 + y ^ 2 ≤ 1;sol = ConvexOptimization[-(x + y), {triangle, disk}, {x, y}]{xmin, ymin} = ConvexOptimization[-(x + y), {triangle, disk}, {x, y}, "PrimalMinimizer"]minval = ConvexOptimization[-(x + y), {triangle, disk}, {x, y}, "PrimalMinimumValue"]RegionPlot[{x ≥ 0 && y ≥ 0 && x + 2 y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, 0, 2}, {y, 0, 1}, AspectRatio -> Automatic, Epilog -> {Red, PointSize[0.025], Point[{x, y} /. sol]}]双対モデル特性 (3)
c = {1, 1};
Subscript[a, 0] = {{1., -1.}}; Subscript[b, 0] = {0};
Subscript[a, 1] = {{1., 0}, {0, 1}, {0, 0}};Subscript[b, 1] = {0, 0, 1};psol = ConvexOptimization[c.x, {Subscript[a, 0].x + Subscript[b, 0] == 0, Subscript[a, 1].x + Subscript[b, 1]Underscript[, {"NormCone", 3}]0}, x]dsol = ConvexOptimization[Subscript[b, 0].Subscript[λ, 0] + Subscript[b, 1].Subscript[λ, 1] , {Transpose[Subscript[a, 0]].Subscript[λ, 0] + Transpose[Subscript[a, 1]].Subscript[λ, 1] == c, Subscript[λ, 1]Underscript[, {"NormCone", 3}]0}, {Subscript[λ, 0], Subscript[λ, 1]}]{c.x /. psol, -Subscript[b, 0].Subscript[λ, 0] - Subscript[b, 1].Subscript[λ, 1] /. dsol}これは,0の双対ギャップを持つことに等しい.一般に,最適点で
である:
ConvexOptimization[c.x, {Subscript[a, 0].x + Subscript[b, 0] == 0, Subscript[a, 1].x + Subscript[b, 1]Underscript[, {"NormCone", 3}]0}, x, "DualityGap"]c = {1, 1};
Subscript[a, 0] = {{1., -1.}}; Subscript[b, 0] = {0};
Subscript[a, 1] = {{1., 0}, {0, 1}, {0, 0}};Subscript[b, 1] = {0, 0, 1};ConvexOptimization[c.x, {Subscript[a, 0].x + Subscript[b, 0] == 0, Subscript[a, 1].x + Subscript[b, 1]Underscript[, {"NormCone", 3}]0}, x, "DualMaximumValue"]ConicOptimization[Indexed[x, {1}] + Indexed[x, {2}], {Indexed[x, {1}] == Indexed[x, {2}], Indexed[x, {1}]^2 + Indexed[x, {2}]^2 ≤ 1}, {Indexed[x, {1}], Indexed[x, {2}]}, "DualMaximumValue"]dualMaximizer = ConicOptimization[Indexed[x, {1}] + Indexed[x, {2}], {Indexed[x, {1}] == Indexed[x, {2}], Indexed[x, {1}]^2 + Indexed[x, {2}]^2 ≤ 1}, {Indexed[x, {1}], Indexed[x, {2}]}, "DualMaximizer"]双対マキシマイザベクトル分割は双対円錐の数と次元をマッチする:
{Subscript[λ, 0], Subscript[λ, 1]} = dualMaximizer特定の問題タイプのソルバに対して双対形式を得るために,これをメソッドオプションとして指定する:
ConvexOptimization[x - y, {x ≥ 0, y ≥ 0, x + 2 y ≤ 3}, {x, y}, "DualMaximizer", Method -> LinearOptimization]LinearOptimization[x - y, {x ≥ 0, y ≥ 0, x + 2 y ≤ 3}, {x, y}, "DualMaximizer"]オプション (13)
Method (8)
ConvexOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "SCS"]ConvexOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "CSDP"]ConvexOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "DSDP"]ConvexOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "IPOPT"]メソッドによってデフォルトの許容範囲が異なるが,これは確度と精度に影響する:
{obj, cons, var} = {-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, y}};
props = {"PrimalMinimumValue", "PrimalMinimizer"};{minval, argmin} = Minimize[obj, cons, var];
exact = {minval, var /. argmin};solSCS = ConvexOptimization[obj, cons, var, props, Method -> "SCS"];solCSDP = ConvexOptimization[obj, cons, var, props, Method -> "CSDP"];solDSDP = ConvexOptimization[obj, cons, var, props, Method -> "DSDP"];solIPOPT = ConvexOptimization[obj, cons, var, props, Method -> "IPOPT"];solSCS - exact"CSDP","DSDP","IPOPT"のデフォルトの許容範囲は
である:
solCSDP - exactsolDSDP - exactsolIPOPT - exact"SCS"法は,指定されるとデフォルトの許容範囲が10-3のSCSライブラリとともに呼び出される:
ConvexOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}, Method -> "SCS"]デフォルトオプションでは,問題は"SCS"法で許容範囲は10-6で解かれる:
ConvexOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}]ConvexOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}, Method -> {"SCS", Tolerance -> 10 ^ -6}]半正定制約条件に変換される制約条件に"CSDP"法または"DSDP"法を使う:
lin = {{1, 0}, {0, 1}, {-1, -2}}.x + {0, 0, 2}Underscript[, {"NonNegativeCone", 3}]0;norm = {{1, 0}, {0, 1}, {0, 0}}.x + {0, 0, 1}Underscript[, {"NormCone", 3}]0;semi = {{{-4, 0}, {0, 0}}, {{0, 0}, {0, -0.8}}}.x + {{5, 1}, {1, 1}}Underscript[, {"SemidefiniteCone", 2}]0;ConvexOptimization[{-1, -1}.x, {lin, norm, semi}, x, Method -> "CSDP"]ConvexOptimization[{-1, -1}.x, {lin, norm, semi}, x, Method -> "DSDP"]"CSDP"および"DSDP"が使えないときに,"IPOPT"法を使って正確な解を得る:
expConstraint = {{1, 0}, {0, 1}, {-1, -2}}.x + {0, 0, 2}Underscript[, "ExponentialCone"]0;powConstraint = {{1, 0}, {0, 1}, {-1, -2}}.x + {1, 0, 2}Underscript[, {"PowerCone", (1/3)}]0;"IPOPT"は"SCS"より正確な結果を生成するが,はるかに遅いことが多い:
AbsoluteTiming[xmin = ConvexOptimization[{1, 1}.x, {expConstraint, powConstraint}, x, Method -> "IPOPT"]]AbsoluteTiming[xmin = ConvexOptimization[{1, 1}.x, {expConstraint, powConstraint}, x, Method -> "SCS"]]PerformanceGoal (1)
オプションPerformanceGoalのデフォルト値は$PerformanceGoalである:
$PerformanceGoalPerformanceGoal"Quality"を使ってより正確な結果を得る:
ConvexOptimization[x + y, {Norm[{x, y}] ≤ Sqrt[2], {x, y}1}, {x, y},
"PrimalMinimumValue", PerformanceGoal -> "Quality"]ConvexOptimization[x + y, {Norm[{x, y}] ≤ Sqrt[2], {x, y}1}, {x, y},
"PrimalMinimumValue", PerformanceGoal -> "Speed"]PerformanceGoal"Speed"を使ってより速く,しかし質を犠牲にして,結果を得る:
n = 100000; {obj, const, vars} = {Total[x] / n, {Norm[x] ≤ Sqrt[n], x1}, x∈Vectors[n]};Timing[resSpeed = ConvexOptimization[obj, const, vars,
"PrimalMinimumValue", PerformanceGoal -> "Speed"];]Timing[resQuality = ConvexOptimization[obj, const, vars,
"PrimalMinimumValue", PerformanceGoal -> "Quality"];]{resSpeed, resQuality}Tolerance (2)
Toleranceの設定を小さくするとより厳密な結果になる:
{obj, cons, var} = {-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, y}};Minimizeで最小値の厳密値を計算する:
exact = Minimize[obj, cons, var][[1]]Toleranceの設定を変えて最小値における誤差を計算する:
err = Table[{tol, Abs[ConvexOptimization[obj, cons, var, "PrimalMinimumValue", Tolerance -> tol] - exact]}, {tol, 10. ^ -Range[7]}]ListLogLogPlot[err, PlotRange -> All, Joined -> True, PlotMarkers -> Automatic]Toleranceの設定を小さくすると答はより厳密になるが,計算時間が長くなるかもしれない:
n = 100000; {obj, const, vars} = {Total[x] / n, {Norm[x] ≤ Sqrt[n], x1}, x∈Vectors[n]};Timing[ptight = ConvexOptimization[obj, const, vars,
"PrimalMinimumValue", Tolerance -> 10^-12];]Timing[ploose = ConvexOptimization[obj, const, vars,
"PrimalMinimumValue", Tolerance -> 10^-2];]{ptight, ploose}WorkingPrecision (2)
デフォルトの作業精度はMachinePrecisionである:
ConvexOptimization[x - y, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}]WorkingPrecisionInfinityを使うと,可能な場合は厳密解が与えられる:
ConvexOptimization[x - y, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}, WorkingPrecision -> ∞]MachinePrecisionと ∞ 以外のWorkingPrecisionは拡張精度をサポートするメソッドを使おうとする:
ConvexOptimization[x - y, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}, WorkingPrecision -> 20]WorkingPrecisionAutomaticを使うと入力問題の精度を使おうとする:
ConvexOptimization[x - y, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}, WorkingPrecision -> Automatic]ConvexOptimization[x - y, {x ≥ 2.0, y ≥ 0.0, x + 2 y ≤ 3.0}, {x, y}, WorkingPrecision -> Automatic]ConvexOptimization[(x - y) ^ 2, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}, WorkingPrecision -> 20]現在のところ,厳密計算で二次目的関数の問題を解く方法はない.要求された精度がサポートされていない場合,計算は機械精度で行われる:
ConvexOptimization[(x - y) ^ 2, {x ≥ 2, y ≥ 0, x + 2 y ≤ 3}, {x, y}, WorkingPrecision -> ∞]アプリケーション (30)
基本的なモデリング変換 (11)
に従って
を最大化する.目的関数を否定することで最大化問題を解く:
ConvexOptimization[-(x + y), {x + y == 3, x ≥ 0, y ≤ 2}, {x, y}]-ConvexOptimization[-(x + y), {x + y == 3, x ≥ 0, y ≤ 2}, {x, y}, "PrimalMinimumValue"]
に従って
を最小化する.制約条件
は凸ではないので,半定値制約条件を使って凸性を明示的にする:
constraint = VectorGreaterEqual[{{{x, 1}, {1, y}}, 0}, "SemidefiniteCone"]左上のすべての部分行列が非負のときかつそのときに限り,行列は半正定値である:
{Det[{{x}}] ≥ 0, Det[{{x, 1}, {1, y}}] ≥ 0}ConvexOptimization[2 x + 3 y, constraint, {x, y}]
のときは
を仮定して,
に従って
を最小化する.補助変数
を使うと,目的は
となるように
を最小化することになる:
{α, β, γ, δ} = {{1, 2}, 1, {-3, 4}, 2};
{a, b} = {{{1, -2}, {-3, 4}}, {-5, -1}};Reduce[Implies[a.{Indexed[x, {1}], Indexed[x, {2}]} + b >= 0, γ.{Indexed[x, {1}], Indexed[x, {2}]} + δ > 0], Reals]シューア補行列の制約条件には,
なら,
のときかつそのときに限りブロック行列
とある.したがって,
のときかつそのときに限り
である.縫込みを避けるための制約条件の構築にInactive[Plus]を使う:
ConvexOptimization[t, {(| | |
| ------- | ------- |
| t | α.x + β |
| α.x + β | γ.x + δ |)Underscript[, {"SemidefiniteCone", 2}]0, a.x + b0}, {t, x∈Vectors[2]}]ConvexOptimization[Norm[x], {x∈Disk[{1, 1}, {2, 1}]}, {x}]エピグラフ変換を使って,線形目的関数と追加変数および制約条件で問題が構築できる:
ConvexOptimization[t, {Norm[x] ≤ t, x∈Disk[{1, 1}, {2, 1}]}, {x, t}]この形式なら,問題はConicOptimizationを使って直接解ける:
ConicOptimization[t, {Norm[x] ≤ t, x∈Disk[{1, 1}, {2, 1}]}, {x, t}]
を最小化する.ただし,
は非減少関数で,代りに
を最小化する.主ミニマイザ
はどちらの問題でも同じままである.
に従って
を最小化することを考える:
f = Function[{s}, Sqrt[s]];{minval, Subscript[z, min]} = ConvexOptimization[x + y, {(| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0, x + y ≥ 0}, {x, y}, {"PrimalMinimumValue", "PrimalMinimizerRules"}]f[minval]ConvexOptimizationは,この変換を自動的に行う:
ConvexOptimization[f[x + y], {(| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0, x + y ≥ 0}, {x, y}, {"PrimalMinimumValue", "PrimalMinimizerRules"}]決定変数
,
に線形に依存する対称行列の最大固有値を最小化する
を求める.
は
と同じ(ただし,
は
の第
固有値)なので,この問題は,線形行列不等式として定式化できる.線形行列関数
を定義する:
A[x_, y_] := (| | |
| -- | -- |
| 2 | -3 |
| -3 | 4 |) + (| | |
| - | - |
| 1 | 2 |
| 2 | 3 |) x + (| | |
| - | - |
| 4 | 5 |
| 5 | 6 |) yA[x, y]//MatrixForm実対称行列
は直交行列
によって
となるように対角化できる.したがって,
のときかつそのときに限り
である.任意の
について
を取ると,
になる.したがって,
のときかつそのときに限り
である.数値的にシミュレーションを行ってこれらの式が等しいことを示す:
eigs = Eigenvalues[A[1., 2.]]data = Table[{λ, λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[1., 2.]}, {λ, RandomReal[{0, 35}, 100]}];
{true, false} = {Cases[data, {λ_, True} :> λ], Cases[data, {λ_, False} :> λ]};NumberLinePlot[{eigs, true, false}, IconizedObject[«Rule»]]res = ConvexOptimization[λ, λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[x, y], {λ, x, y}]モンテカルロシミュレーションを実行して結果の妥当性を確認する:
Min[Table[Max[Eigenvalues[A@@RandomReal[{-10000, 10000}, 2]]], 10000]]決定変数
に線形依存する対称行列
の最小固有値を最大にする
を求める.線形行列関数
を定義する:
A[x_, y_] := (| | |
| ------------- | ------------- |
| x + 4 y + 2 | 2 x + 5 y - 3 |
| 2 x + 5 y - 3 | 3 x + 6 y + 4 |);
は
と等しいので(ただし,
は
の
番目の固有値),この問題は,線形行列不等式として定式化できる.
を最大化するために
を最小化する:
res = ConvexOptimization[-λ,
λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[x, y], {λ, x, y}]モンテカルロシミュレーションを実行して結果の妥当性を確認する:
Max[Table[Min[Eigenvalues[A@@RandomReal[{-10000, 10000}, 2]]], 10000]]決定変数
に線形依存する対称行列
の最大固有値と最小固有値の差を最小にする
を求める.線形行列関数
を定義する:
A[x_, y_] := (| | |
| ------------- | ------------- |
| x + 4 y + 2 | 2 x + 5 y - 3 |
| 2 x + 5 y - 3 | 3 x + 6 y + 4 |);
は
と等しいので(ただし,
は
の第
固有値),この問題は,線形行列不等式として定式化できる.結果の問題を解く:
res = ConvexOptimization[μ - λ, {λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[x, y]Underscript[, {"SemidefiniteCone", 2}]μ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)}, {λ, μ, x, y}]この場合は,最小固有値と最大固有値が一致するので差は0である:
{Eigenvalues[A[x, y] /. res], Chop[μ - λ /. res, 10 ^ -7]}決定変数
に線形依存する対称行列
の(絶対値での)最大固有値を最小化する:
A[x_, y_] := (| | |
| ------------- | ------------- |
| x + 4 y + 2 | 2 x + 5 y - 3 |
| 2 x + 5 y - 3 | 3 x + 6 y + 4 |);最大固有値は
を満足する.
の(絶対値が)最大の負の固有値は
の最大固有値で,
を満足する:
res = ConvexOptimization[λ, {-λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)Underscript[, {"SemidefiniteCone", 2}]A[x, y]Underscript[, {"SemidefiniteCone", 2}]λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)}, {λ, x, y}]Eigenvalues[A[x, y] /. res]決定変数
に線形依存する対称行列
の最大特異値
を最小化する
を求める:
A[x_, y_] := (| | | |
| ----------- | ----------- | ----- |
| 1 + x + 2 y | 2 + 3 y | x + 1 |
| 3 + 5 y | 4 - x + 8 y | 2y |);
の最大特異値
は
の最大固有値の平方根であり,上記の例より,
または
を満足する:
res = ConvexOptimization[σ, **{****{****σ** (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |)**, ****A[x, y]****}****, ****{****A[x, y]****, ****σ** (| | | |
| - | - | - |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |)**}****}** Underscript[, {"SemidefiniteCone", 5}]0, {x, y, **σ**}]f[x_, y_] := Module[{v = SingularValueList[A[x, y]]}, Max[v]];
Show[Plot3D[f[x, y], {x, -10, 10}, {y, -2, 2}], Graphics3D[{Red, PointSize[.05], Point[res[[All, 2]]]}]]楕円体,二次円錐,放物面を含む二次集合
を求め,
かどうかを判定する.ただし,
は対称行列,
はベクトル,
はスカラーである:
{a1, b1, c1} = {{{0.7, 0.68}, {0.68, 0.94}}, {0.35, .42}, 0.12};{a2, b2, c2} = {{{0.13, 0.2}, {0.2, 0.62}}, {.2, .4}, .01};With[{x = {x1, x2}}, RegionPlot[{x.a1.x + 2 b1.x + c1 ≤ 0, x.a2.x + 2 b2.x + c2 ≤ 0}, {x1, -2, 2}, {x2, -2, 2}, PlotLegends -> {Subscript[𝒬, 1], Subscript[𝒬, 2]}, ImageSize -> 100]]集合
が全次元であると仮定すると,S-procedureには
となるような非負の数
が存在するときかつそのときに限り
であるとある.非負の
が存在することを視覚的に見る:
m1 = ArrayFlatten[{{a1, {b1}}, {{b1}, {{c1}}}}];
m2 = ArrayFlatten[{{a2, {b2}}, {{b2}, {{c2}}}}];
Plot[Boole[λm1Underscript[, {"SemidefiniteCone", 3}]m2], {λ, 0, 5}, ImageSize -> Small]実現可能性が問題なので,目的関数として0を使う.λ≥0なので,
である:
ConvexOptimization[0, λ(| | |
| -- | -- |
| a1 | b1 |
| b1 | c1 |)Underscript[, {"SemidefiniteCone", 3}](| | |
| -- | -- |
| a2 | b2 |
| b2 | c2 |), λ]幾何学の問題 (8)
面積4の長方形の対角線の長さを最小にする.ただし,縦の3倍と横を足したものが7未満とする:
ConvexOptimization[Sqrt[w ^ 2 + h ^ 2], {w h == 4, w + 3h ≤ 7, h ≥ 0, w ≥ 0}, {w, h}]中心が
と
で半径が1の2つの円板の最短距離を求める.
を円板1の上の点,
を円板2の上の点とする.目的は,制約条件
に従って
を最小にすることである:
res = ConvexOptimization[Norm[p1 - p2], {c2 == {2, 1}, Norm[p1] ≤ 1, Norm[p2 - c2] ≤ 1}, {p1∈Vectors[2], p2∈Vectors[2]}]Graphics[{{Lighter[Blue], Disk[]}, {Lighter[Red], Disk[{2, 1}]}, {Green, PointSize[0.03], Point[{p1, p2} /. res]}}]EuclideanDistance[p1, p2] /. res表面積が最大で1の楕円体の体積を最大にする主軸
の長さの半分を求める:
volume = (4/3)π a b c;surfaceArea = 4π ((a^pb^p + a^pc^p + b^p c^p/3))^1 / p /. p -> 1.6075;ConvexOptimization[1 / volume, {surfaceArea ≤ 1, a ≥ 0, b ≥ 0, c ≥ 0}, {a, b, c}]以下は球面である.軸の長さについての追加的な制約条件を含めるとこれが変わる:
ConvexOptimization[1 / volume, {surfaceArea ≤ 1, 3b + a ≤ 1, a ≥ 0, b ≥ 0, c ≥ 0}, {a, b, c}]Graphics3D[Ellipsoid[{0, 0, 0}, {a, b, c} /. %]]与えられた領域を包み込む最小の球体の半径
と中心
を求める:
region = [image];constraints = Table[Norm[Inactive[Plus][pi, -c]] ≤ r, {pi, MeshCoordinates[region]}];res = ConvexOptimization[r, constraints, {r, c∈Vectors[3]}]Show[Graphics3D[{Opacity[0.2], Red, Ball[c, r] /. res}], region]包み込んでいる最小の球体はBoundingRegionを使って効率的に求めることができる:
BoundingRegion[region, "MinBall"]凸多面体の解析的中心を求める.解析的中心は制約条件までの距離の積を最大にする点である:
cmesh = ConvexHullMesh[IconizedObject[«With»]];凸多面体の各線分は半平面
の交線として表すことができる.線形不等式を抽出する:
{a, b} = LinearOptimization[0, x∈cmesh, x, "LinearInequalityConstraints"];目的は
を最大にすることである.
を取って目的関数を否定する.変換された目的関数は
である:
objective = Total[Table[-Log[a[[i]].x + b[[i]]], {i, Length[a]}]];補助変数
を使うと,変換された目的は,制約条件
に従う
になる:
res = ConvexOptimization[objective, {}, {x}, Method -> {"SCS", Tolerance -> 10 ^ -7}]Show[cmesh, Graphics[{PointSize[0.02], Point[x /. res]}]]{a1, b1, c1} = {{{0.13, 0.2}, {0.2, 0.62}}, {.2, .4}, .01};
{a2, b2, c2} = {{{0.7, 0.68}, {0.68, 0.94}}, {0.35, .42}, 0.12};S-procedureを使うと,
であるときかつそのときに限り,楕円2が楕円1の部分集合であることがわかる:
subsetConstraint = (| | |
| -- | -- |
| a1 | b1 |
| b1 | c1 |)Underscript[, {"SemidefiniteCone", 3}]τ(| | |
| -- | -- |
| a2 | b2 |
| b2 | c2 |);ConvexOptimization[0, {subsetConstraint, τ ≥ 0}, τ]楕円体を明示的な形に変換し,楕円2が楕円1の中にあることを確認する:
ellipse1 = With[{ai = Inverse[a1]}, Ellipsoid[-ai.b1, ai(b1.ai.b1 - c1)]];
ellipse2 = With[{ai = Inverse[a2]}, Ellipsoid[-ai.b2, ai(b2.ai.b2 - c2)]];Graphics[{{Red, Opacity[0.5], ellipse1}, {Blue, Opacity[0.5], ellipse2}}]{a3, b3, c3} = {{{0.7, 0.68}, {0.68, 0.94}}, {0.45, .42}, 0.12};
ellipse3 = With[{ai = Inverse[a3]}, Ellipsoid[-ai.b3, ai(b3.ai.b3 - c3)]];テストは,楕円体2が楕円体1の部分集合ではなく,この問題は実行不可能であることを示している:
ConvexOptimization[0, {(| | |
| -- | -- |
| a1 | b1 |
| b1 | c1 |)Underscript[, {"SemidefiniteCone", 3}]τ(| | |
| -- | -- |
| a3 | b3 |
| b3 | c3 |), τ ≥ 0}, τ];Graphics[{{Red, Opacity[0.5], ellipse1}, {Blue, Opacity[0.5], ellipse3}}]凸多面体内に収められる
としてパラメータ化される楕円の最大面積を求める:
cmesh = ConvexHullMesh[IconizedObject[«With»]];凸多面体の各線分は,半平面
の交線として表すことができる.線形不等式を抽出する:
segs = MeshPrimitives[cmesh, 1][[All, 1]];
a = segs /. {p_, q_} :> {-1, 1} * Reverse[p - q];
b = MapThread[#1.#2&, {a, segs[[All, 1]]}];半平面にパラメータ化を適用すると
が与えられる.
.したがって,制約条件は
である:
constraints = Table[Norm[a[[i]].c] + a[[i]].d ≤ b[[i]], {i, Length[a]}];面積を最小にするのは
を最小にすることと同じであるが,それは
を最小にすることと同じである:
res = ConvexOptimization[-Tr[c], constraints, {c∈Matrices[{2, 2}], d}]inscribedEllipse = Ellipsoid[d, Transpose[c].c] /. resShow[cmesh, Graphics[{Purple, inscribedEllipse}]]体積を最小にすることで3Dの点集合を含む
としてパラメータ化された最小の楕円体を求める:
pts = IconizedObject[«With»];constraints = Table[Norm[a.pi + b] ≤ 1, {pi, pts}];体積を最小にすることは
を最小にすることに等しいが,これは
を最小にすることに等しい:
res = ConvexOptimization[-Tr[a], {constraints, aUnderscript[, {"SemidefiniteCone", 3}]0}, {a, b∈Vectors[3]}]{Σ, x0} = {Inverse[Transpose[a].a /. res], -LinearSolve[a, b] /. res};
minVolEllipsoid = Ellipsoid[x0, Σ]Graphics3D[{{Opacity[0.3], Red, Ellipsoid[x0, Σ]}, {PointSize[0.025], Point[pts]}}]境界楕円体は,必ずしも体積が最小ではないが,BoundingRegionを使って求めることができる:
fastEllipsoid = BoundingRegion[pts, "FastEllipsoid"]{Volume[minVolEllipsoid], Volume[fastEllipsoid]}データフィット問題 (4)
指定された行列 a とベクトル b についての制約条件
に従って
を最小化する:
{a, b} = IconizedObject[«Block»];ConvexOptimization[Norm[Inactive[Plus][a.x, -b]], x1, {x}]データの最初と最後の点が曲線上にあるようにして,三次元曲線を離散データにフィットする:
data = IconizedObject[«Block»];DesignMatrixを使って行列を構築する:
a = DesignMatrix[data, {1, x, x^2, x^3}, x];
b = data[[All, 2]];最初と最後の点が必ず曲線上にあるようになる制約条件を定義する:
pointConstraints = {a[[1]].λ == b[[1]], a[[-1]].λ == b[[-1]]};res = ConvexOptimization[Norm[Inactive[Plus][a.λ, -b]], pointConstraints, {λ}]Show[Plot[Evaluate[{1, x, x^2, x^3}.λ /. res], {x, 0, 1}, Epilog -> {Red, PointSize[0.03], Point[data[[{1, -1}]]]}], ListPlot[data]]
を最小化することで,非線形離散データの外れ値にあまり敏感ではないフィットを求める:
data = IconizedObject[«Block»];bases = Sqrt[1 + (x - #) ^ 2]& /@ Subdivide[-3, 3, 10];
input = DesignMatrix[data, bases, x, IncludeConstantBasis -> False];
output = data[[All, 2]];res = ConvexOptimization[Norm[Inactive[Plus][a.λ, -b], 1], {a == input, b == output}, {λ}]Plot[Evaluate[bases.λ /. res], {x, -3, 3}, Epilog -> {PointSize[0.008], Point[data]}]Plot[{Sin[2x] + Cos[x ^ 2], Evaluate[bases.λ /. res]}, {x, -3, 3}, PlotLegends -> {"Reference", "SubscriptBox[L, 1]fit"}]複素数
について
を最小化することで,複素データへの
正規化フィットを求める:
data = Block[{z}, SeedRandom[1234];
Table[{z = RandomComplex[{-2 - 2I, 2 + 2I}], z ^ (3 / 2) + 0.02 RandomComplex[]}, {i, 100}]];DesignMatrixを使って基底
について行列
を構築する:
basis = {1, z, z ^ 2, z ^ 3};
a = DesignMatrix[data, basis, z];
b = data[[All, 2]];With[{σ = 0.2, m = Length[basis]}, res = ConvexOptimization[Norm[Inactive[Plus][a.λ, -b]] + σ Norm[λ, 1], {}, {Element[λ, Vectors[m, Complexes]]}]]
が
の実数成分と虚数成分の関数として定義されたフィットであるとする:
f[x_, y_] := basis.λ /. res /. z -> x + I y;Show[Plot3D[Re[f[x, y]], {x, -2, 2}, {y, -2, 2}], Graphics3D[{PointSize[0.03], Blue, Point[MapThread[Append, {ReIm[data[[All, 1]]], Re[data[[All, 2]]]}]]}]]Show[Plot3D[Im[f[x, y]], {x, -2, 2}, {y, -2, 2}], Graphics3D[{PointSize[0.03], Red, Point[MapThread[Append, {ReIm[data[[All, 1]]], Im[data[[All, 2]]]}]]}]]平方和表現 (1)
poly = 2 + 4 x + 6 x^2 + 4 x^3 + x^4;目的は,
となるような
を求めることである.ただし,
は単項式のベクトルである:
v = {1, x, x^2};n = Length[v];
mat = Array[Indexed[q, {##}] &, {n, n}];
Q = UpperTriangularize[mat] + Transpose[UpperTriangularize[mat, 1]];coeffs = Map[# == 0&, DeleteCases[Flatten[CoefficientList[v.Q.v - poly, {x}]], 0]]res = ConvexOptimization[0, {coeffs , qUnderscript[, {"SemidefiniteCone", n}]0}, q]二次の項
,ただし,
は
のコレスキー分解によって得られた下三角行列である:
L = CholeskyDecomposition[(Q /. res)];
g = L.v;
Expand[Sum[g[[i]]^2, {i, Length[g]}]]Chop[Expand[Total[g ^ 2]] - poly, 10^-7]分類問題 (3)
{set1, set2} = IconizedObject[«Block»];分割するためには,集合1は
を,集合2は
を満足しなければならない:
constraints = {set1.a + b1, set2.a + b-1};目的は
を最小にすることであるが,これは
と
の間の厚みの2倍を与える:
res = ConvexOptimization[Norm[a], constraints, {a, b}]line = a.{x, y} + b /. resShow[RegionPlot[line ≤ 0, {x, 0, 1}, {y, 0, 1}], ListPlot[{set1, set2}, PlotMarkers -> {Automatic, PointSize[0.025]}]]{set1, set2} = IconizedObject[«Block»];
dataplot = ListPointPlot3D[{set1, set2}, Sequence[...]]DesignMatrixを使って2つの集合についての二次多項式データ行列を構築する:
{data1, data2} = DesignMatrix[#, {x, x^2, y, y^2, x y}, {x, y}]& /@ {set1, set2};分割するためには,集合は
を,集合2は
を満足しなければならない:
constraints = {data1.a + b1, data2.a + b-1};res = ConvexOptimization[Norm[a], constraints, {a, b}, Tolerance -> 10 ^ -3]poly = (a.{1, x, x^2, y, y^2, x y} + b) /. resShow[dataplot, ContourPlot3D[poly == 0, {x, -1.5, 1.5}, {y, -1.5, 1.5}, {z, -1, 1}, Sequence[...]]]与えられた点集合
を別のグループに分割する.これは,
を最小にして各グループの中心
を求めることで行える.ただし,
は与えられたローカルカーネルで
は与えられたペナルティパラメータである:
x = IconizedObject[«Block»];
{n, dim} = Dimensions[x];
centers = Indexed[μ, #]& /@ Range[n];カーネル
は,
で他では
の
-最近傍(
)関数である.この問題のために
の最近傍が選ばれている:
kNN = Nearest[x -> Automatic][x, 10];
κ = SparseArray[Join@@Table[Thread[{i, kNN[[i]]}], {i, n}] -> 1, {n, n}];c1 = Table[Norm[Inactive[Plus][Indexed[x, {i}], -Indexed[μ, {i}]]], {i, n}];
c2 = Flatten[Table[κ[[i, j]]Norm[Indexed[μ, {i}] - Indexed[μ, {j}], 1], {i, 1, n}, {j, i + 1, n}]];
objective = Total[c1 ^ 2] / 2 + 10 Total[c2];vars = Table[Indexed[μ, {i}]∈Vectors[dim, Reals], {i, n}];res = ConvexOptimization[objective, {}, vars];各データ点について対応する中心が存在する.同じグループに属すデータは同じ中心値を持つ:
allCenters = centers /. res;
cvals = Map[First, Gather[allCenters, Norm[#1 - #2] ≤ 0.001&]]gpts = Table[Pick[x, Map[Norm[# - ci] ≤ 0.001&, allCenters]], {ci, cvals}];
Show[ListPlot[gpts, PlotStyle -> PointSize[0.02]], ListPlot[allCenters, PlotStyle -> {PointSize[0.03], Yellow}]]施設の位置についての問題 (1)
にいるクライアントにサービスを提供するために必要な,さまざまな携帯基地局の位置
とその範囲
を求める:
clientPos = {{0, 0}, {1, 0}, {3 / 2, 1}, {-1 / 2, 1}, {1 / 2, 3 / 2}, {1 / 2, 1 / 2}, {0, 3 / 2}, {1, 1}, {0, 1}, {3 / 2, 3 / 2}};
nTowers = 3;
nClients = Length[clientPos];各携帯基地局はその範囲に比例して電力を消費するが,これは
で与えられる.目的は電力消費量を最小にすることである:
objective = Sum[r[i] ^ 1.5, {i, nTowers}];クライアント
が携帯基地局
でカバーされている場合に,
を
を示す決定変数とする:
decisionConstraint = 0z1;各携帯基地局はその範囲がクライアントのある部分をカバーするような場所になければならない:
m = 20;
distConstraint = Table[Norm[Inactive[Plus][p[j], -clientPos[[i]]]] -
m * (1 - Indexed[z, {i, j}]) ≤ r[j], {i, nClients}, {j, nTowers}];coverageConstraint = Total[z, {2}]1;maxCoverageConstraint = Table[0 ≤ r[j] ≤ 1, {j, nTowers}];vars = Flatten[{Table[{p[j]∈Vectors[2], r[j]}, {j, nTowers}], z∈Matrices[{nClients, nTowers}, Integers]}];res = Quiet[ConvexOptimization[objective, {decisionConstraint,
distConstraint, coverageConstraint, maxCoverageConstraint}, vars]]towerPos = Table[p[i], {i, nTowers}] /. res;
towerRange = Table[r[i], {i, nTowers}] /. res;クライアントの位置についての基地局の位置と範囲を可視化する:
Graphics[{{Orange, PointSize[0.04], Point[towerPos]}, {Blue, PointSize[0.02], Point[clientPos]}, {...}}, Frame -> True]ポートフォリオの最適化 (1)
リスクを最小に抑えながらリターンを最大化するために6つの株式に投資するための資本
の配分を求める:
{μ, Σ} = Block[...];リターンは
で与えられる.ただし,
は各株式の期待されるリターンの値のベクトルである:
return = μ.w;リスクは
で与えられる.
はリスク回避パラメータで
である:
risk = w.Σ.w;
riskConstraint = risk ≤ s;目的は,指定されたリスク回避パラメータについてリスクを最小にしながらリターンを最大にすることである:
objective[α_ ? NumericQ] := -(return - α s);株式売買による株式の市場価格への影響は,
でモデル化されるが,これは,エピグラフ変換を使ったPower Coneによってモデル化できる:
marketConstraints = Table[Abs[Indexed[w, i]] ^ 1.5 ≤ Indexed[t, i], {i, 6}];重み
は0より大きくなければならず,重みと市場への影響のコストを1に加算する必要がある:
weightConstraints = {w0, Total[w] + 0.1Total[t] == 1};リスク回避パラメータの範囲についてリターンと対応するリスクを計算する:
frontier = Table[res = Quiet@ConvexOptimization[objective[α],
{riskConstraint, weightConstraints, marketConstraints}, {w, s, t∈Vectors[6]}];
{risk, return} /. res, {α, Subdivide[0, 10, 200]}];
の範囲における最適な
は,リターンとリスクの間のトレードオフの上限を示す:
randomRiskReturns = Table[{risk, return}, {w, Table[...]}];
Show[ListPlot[frontier, ...], ListPlot[randomRiskReturns, Rule[...]]]riskAversionParameter = N@{1 / 1000, 1 / 100, 1 / 2, 1, 5, 10, 15, 20};
res = Table[{α, return, Quiet@Append[w, 1 - Total[w]]} /.
Quiet@ConicOptimization[objective[α],
{riskConstraint, weightConstraints, marketConstraints}, {w, s, t∈Vectors[6]}], {α, riskAversionParameter}];市場コストを考慮することで低リスク回避のための分散ポートフォリオを得ることができるが,リスク回避が高い場合は分散の少ない株式を購入するため,市場の影響コストが支配的になる:
BarChart[res[[All, -1]], ChartLayout -> "Stacked", ChartLabels -> {riskAversionParameter, None}, Axes -> False, Frame -> True, ChartLegends -> SwatchLegend[Automatic, Append[(StringForm["Stock ``", #]&) /@ Range[6], "market impact cost"], LegendLabel -> "Stock"], FrameLabel -> {"Risk Aversion Parameter", "Fraction of budget"}]画像処理 (1)
全変動ノルムの下で最も近い画像を探すことで,破損した画像を回復する:
image = ImageResize[ColorConvert[ExampleData[{"TestImage", "House"}], "Grayscale"], 75]40%のデータ点をランダムに削除することで破損した画像を作成する:
data = ImageData[image];
SeedRandom[123];
mask = RandomChoice[{0.4, 0.6} -> {0, 1}, Dimensions[data]];
corruptedData = mask * data;
Image[corruptedData]目的は
を最小化することである.ただし,
は画像データである:
{n, m} = Dimensions[data];objective = Total[Flatten[Table[Norm[{Indexed[u, {i + 1, j}] - Indexed[u, {i, j}], Indexed[u, {i, j + 1}] - Indexed[u, {i, j}]}], {i, n - 1}, {j, m - 1}]]];任意の非零のデータ点
が破損していると仮定する.それらの点に対して
を設定する:
knownPos = SparseArray[mask]["NonzeroPositions"];constraint = Map[Indexed[u, #] == data[[Sequence@@#]]&, knownPos];sol = ConvexOptimization[objective, constraint, u∈Matrices[{n, m}]];Image[u /. sol]テクニカルノート
関連するガイド
-
▪
- 凸最適化 ▪
- 最適化 ▪
- 記号的なベクトル,行列,配列
テキスト
Wolfram Research (2020), ConvexOptimization, Wolfram言語関数, https://reference.wolfram.com/language/ref/ConvexOptimization.html.
CMS
Wolfram Language. 2020. "ConvexOptimization." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ConvexOptimization.html.
APA
Wolfram Language. (2020). ConvexOptimization. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ConvexOptimization.html
BibTeX
@misc{reference.wolfram_2026_convexoptimization, author="Wolfram Research", title="{ConvexOptimization}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ConvexOptimization.html}", note=[Accessed: 13-July-2026]}
BibLaTeX
@online{reference.wolfram_2026_convexoptimization, organization={Wolfram Research}, title={ConvexOptimization}, year={2020}, url={https://reference.wolfram.com/language/ref/ConvexOptimization.html}, note=[Accessed: 13-July-2026]}