Convexe optimalisatie met restricties

Introductie tot optimalisatie in Python

Jasmin Ludolf

Content Developer

Convexe optimalisatie met restricties

Convexe functie.

  • Restrictie: beperking op variabelen
  • Indifferentiecurve: toont combinaties van variabelen
  • Vind het punt op de indifferentiecurve dat de doelfunctie minimaliseert of maximaliseert
Introductie tot optimalisatie in Python

De indifferentiecurve

Een jonge vrouw met donker haar werkt op een laptop

  • Freelance software engineer
  • Waardeert werk ($w$) en vrije tijd ($l$)

 

Nutfunctie:

  • $U(w, l)=w^{0.4}l^{0.6}$
Introductie tot optimalisatie in Python

De indifferentiecurve plotten

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()
Introductie tot optimalisatie in Python

De indifferentiecurve

De indifferentiecurve visualiseren

  • Alexia is onverschillig over de specifieke combinatie van $w$ en $l$
Introductie tot optimalisatie in Python

Tijdsrestrictie

  • 24 uur per dag
  • Lineaire gelijkheidsrestrictie

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

  • Voeg de restrictie toe aan de grafiek:
    • l = 24 - w
    • plt.plot(w, l, color='red')

Indifferentiecurve en lineaire restrictie. De indifferentiecurve op het optimum raakt de restrictie. In het raakpunt staat de gradiënt loodrecht op de restrictie en de raaklijn.

Introductie tot optimalisatie in Python

Oplossen met 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]
Introductie tot optimalisatie in Python

Laten we oefenen!

Introductie tot optimalisatie in Python

Preparing Video For Download...