Optimisation convexe avec contrainte

Introduction à l'optimisation en Python

Jasmin Ludolf

Content Developer

Optimisation convexe avec contrainte

Fonction convexe.

  • Contrainte : limitation sur les variables
  • Courbe d'indifférence : représente une combinaison de variables
  • Trouver sur la courbe d'indifférence le point qui minimise ou maximise la fonction objectif
Introduction à l'optimisation en Python

La courbe d'indifférence

Jeune femme aux cheveux foncés travaillant sur un portable

  • Ingénieure logicielle pigiste
  • Valorise le travail ($w$) et les loisirs ($l$)

 

Fonction d'utilité :

  • $U(w, l)=w^{0.4}l^{0.6}$
Introduction à l'optimisation en Python

Tracer la courbe d'indifférence

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()
Introduction à l'optimisation en Python

La courbe d'indifférence

Visualiser la courbe d'indifférence

  • Alexia est indifférente à la combinaison précise de $w$ et $l$
Introduction à l'optimisation en Python

Contrainte de temps

  • 24 heures par jour
  • Contrainte d'égalité linéaire

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

  • Ajouter la contrainte au graphique :
    • l = 24 - w
    • plt.plot(w, l, color='red')

Courbe d'indifférence et contrainte linéaire. La courbe d'indifférence au niveau optimal est tangente à la contrainte. Au point de tangence, le gradient est perpendiculaire à la contrainte et à la tangente.

Introduction à l'optimisation en Python

Résoudre avec 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]
Introduction à l'optimisation en Python

Passons à la pratique !

Introduction à l'optimisation en Python

Preparing Video For Download...