SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
 
07 dimensionality reduction
07 dimensionality reduction07 dimensionality reduction
07 dimensionality reductionMarco Quartulli
 
Interpolation of Cubic Splines
Interpolation of Cubic SplinesInterpolation of Cubic Splines
Interpolation of Cubic SplinesSohaib H. Khan
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Pagerank Algorithm Explained
Pagerank Algorithm ExplainedPagerank Algorithm Explained
Pagerank Algorithm Explainedjdhaar
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaEdureka!
 
Numerical integration
Numerical integrationNumerical integration
Numerical integrationSunny Chauhan
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clusteringJeonghun Yoon
 
Problem Formulation
Problem FormulationProblem Formulation
Problem FormulationAdri Jovin
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithmami_01
 
Machine Learning With Logistic Regression
Machine Learning  With Logistic RegressionMachine Learning  With Logistic Regression
Machine Learning With Logistic RegressionKnoldus Inc.
 
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...Edureka!
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
Feature selection concepts and methods
Feature selection concepts and methodsFeature selection concepts and methods
Feature selection concepts and methodsReza Ramezani
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent methodSanghyuk Chun
 
Gaussian Numerical Integration
Gaussian Numerical IntegrationGaussian Numerical Integration
Gaussian Numerical IntegrationVARUN KUMAR
 

Was ist angesagt? (20)

Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
07 dimensionality reduction
07 dimensionality reduction07 dimensionality reduction
07 dimensionality reduction
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
 
Interpolation of Cubic Splines
Interpolation of Cubic SplinesInterpolation of Cubic Splines
Interpolation of Cubic Splines
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Pagerank Algorithm Explained
Pagerank Algorithm ExplainedPagerank Algorithm Explained
Pagerank Algorithm Explained
 
06. graph mining
06. graph mining06. graph mining
06. graph mining
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Numerical integration
Numerical integrationNumerical integration
Numerical integration
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clustering
 
Problem Formulation
Problem FormulationProblem Formulation
Problem Formulation
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
Machine Learning With Logistic Regression
Machine Learning  With Logistic RegressionMachine Learning  With Logistic Regression
Machine Learning With Logistic Regression
 
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...
Linear Regression Algorithm | Linear Regression in Python | Machine Learning ...
 
Introductoin to Python.ppt
Introductoin to Python.pptIntroductoin to Python.ppt
Introductoin to Python.ppt
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Feature selection concepts and methods
Feature selection concepts and methodsFeature selection concepts and methods
Feature selection concepts and methods
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
 
Gaussian Numerical Integration
Gaussian Numerical IntegrationGaussian Numerical Integration
Gaussian Numerical Integration
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.pptamreenkhanum0307
 

Kürzlich hochgeladen (20)

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.ppt
 

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