凸の制約付き最適化

Pythonで学ぶOptimization入門

Jasmin Ludolf

Content Developer

凸の制約付き最適化

凸関数。

  • 制約: 変数への制限
  • 無差別曲線: 変数の組合せを表す
  • 目的関数を最小化/最大化する無差別曲線上の点を探す
Pythonで学ぶOptimization入門

無差別曲線

暗い髪の若い女性がノートPCで作業している

  • フリーランスのソフトウェアエンジニア
  • 仕事($w$)と余暇($l$)を重視

 

効用関数:

  • $U(w, l)=w^{0.4}l^{0.6}$
Pythonで学ぶOptimization入門

無差別曲線を描く

import numpy as np
import matplotlib.pyplot as plt


w = np.linspace(1, 30, 100) l = np.linspace(1, 30, 100)
W, L = np.meshgrid(w, l)
F = W**0.4 * L**0.6
plt.figure(figsize=(8, 6))
contours = plt.contour(W, L, F, levels=[5, 10, 15, 20])
plt.clabel(contours)
plt.title('Indifference Curves for the function: w**0.4 * l**0.6') plt.xlabel('w') plt.ylabel('l') plt.grid(True) plt.show()
Pythonで学ぶOptimization入門

無差別曲線

無差別曲線の可視化

  • Alexiaは$w$と$l$の具体的な組合せに無差別です
Pythonで学ぶOptimization入門

時間制約

  • 1日は24時間
  • 線形等式制約

$$ \max_{w,l} w^{0.4}l^{0.6}$$ $$s.t.\ \ \ w+l = 24$$

  • 制約をグラフに追加:
    • l = 24 - w
    • plt.plot(w, l, color='red')

無差別曲線と線形制約。最適な無差別曲線は制約に接する。接点では勾配は制約と接線に直交する。

Pythonで学ぶOptimization入門

SciPyで解く

def utility_function(vars):
    w, l = vars
    return -(w**0.4 * l**0.6)


def constraint(vars): return 24 - np.sum(vars)
initial_guess = [12, 12] constraint_definition = {'type': 'eq', 'fun': constraint} result = minimize(utility_function, initial_guess, constraints=constraint_definition) print(result.x)
[ 9.60001122 14.39998878]
Pythonで学ぶOptimization入門

練習しましょう!

Pythonで学ぶOptimization入門

Preparing Video For Download...