SlideShare una empresa de Scribd logo
1 de 19
Hands on with Optimization solvers in PYTHON
Presentation on
Dr. Kishalay Mitra
Professor, Department of Chemical Engineering
Indian Institute of Technology Hyderabad
kishalay@che.iith.ac.in
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Type Formulation Solver
Scalar minimization min
𝑥
𝑓(𝑥)
such that lb<x<ub (x is a scalar)
fminbound,
minimize_scalar
Unconstrained minimization min
𝑥
𝑓(𝑥) fmin, fmin_powell
Linear programming min
𝑥
𝑓𝑇
𝑥
such that 𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤
𝑥 ≤ 𝑢𝑏
linprog
Mixed integer linear
programming
min
𝑥
𝑓𝑇
𝑥
such that 𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤
𝑥 ≤ 𝑢𝑏
x is integer valued
milp
Constrained minimization min
𝑥
𝑓(𝑥)
such that 𝑐 𝑥 ≤ 0, 𝑐𝑒𝑞 𝑥 = 0,
𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏
minimize
Root finding methods min
𝑥
𝑓(𝑥)
such that lb<x<ub
root_scalar, root
Minimization problems : scipy.optimize
Department of Chemical Engineering Indian Institute of Technology Hyderabad
Type Formulation Solver
Linear least squares
min
𝑥
1
2
𝑐. 𝑥 − 𝑑 2
m equations, n variables
lsq_linear
Non negative linear least squares
min
𝑥
1
2
𝑐. 𝑥 − 𝑑 2
Such that x≥0
nnls
Nonlinear least squares
min
𝑥
𝐹 𝑥 = min
𝑥
𝑖
𝐹𝑖
2
(𝑥)
such that 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏
least_squares
Nonlinear curve fitting min
𝑥
𝐹 𝑥, 𝑥𝑑𝑎𝑡𝑎 − 𝑦𝑑𝑎𝑡𝑎 2
such that 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏
curve_fit
Least squares (curve fitting) problems: scipy.optimize
Single objective optimization min
𝑥
𝑓(𝑥) GA
Multi objective optimization min
𝑥
𝑓1(𝑥)
m𝑎𝑥
𝑥
𝑓2(𝑥)
NSGA2
Optimization problems: pymoo
Optimizer
myfun
Decision
Variables
Objective
function
Unconstrained nonlinear function minimization
Result = optimizer (myfun, x0)
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Case study 1 min
𝑥
𝑓 𝑥 = 12𝑥5
− 45𝑥4
+ 40𝑥3
+ 5
Optimizer
myfun
Decision
Variables
Objective
function
Result = optimizer (myfun, x0)
Unconstrained unbounded nonlinear function minimization
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
def f = myfun(x):
f = 12*x^5 - 45*x^4 + 40*x^3 + 5
Case study 1 min
𝑥
𝑓 𝑥 = 12𝑥5
− 45𝑥4
+ 40𝑥3
+ 5
 Result= fmin (myfun, x0)
 Result = fmin_powell (myfun, x0)
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Result = optimizer (myfun, x0)
Unconstrained unbounded nonlinear function minimization
Case study 2 min
𝑥
𝑓 𝑥 = 12𝑥5
− 45𝑥4
+ 40𝑥3
+ 5
Optimizer
myfun
Decision
Variables
Objective
function
Result = optimizer (myfun, 𝑥1, 𝑥2)
such that x ∈ (0.5, 2.5)
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Unconstrained bounded nonlinear function minimization
def f = myfun(x):
f = 12*x^5 - 45*x^4 + 40*x^3 + 5
Case study 2 min
𝑥
𝑓 𝑥 = 12𝑥5
− 45𝑥4
+ 40𝑥3
+ 5
Result = optimizer (myfun, 𝑥1, 𝑥2)
such that x ∈ (0.5, 2.5)
 Result = fminbound (myfun, 𝑥1, 𝑥2)
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Unconstrained bounded nonlinear function minimization
def f = myfun(x):
f = 12*x^5 - 45*x^4 + 40*x^3 + 5
f = -f;
Case study 3 m𝑎𝑥
𝑥
𝑓 𝑥 = 12𝑥5
− 45𝑥4
+ 40𝑥3
+ 5
such that x ∈ (0.5, 2.5)
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Unconstrained bounded nonlinear function maximization
Result = optimizer (myfun, 𝑥1, 𝑥2)
 Result = fminbound (myfun, 𝑥1, 𝑥2)
Case study 4
Root finder
myfun
Variable
Function
value
Result = rootfinder (myfun, x0)
Root finding
min
𝑥,𝑦
𝑓 𝑥, 𝑦 = 3𝑥2
− 6
𝑥0 = 0.2
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
 Result = root_scalar(fun, x0, fprime=fprime)
• lsq_linear, nnls, least_squares, curve_fit are the operators used for
solving an overdetermined system of linear equations
• Result = optimize.curve_fit(myfun, 𝑥𝑑𝑎𝑡𝑎, 𝑦𝑑𝑎𝑡𝑎, p0)
lsqcurvefit
myfun
p0 – decision
variables/
Parameters and
𝑥𝑑𝑎𝑡𝑎
𝑦𝑠𝑖𝑚𝑢𝑙𝑎𝑡𝑒𝑑
𝑦𝑑𝑎𝑡𝑎
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Linear & Nonlinear regression and curve fitting
Result= optimize.minimize(c=f, x0, constraints, method,
bounds=[lb,ub])
Optimizer
Model
Decision
Variables
Objective and
Constraints
Constrained nonlinear function minimization
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Result= optimize.minimize(c=f, x0, constraints, method,
bounds=[lb,ub])
Constrained nonlinear function minimization
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Case study 5
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Constrained nonlinear function minimization
   
5
x
,
x
5
25
x
x
.
t
.
s
7
x
x
11
x
x
2
1
2
2
2
1
2
2
1
2
2
2
1
x
,
x
2
2
1
Min










Constrained nonlinear function minimization
Case study 6.
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
𝒎𝒊𝒏 𝒇𝟏 𝒙, 𝒚 = 𝟒𝒙𝟐 + 𝟒𝒚𝟐
𝒎𝒊𝒏 𝒇𝟐 𝒙, 𝒚 = 𝒙 − 𝟓 𝟐
+ 𝒚 − 𝟓 𝟐
𝒈𝟏 𝒙, 𝒚 = 𝒙 − 𝟓 𝟐 + 𝒚 𝟐 ≤ 𝟐𝟓
𝒈𝟐 𝒙, 𝒚 = 𝒙 − 𝟖 𝟐 + 𝒚 + 𝟑 𝟐 ≤ 𝟕. 𝟕
𝟎 ≤ 𝒙 ≤ 𝟓 𝟎 ≤ 𝒚 ≤ 𝟑
Constrained nonlinear Multi objective optimization
Case study 7.
Unconstrained nonlinear function minimization
Linear & Nonlinear Regression and Curve Fitting
Case study 8. ODE Solving
First order series reactions happening in an isothermal
batch reactor
0
)
0
(
c
),
t
(
b
k
dt
dc
0
)
0
(
b
),
t
(
b
k
)
t
(
a
k
dt
db
1
)
0
(
a
),
t
(
a
k
dt
da
2
2
1
1








A B C
k1 k2
Solve using solve_ivp
& then perform parameter
estimation using minimize
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
Unconstrained nonlinear function minimization
Linear & Nonlinear Regression and Curve Fitting
First order series reactions happening in an isothermal
batch reactor
0
)
0
(
,
0
)
0
(
,
1
)
0
(
)
(
)
(
)
(
)
(
2
2
1
1








c
b
a
t
b
k
dt
dc
t
b
k
t
a
k
dt
db
t
a
k
dt
da
A B C
k1 k2
def my_model(t,y,k):
f =[]
f[0] = -k[0]*y[0]
f[2] = k[0]*y[0]-k[1]*y[1]
f[3] = k[1]*y[1]
return f
Indian Institute of Technology Hyderabad
Department of Chemical Engineering
def fun:
ic = [1,0,0]
tspan = [0 0.05 0.1 0.15 0.2 0.3 0.4 0.45 0.56
0.67 0.7 0.75 0.78 0.8 0.9 0.92 1]
k = [6.3,4.23]
sol = solve_ivp(my_model(t,y,k),tspan, ic)
Case study 10. ODE Solving
Indian Institute of Technology Hyderabad
Department of Chemical Engineering

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

データ解析14 ナイーブベイズ
データ解析14 ナイーブベイズデータ解析14 ナイーブベイズ
データ解析14 ナイーブベイズ
 
Machine Learning lecture2(linear regression)
Machine Learning lecture2(linear regression)Machine Learning lecture2(linear regression)
Machine Learning lecture2(linear regression)
 
PRML輪読#4
PRML輪読#4PRML輪読#4
PRML輪読#4
 
[2021CAPE公開セミナー] 論理学上級 Ⅱ-3「証明論的意味論としてのマーティン・レーフの構成的型理論」
[2021CAPE公開セミナー] 論理学上級 Ⅱ-3「証明論的意味論としてのマーティン・レーフの構成的型理論」[2021CAPE公開セミナー] 論理学上級 Ⅱ-3「証明論的意味論としてのマーティン・レーフの構成的型理論」
[2021CAPE公開セミナー] 論理学上級 Ⅱ-3「証明論的意味論としてのマーティン・レーフの構成的型理論」
 
PRML Chapter 5
PRML Chapter 5PRML Chapter 5
PRML Chapter 5
 
「リア充」で学ぶ線形計画問題(ver0.5.3)
「リア充」で学ぶ線形計画問題(ver0.5.3)「リア充」で学ぶ線形計画問題(ver0.5.3)
「リア充」で学ぶ線形計画問題(ver0.5.3)
 
ディープボルツマンマシン入門
ディープボルツマンマシン入門ディープボルツマンマシン入門
ディープボルツマンマシン入門
 
PRML 5章 PP.227-PP.247
PRML 5章 PP.227-PP.247PRML 5章 PP.227-PP.247
PRML 5章 PP.227-PP.247
 
PRML輪読#3
PRML輪読#3PRML輪読#3
PRML輪読#3
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
 
Prml 3 3.3
Prml 3 3.3Prml 3 3.3
Prml 3 3.3
 
劣モジュラ最適化と機械学習 2.4節
劣モジュラ最適化と機械学習 2.4節劣モジュラ最適化と機械学習 2.4節
劣モジュラ最適化と機械学習 2.4節
 
Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...
Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...
Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...
 
Penalty functions
Penalty functionsPenalty functions
Penalty functions
 
Prml
PrmlPrml
Prml
 
データ解析3 最適化の復習
データ解析3 最適化の復習データ解析3 最適化の復習
データ解析3 最適化の復習
 
Python 機械学習プログラミング データ分析演習編
Python 機械学習プログラミング データ分析演習編Python 機械学習プログラミング データ分析演習編
Python 機械学習プログラミング データ分析演習編
 
PRML_2.3.1~2.3.3
PRML_2.3.1~2.3.3PRML_2.3.1~2.3.3
PRML_2.3.1~2.3.3
 
ベイズ推論とシミュレーション法の基礎
ベイズ推論とシミュレーション法の基礎ベイズ推論とシミュレーション法の基礎
ベイズ推論とシミュレーション法の基礎
 

Similar a Hands on Optimization in Python (1).pptx

4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
BechanYadav4
 

Similar a Hands on Optimization in Python (1).pptx (20)

A machine learning method for efficient design optimization in nano-optics
A machine learning method for efficient design optimization in nano-opticsA machine learning method for efficient design optimization in nano-optics
A machine learning method for efficient design optimization in nano-optics
 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
 
A machine learning method for efficient design optimization in nano-optics
A machine learning method for efficient design optimization in nano-optics A machine learning method for efficient design optimization in nano-optics
A machine learning method for efficient design optimization in nano-optics
 
4-Unconstrained Single Variable Optimization-Methods and Application.pdf
4-Unconstrained Single Variable Optimization-Methods and Application.pdf4-Unconstrained Single Variable Optimization-Methods and Application.pdf
4-Unconstrained Single Variable Optimization-Methods and Application.pdf
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
 
Optmization techniques
Optmization techniquesOptmization techniques
Optmization techniques
 
optmizationtechniques.pdf
optmizationtechniques.pdfoptmizationtechniques.pdf
optmizationtechniques.pdf
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
 
Paper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipelinePaper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipeline
 
Recommender Systems
Recommender SystemsRecommender Systems
Recommender Systems
 
Methods of Manifold Learning for Dimension Reduction of Large Data Sets
Methods of Manifold Learning for Dimension Reduction of Large Data SetsMethods of Manifold Learning for Dimension Reduction of Large Data Sets
Methods of Manifold Learning for Dimension Reduction of Large Data Sets
 
Error Estimates for Multi-Penalty Regularization under General Source Condition
Error Estimates for Multi-Penalty Regularization under General Source ConditionError Estimates for Multi-Penalty Regularization under General Source Condition
Error Estimates for Multi-Penalty Regularization under General Source Condition
 
Convex optmization in communications
Convex optmization in communicationsConvex optmization in communications
Convex optmization in communications
 
OR_Hamdy_taha.ppt
OR_Hamdy_taha.pptOR_Hamdy_taha.ppt
OR_Hamdy_taha.ppt
 
OR_Hamdy_taha.ppt
OR_Hamdy_taha.pptOR_Hamdy_taha.ppt
OR_Hamdy_taha.ppt
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
 
Optimization techniques
Optimization techniquesOptimization techniques
Optimization techniques
 
Optimization Techniques.pdf
Optimization Techniques.pdfOptimization Techniques.pdf
Optimization Techniques.pdf
 

Último

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
amitlee9823
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
gajnagarg
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Último (20)

Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 

Hands on Optimization in Python (1).pptx

  • 1. Hands on with Optimization solvers in PYTHON Presentation on Dr. Kishalay Mitra Professor, Department of Chemical Engineering Indian Institute of Technology Hyderabad kishalay@che.iith.ac.in
  • 2. Indian Institute of Technology Hyderabad Department of Chemical Engineering Type Formulation Solver Scalar minimization min 𝑥 𝑓(𝑥) such that lb<x<ub (x is a scalar) fminbound, minimize_scalar Unconstrained minimization min 𝑥 𝑓(𝑥) fmin, fmin_powell Linear programming min 𝑥 𝑓𝑇 𝑥 such that 𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏 linprog Mixed integer linear programming min 𝑥 𝑓𝑇 𝑥 such that 𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏 x is integer valued milp Constrained minimization min 𝑥 𝑓(𝑥) such that 𝑐 𝑥 ≤ 0, 𝑐𝑒𝑞 𝑥 = 0, 𝐴. 𝑥 ≤ 𝑏, 𝐴𝑒𝑞. 𝑥 = 𝑏𝑒𝑞, 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏 minimize Root finding methods min 𝑥 𝑓(𝑥) such that lb<x<ub root_scalar, root Minimization problems : scipy.optimize
  • 3. Department of Chemical Engineering Indian Institute of Technology Hyderabad Type Formulation Solver Linear least squares min 𝑥 1 2 𝑐. 𝑥 − 𝑑 2 m equations, n variables lsq_linear Non negative linear least squares min 𝑥 1 2 𝑐. 𝑥 − 𝑑 2 Such that x≥0 nnls Nonlinear least squares min 𝑥 𝐹 𝑥 = min 𝑥 𝑖 𝐹𝑖 2 (𝑥) such that 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏 least_squares Nonlinear curve fitting min 𝑥 𝐹 𝑥, 𝑥𝑑𝑎𝑡𝑎 − 𝑦𝑑𝑎𝑡𝑎 2 such that 𝑙𝑏 ≤ 𝑥 ≤ 𝑢𝑏 curve_fit Least squares (curve fitting) problems: scipy.optimize Single objective optimization min 𝑥 𝑓(𝑥) GA Multi objective optimization min 𝑥 𝑓1(𝑥) m𝑎𝑥 𝑥 𝑓2(𝑥) NSGA2 Optimization problems: pymoo
  • 4. Optimizer myfun Decision Variables Objective function Unconstrained nonlinear function minimization Result = optimizer (myfun, x0) Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 5. Case study 1 min 𝑥 𝑓 𝑥 = 12𝑥5 − 45𝑥4 + 40𝑥3 + 5 Optimizer myfun Decision Variables Objective function Result = optimizer (myfun, x0) Unconstrained unbounded nonlinear function minimization Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 6. def f = myfun(x): f = 12*x^5 - 45*x^4 + 40*x^3 + 5 Case study 1 min 𝑥 𝑓 𝑥 = 12𝑥5 − 45𝑥4 + 40𝑥3 + 5  Result= fmin (myfun, x0)  Result = fmin_powell (myfun, x0) Indian Institute of Technology Hyderabad Department of Chemical Engineering Result = optimizer (myfun, x0) Unconstrained unbounded nonlinear function minimization
  • 7. Case study 2 min 𝑥 𝑓 𝑥 = 12𝑥5 − 45𝑥4 + 40𝑥3 + 5 Optimizer myfun Decision Variables Objective function Result = optimizer (myfun, 𝑥1, 𝑥2) such that x ∈ (0.5, 2.5) Indian Institute of Technology Hyderabad Department of Chemical Engineering Unconstrained bounded nonlinear function minimization
  • 8. def f = myfun(x): f = 12*x^5 - 45*x^4 + 40*x^3 + 5 Case study 2 min 𝑥 𝑓 𝑥 = 12𝑥5 − 45𝑥4 + 40𝑥3 + 5 Result = optimizer (myfun, 𝑥1, 𝑥2) such that x ∈ (0.5, 2.5)  Result = fminbound (myfun, 𝑥1, 𝑥2) Indian Institute of Technology Hyderabad Department of Chemical Engineering Unconstrained bounded nonlinear function minimization
  • 9. def f = myfun(x): f = 12*x^5 - 45*x^4 + 40*x^3 + 5 f = -f; Case study 3 m𝑎𝑥 𝑥 𝑓 𝑥 = 12𝑥5 − 45𝑥4 + 40𝑥3 + 5 such that x ∈ (0.5, 2.5) Indian Institute of Technology Hyderabad Department of Chemical Engineering Unconstrained bounded nonlinear function maximization Result = optimizer (myfun, 𝑥1, 𝑥2)  Result = fminbound (myfun, 𝑥1, 𝑥2)
  • 10. Case study 4 Root finder myfun Variable Function value Result = rootfinder (myfun, x0) Root finding min 𝑥,𝑦 𝑓 𝑥, 𝑦 = 3𝑥2 − 6 𝑥0 = 0.2 Indian Institute of Technology Hyderabad Department of Chemical Engineering  Result = root_scalar(fun, x0, fprime=fprime)
  • 11. • lsq_linear, nnls, least_squares, curve_fit are the operators used for solving an overdetermined system of linear equations • Result = optimize.curve_fit(myfun, 𝑥𝑑𝑎𝑡𝑎, 𝑦𝑑𝑎𝑡𝑎, p0) lsqcurvefit myfun p0 – decision variables/ Parameters and 𝑥𝑑𝑎𝑡𝑎 𝑦𝑠𝑖𝑚𝑢𝑙𝑎𝑡𝑒𝑑 𝑦𝑑𝑎𝑡𝑎 Indian Institute of Technology Hyderabad Department of Chemical Engineering Linear & Nonlinear regression and curve fitting
  • 12. Result= optimize.minimize(c=f, x0, constraints, method, bounds=[lb,ub]) Optimizer Model Decision Variables Objective and Constraints Constrained nonlinear function minimization Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 13. Result= optimize.minimize(c=f, x0, constraints, method, bounds=[lb,ub]) Constrained nonlinear function minimization Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 14. Case study 5 Indian Institute of Technology Hyderabad Department of Chemical Engineering Constrained nonlinear function minimization
  • 15.     5 x , x 5 25 x x . t . s 7 x x 11 x x 2 1 2 2 2 1 2 2 1 2 2 2 1 x , x 2 2 1 Min           Constrained nonlinear function minimization Case study 6. Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 16. Indian Institute of Technology Hyderabad Department of Chemical Engineering 𝒎𝒊𝒏 𝒇𝟏 𝒙, 𝒚 = 𝟒𝒙𝟐 + 𝟒𝒚𝟐 𝒎𝒊𝒏 𝒇𝟐 𝒙, 𝒚 = 𝒙 − 𝟓 𝟐 + 𝒚 − 𝟓 𝟐 𝒈𝟏 𝒙, 𝒚 = 𝒙 − 𝟓 𝟐 + 𝒚 𝟐 ≤ 𝟐𝟓 𝒈𝟐 𝒙, 𝒚 = 𝒙 − 𝟖 𝟐 + 𝒚 + 𝟑 𝟐 ≤ 𝟕. 𝟕 𝟎 ≤ 𝒙 ≤ 𝟓 𝟎 ≤ 𝒚 ≤ 𝟑 Constrained nonlinear Multi objective optimization Case study 7.
  • 17. Unconstrained nonlinear function minimization Linear & Nonlinear Regression and Curve Fitting Case study 8. ODE Solving First order series reactions happening in an isothermal batch reactor 0 ) 0 ( c ), t ( b k dt dc 0 ) 0 ( b ), t ( b k ) t ( a k dt db 1 ) 0 ( a ), t ( a k dt da 2 2 1 1         A B C k1 k2 Solve using solve_ivp & then perform parameter estimation using minimize Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 18. Unconstrained nonlinear function minimization Linear & Nonlinear Regression and Curve Fitting First order series reactions happening in an isothermal batch reactor 0 ) 0 ( , 0 ) 0 ( , 1 ) 0 ( ) ( ) ( ) ( ) ( 2 2 1 1         c b a t b k dt dc t b k t a k dt db t a k dt da A B C k1 k2 def my_model(t,y,k): f =[] f[0] = -k[0]*y[0] f[2] = k[0]*y[0]-k[1]*y[1] f[3] = k[1]*y[1] return f Indian Institute of Technology Hyderabad Department of Chemical Engineering
  • 19. def fun: ic = [1,0,0] tspan = [0 0.05 0.1 0.15 0.2 0.3 0.4 0.45 0.56 0.67 0.7 0.75 0.78 0.8 0.9 0.92 1] k = [6.3,4.23] sol = solve_ivp(my_model(t,y,k),tspan, ic) Case study 10. ODE Solving Indian Institute of Technology Hyderabad Department of Chemical Engineering