SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Numerical method for solving non linear equations
Numerical method for solving non linear equationsNumerical method for solving non linear equations
Numerical method for solving non linear equationsMdHaque78
 
Stream Computing & Analytics at Uber
Stream Computing & Analytics at UberStream Computing & Analytics at Uber
Stream Computing & Analytics at UberSudhir Tonse
 
Newton's Forward/Backward Difference Interpolation
Newton's Forward/Backward  Difference InterpolationNewton's Forward/Backward  Difference Interpolation
Newton's Forward/Backward Difference InterpolationVARUN KUMAR
 
interpolation of unequal intervals
interpolation of unequal intervalsinterpolation of unequal intervals
interpolation of unequal intervalsvaani pathak
 
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACE
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACEA FOCUS ON FIXED POINT THEOREM IN BANACH SPACE
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACEIJESM JOURNAL
 
Maximal and minimal elements of poset.pptx
Maximal and minimal elements of poset.pptxMaximal and minimal elements of poset.pptx
Maximal and minimal elements of poset.pptxKiran Kumar Malik
 
introduction to Numerical Analysis
introduction to Numerical Analysisintroduction to Numerical Analysis
introduction to Numerical AnalysisGhulam Mehdi Sahito
 
Newton’s Divided Difference Formula
Newton’s Divided Difference FormulaNewton’s Divided Difference Formula
Newton’s Divided Difference FormulaJas Singh Bhasin
 
Differential in several variables
Differential in several variables Differential in several variables
Differential in several variables Kum Visal
 
1.3 Solving Linear Equations
1.3 Solving Linear Equations1.3 Solving Linear Equations
1.3 Solving Linear EquationsSarah Stillwell
 

Tendances (20)

Bloom filters
Bloom filtersBloom filters
Bloom filters
 
Numerical method for solving non linear equations
Numerical method for solving non linear equationsNumerical method for solving non linear equations
Numerical method for solving non linear equations
 
Stream Computing & Analytics at Uber
Stream Computing & Analytics at UberStream Computing & Analytics at Uber
Stream Computing & Analytics at Uber
 
Maxima and minima
Maxima and minimaMaxima and minima
Maxima and minima
 
Integration
IntegrationIntegration
Integration
 
Newton's Forward/Backward Difference Interpolation
Newton's Forward/Backward  Difference InterpolationNewton's Forward/Backward  Difference Interpolation
Newton's Forward/Backward Difference Interpolation
 
interpolation of unequal intervals
interpolation of unequal intervalsinterpolation of unequal intervals
interpolation of unequal intervals
 
Primitive Recursive Functions
Primitive Recursive FunctionsPrimitive Recursive Functions
Primitive Recursive Functions
 
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACE
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACEA FOCUS ON FIXED POINT THEOREM IN BANACH SPACE
A FOCUS ON FIXED POINT THEOREM IN BANACH SPACE
 
Ch5 範例
Ch5 範例Ch5 範例
Ch5 範例
 
Maximal and minimal elements of poset.pptx
Maximal and minimal elements of poset.pptxMaximal and minimal elements of poset.pptx
Maximal and minimal elements of poset.pptx
 
introduction to Numerical Analysis
introduction to Numerical Analysisintroduction to Numerical Analysis
introduction to Numerical Analysis
 
Optimization tutorial
Optimization tutorialOptimization tutorial
Optimization tutorial
 
Golden Section method
Golden Section methodGolden Section method
Golden Section method
 
Unit4
Unit4Unit4
Unit4
 
Newton’s Divided Difference Formula
Newton’s Divided Difference FormulaNewton’s Divided Difference Formula
Newton’s Divided Difference Formula
 
Differential in several variables
Differential in several variables Differential in several variables
Differential in several variables
 
2-4 tree
2-4 tree2-4 tree
2-4 tree
 
Engineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and MinimaEngineering Mathematics | Maxima and Minima
Engineering Mathematics | Maxima and Minima
 
1.3 Solving Linear Equations
1.3 Solving Linear Equations1.3 Solving Linear Equations
1.3 Solving Linear Equations
 

Similaire à Hands on Optimization in Python (1).pptx

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-opticsJCMwave
 
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...AmirParnianifard1
 
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 JCMwave
 
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.pdfkhadijabutt34
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdfBechanYadav4
 
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...IJERA Editor
 
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...IJERA Editor
 
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 pipelineChenYiHuang5
 
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 SetsRyan B Harvey, CSDP, CSM
 
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 Conditioncsandit
 
Convex optmization in communications
Convex optmization in communicationsConvex optmization in communications
Convex optmization in communicationsDeepshika Reddy
 
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.pdfJifarRaya
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical EngineeringDebarun Banerjee
 
Optimization techniques
Optimization techniquesOptimization techniques
Optimization techniquesprashik shimpi
 
Optimization Techniques.pdf
Optimization Techniques.pdfOptimization Techniques.pdf
Optimization Techniques.pdfanandsimple
 

Similaire à 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
 

Dernier

BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
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 Researchmichael115558
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...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
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxolyaivanovalion
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxolyaivanovalion
 

Dernier (20)

BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
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
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
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
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
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...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
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