Convex constrained-optimization

Python में Optimization परिचय

Jasmin Ludolf

Content Developer

Convex constrained-optimization

उत्तल फंक्शन.

  • Constraint: वैरिएबल्स पर सीमा
  • Indifference curve: वैरिएबल्स के संयोजन को दर्शाती है
  • उस indifference curve पर बिंदु खोजें जहाँ objective function न्यूनतम या अधिकतम हो
Python में Optimization परिचय

Indifference curve

घने बालों वाली एक युवा महिला लैपटॉप पर काम करती हुई

  • Freelance software engineer
  • काम ($w$) और अवकाश ($l$) को महत्व देती है

 

Utility function:

  • $U(w, l)=w^{0.4}l^{0.6}$
Python में Optimization परिचय

Indifference curve प्लॉट करना

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 परिचय

Indifference curve

Indifference curve का विज़ुअलाइज़ेशन

  • Alexia के लिए $w$ और $l$ के संयोजन आपस में समतुल्य हैं
Python में Optimization परिचय

Time constraint

  • प्रति दिन 24 घंटे
  • Linear equality constraint

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

  • Constraint को ग्राफ में जोड़ें:
    • l = 24 - w
    • plt.plot(w, l, color='red')

Indifference curve और linear constraint. Optimal स्तर पर indifference curve constraint को स्पर्श करती है. स्पर्श बिंदु पर gradient constraint और tangent, दोनों के लंबरूप होता है.

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...