Difference between revisions of "Scilab---FOSSEE-Optimisation-Toolbox/C2/Unconstrained-Optimization-using-FOT/English"
Anandajitht (Talk | contribs) (Created page with "'''Title of the script''': '''Unconstrained Optimisation using FOT''' '''Author: Siddharth Agarwal, Anandajith TS''' '''Keywords: FOSSEE Optimization Toolbox, Integer Uncons...") |
Nancyvarkey (Talk | contribs) |
||
Line 21: | Line 21: | ||
In this tutorial, we will learn how to: | In this tutorial, we will learn how to: | ||
− | + | *Use '''fot_fminunc''' and '''fot_intfminunc functions''' in '''Scilab''' | |
− | + | *Solve '''unconstrained optimisation''' problems using '''fot_fminunc and fot_intfminunc functions''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 32: | Line 31: | ||
To record this tutorial, I am using | To record this tutorial, I am using | ||
− | + | *'''Windows 10''' as the operating system | |
− | + | *'''Scilab 6.1.0''' | |
− | + | *'''FOSSEE Optimization Toolbox''' version '''0.4.1''' | |
− | + | ||
The process demonstrated in this tutorial is identical in '''Linux''' OS also | The process demonstrated in this tutorial is identical in '''Linux''' OS also | ||
Line 51: | Line 49: | ||
To follow this tutorial, you should | To follow this tutorial, you should | ||
− | + | *Install '''FOSSEE Optimization Toolbox''' version 0.4.1 or above*Have basic understanding of Scilab and optimization theory | |
− | + | ||
− | + | ||
If not, for relevant tutorials please visit this site. | If not, for relevant tutorials please visit this site. | ||
Line 62: | Line 58: | ||
'''Code Files''' | '''Code Files''' | ||
| | | | ||
− | + | *The files used in this tutorial are have been provided in the '''Code files''' link | |
− | + | *Please download and extract the files | |
− | + | *Make a copy and then use them while practising | |
− | + | ||
|- | |- | ||
| | | | ||
Line 71: | Line 66: | ||
'''What is the Unconstrained Optimisation problem?''' | '''What is the Unconstrained Optimisation problem?''' | ||
− | | | + | |A '''function''' is nonlinear if it has a degree of two or more. |
− | A function is nonlinear if it has a degree of two or more | + | |
− | '''An Unconstrained Optimisation Problem''' is a mathematical optimization model with: | + | '''An Unconstrained Optimisation Problem''' is a mathematical '''optimization model''' with: |
− | + | *'''Nonlinear''' objective function | |
− | + | *'''No constraints''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 84: | Line 77: | ||
'''Mathematical Formulation''' | '''Mathematical Formulation''' | ||
− | | A | + | | A general form of the '''unconstrained optimization problem''' is as shown. |
|- | |- | ||
| | | | ||
Line 95: | Line 88: | ||
In this example, we will learn how to: | In this example, we will learn how to: | ||
− | + | *Minimize the given '''function''' | |
− | + | *Note that the '''objective function''' is '''nonlinear''' | |
− | + | ||
|- | |- | ||
| | | | ||
− | | | + | |We will use the '''toolbox''' to solve this example. |
− | We will use the toolbox to solve this example. | + | |
− | Make sure that the toolbox is already installed on Scilab. | + | Make sure that the '''toolbox''' is already '''installed''' on '''Scilab'''. |
|- | |- | ||
| Cursor on the Scilab console. | | Cursor on the Scilab console. | ||
− | | Now open the '''Scilab console''' | + | | Now open the '''Scilab console'''. |
|- | |- | ||
| Type '''editor''' >> press '''Enter'''. | | Type '''editor''' >> press '''Enter'''. | ||
| | | | ||
− | In the '''Scilab console''' type '''editor''' and press '''Enter''' | + | In the '''Scilab console''' type '''editor''' and press '''Enter'''. |
− | '''Editor''' window opens | + | '''Editor''' window opens. |
|- | |- | ||
| | | | ||
Line 126: | Line 117: | ||
Point to the file. | Point to the file. | ||
| | | | ||
− | Click on '''Open''' button on the toolbar. | + | Click on '''Open''' button on the '''toolbar'''. |
− | Go to the Downloads folder | + | Go to the '''Downloads''' folder. |
Locate the file '''opt_fminunc.sce'''. | Locate the file '''opt_fminunc.sce'''. | ||
Line 134: | Line 125: | ||
Then click the '''Open''' button. | Then click the '''Open''' button. | ||
− | '''opt_fminunc.sce''' file opens in the '''editor''' | + | '''opt_fminunc.sce''' file opens in the '''editor'''. |
|- | |- | ||
| Show '''opt_fminunc.sce''' in scilab editor. | | Show '''opt_fminunc.sce''' in scilab editor. | ||
− | | Now we will see the input arguments for '''fot_fminunc''' | + | | Now we will see the '''input arguments''' for '''fot_fminunc'''. |
|- | |- | ||
| Highlight '''‘f’''' | | Highlight '''‘f’''' | ||
− | | | + | |'''f''' is an '''objective function''' |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘x0’''' | | Highlight '''‘x0’''' | ||
− | | | + | |'''x0''' is a '''vector''' containing the starting values of the '''decision variables'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight ‘'''xopt,''' '''fopt''', '''exitflag, output, gradient, hessian’''' | | Highlight ‘'''xopt,''' '''fopt''', '''exitflag, output, gradient, hessian’''' | ||
| | | | ||
− | Now we will see the output arguments. | + | Now we will see the '''output arguments'''. |
− | + | '''Output arguments''' are '''xopt, fopt, exitflag, output, gradient, hessian'''. | |
|- | |- | ||
| Highlight '''‘xopt’''' | | Highlight '''‘xopt’''' | ||
− | | | + | |'''xopt''' is the optimal value of '''x'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘fopt’''' | | Highlight '''‘fopt’''' | ||
− | | | + | |'''fopt''' is the optimal '''objective function''' value. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘exitflag’''' | | Highlight '''‘exitflag’''' | ||
− | | | + | |'''exitflag''' is the status of '''execution'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘Output’''' | | Highlight '''‘Output’''' | ||
− | | | + | |'''Output''' is structure containing detailed information about the '''optimization'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘Gradient’''' | | Highlight '''‘Gradient’''' | ||
− | | | + | |'''Gradient''' is a '''vector''' containing the '''objective's gradient''' of the solution. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘Hessian’''' | | Highlight '''‘Hessian’''' | ||
− | | | + | |'''Hessian''' is a '''matrix''' containing the '''Lagrangian's hessian''' of the solution. |
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 189: | Line 164: | ||
'''[xopt,fopt,exitflag,output,gradient,hessian]=fot_fminunc(f,x0)''' | '''[xopt,fopt,exitflag,output,gradient,hessian]=fot_fminunc(f,x0)''' | ||
− | | | + | | Here we see the '''Scilab''' code to define and solve the example. |
− | + | ||
− | + | We call the '''fot_fminunc function''' to solve the given problem. | |
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 202: | Line 175: | ||
Save the file by pressing '''Control''' and '''S''' keys simultaneously. | Save the file by pressing '''Control''' and '''S''' keys simultaneously. | ||
− | To '''run''' the file, click on the '''Execute''' | + | To '''run''' the file, click on the '''Execute menu'''. |
− | Click on '''File with Echo''' from the drop down. | + | Click on '''File with Echo''' from the drop-down menu. |
|- | |- | ||
| Change the window to '''Scilab console.''' | | Change the window to '''Scilab console.''' | ||
| | | | ||
− | Switch to the | + | Switch to the '''Scilab console''' to see the '''output'''. |
We see that it prints the | We see that it prints the | ||
− | + | *'''xopt''' value as 1,1, | |
− | + | *'''fopt''' value as 1.466D-16, | |
− | + | *'''Output''' as the '''Optimal solution Found''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 224: | Line 196: | ||
We will now look at '''integer nonlinear programming''' problems. | We will now look at '''integer nonlinear programming''' problems. | ||
− | These are problems where some decision variables are constrained to be integers. | + | These are problems where some '''decision variables''' are constrained to be '''integers'''. |
|- | |- | ||
| | | | ||
Line 230: | Line 202: | ||
'''Mathematical Formulation''' | '''Mathematical Formulation''' | ||
− | | A | + | | A general form of the unconstrained '''integer programming''' problem is as shown. |
|- | |- | ||
| | | | ||
Line 239: | Line 211: | ||
We will now solve this example to illustrate the use of '''fot_intfminunc.''' | We will now solve this example to illustrate the use of '''fot_intfminunc.''' | ||
− | In this example, we will | + | In this example, we will learn how to: |
− | + | *Minimize the given '''function''' | |
− | + | *Note that the '''objective function''' is '''nonlinear.''' | |
− | + | ||
Some of the '''decision variables''' are '''integers'''. | Some of the '''decision variables''' are '''integers'''. | ||
Line 249: | Line 220: | ||
| Show '''opt_intfminunc.sce''' in '''scilab editor.''' | | Show '''opt_intfminunc.sce''' in '''scilab editor.''' | ||
| | | | ||
− | We will use the toolbox to solve this example. | + | We will use the '''toolbox''' to solve this example. |
Open the '''Scilab console'''. | Open the '''Scilab console'''. | ||
− | Type editor on the Scilab console and | + | Type '''editor''' on the '''Scilab console''' and press '''Enter'''. |
Open '''opt_intfminunc.sce''' in the '''Scilab editor.''' | Open '''opt_intfminunc.sce''' in the '''Scilab editor.''' | ||
|- | |- | ||
| Highlight '''‘f’''' | | Highlight '''‘f’''' | ||
− | | | + | |'''f''' is the '''objective function'''. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘x0’''' | | Highlight '''‘x0’''' | ||
− | | | + | |'''x0''' is a '''vector''' containing the starting values of the '''decision variables'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘intcon’''' | | Highlight '''‘intcon’''' | ||
− | | | + | |'''intcon''' is a '''vector''' of the '''indices''' of the '''integer variables'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight ‘'''xopt,''' '''fopt''', '''exitflag, output, gradient, hessian’''' | | Highlight ‘'''xopt,''' '''fopt''', '''exitflag, output, gradient, hessian’''' | ||
| | | | ||
− | Now we will see the output arguments. | + | Now we will see the '''output arguments'''. |
− | + | '''Output arguments''' are '''xopt,''' '''fopt''', '''exitflag, output, gradient, hessian''' | |
− | + | ||
|- | |- | ||
| Highlight '''‘xopt’''' | | Highlight '''‘xopt’''' | ||
− | | | + | |'''xopt''' is the optimal value of '''x'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘fopt’''' | | Highlight '''‘fopt’''' | ||
− | | | + | |'''fopt''' is the optimal '''objective function''' value. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘exitflag’''' | | Highlight '''‘exitflag’''' | ||
− | | | + | |'''exitflag''' is the status of '''execution'''. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘Gradient’''' | | Highlight '''‘Gradient’''' | ||
− | | | + | |'''Gradient''' is a '''vector''' containing the '''objective's''' '''gradient''' of the solution |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight '''‘Hessian’''' | | Highlight '''‘Hessian’''' | ||
− | | | + | |'''Hessian''' is a '''matrix''' containing the '''Lagrangian's hessian''' of the solution. |
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 312: | Line 266: | ||
Save the file by pressing '''Control''' and '''S''' keys simultaneously. | Save the file by pressing '''Control''' and '''S''' keys simultaneously. | ||
− | To '''run''' the file, click on the '''Execute''' | + | To '''run''' the file, click on the '''Execute menu'''. |
− | Click on '''File with Echo''' from the drop down. | + | Click on '''File with Echo''' from the drop-down. |
|- | |- | ||
| Change the window to '''Scilab console.''' | | Change the window to '''Scilab console.''' | ||
| | | | ||
− | Switch to the '''Scilab | + | Switch to the '''Scilab console''' to see the output. |
We see that it prints the | We see that it prints the | ||
− | + | *'''xopt''' value as 1,1, | |
− | + | *'''fopt''' value as 1.341D-19, | |
− | + | *'''Output''' as the '''Optimal solution Found''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 336: | Line 289: | ||
In this tutorial, we have learnt to: | In this tutorial, we have learnt to: | ||
− | + | *Use '''fot_fminunc''' and '''fot_intfminunc functions''' of the '''FOSSEE Optimization Toolbox'''. | |
− | + | *Solve unconstrained '''nonlinear programming''' examples in '''Scilab'''. | |
− | + | ||
|- | |- | ||
| | | | ||
Line 347: | Line 299: | ||
As an assignment, please do the following: | As an assignment, please do the following: | ||
− | + | *What will be the solution if we include the following constraint in the previous example. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | example | + | |
− | + | ||
|- | |- | ||
| | | | ||
Line 360: | Line 306: | ||
'''Assignment''' | '''Assignment''' | ||
| | | | ||
− | + | *The optimal value will be 2547.7231 and | |
− | + | *Optimal solution will be '''x one''' equal to 64.363297and '''x two''' equal to 50.720229 | |
− | + | ||
|- | |- | ||
| | | | ||
Line 418: | Line 363: | ||
'''Thank you''' | '''Thank you''' | ||
− | | | + | |This is Anandajith TS, FOSSEE intern 2021, IIT Bombay signing off. |
− | + | ||
− | + | ||
− | + | Thanks for joining. | |
− | + | ||
|} | |} |
Revision as of 14:38, 5 November 2021
Title of the script: Unconstrained Optimisation using FOT
Author: Siddharth Agarwal, Anandajith TS
Keywords: FOSSEE Optimization Toolbox, Integer Unconstrained Optimisation, Unconstrained Optimisation, fminunc, intfminunc.
Visual Cue | Narration |
---|---|
Show Slide 1 Title Slide |
Welcome to the spoken tutorial on Unconstrained Optimisation using FOT. |
Show Slide 2 Learning Objectives |
In this tutorial, we will learn how to:
|
Show Slide 3 System Requirements |
To record this tutorial, I am using
The process demonstrated in this tutorial is identical in Linux OS also |
Only narration | Annotations will be added to the tutorial if there are any differences. |
Show Slide 4 Pre-requisites |
To follow this tutorial, you should
If not, for relevant tutorials please visit this site. |
Show slide Code Files |
|
Slide 5 What is the Unconstrained Optimisation problem? |
A function is nonlinear if it has a degree of two or more.
An Unconstrained Optimisation Problem is a mathematical optimization model with:
|
Show Slide 6 Mathematical Formulation |
A general form of the unconstrained optimization problem is as shown. |
Show Slide 7 Example |
We will now solve this example to illustrate the use of fot_fminunc In this example, we will learn how to:
|
We will use the toolbox to solve this example.
Make sure that the toolbox is already installed on Scilab. | |
Cursor on the Scilab console. | Now open the Scilab console. |
Type editor >> press Enter. |
In the Scilab console type editor and press Enter. Editor window opens. |
Click on Open button. Go to the Downloads folder. Locate the file opt_fminunc.sce. Click the Open button. Point to the file. |
Click on Open button on the toolbar. Go to the Downloads folder. Locate the file opt_fminunc.sce. Then click the Open button. opt_fminunc.sce file opens in the editor. |
Show opt_fminunc.sce in scilab editor. | Now we will see the input arguments for fot_fminunc. |
Highlight ‘f’ | f is an objective function |
Highlight ‘x0’ | x0 is a vector containing the starting values of the decision variables. |
Highlight ‘xopt, fopt, exitflag, output, gradient, hessian’ |
Now we will see the output arguments. Output arguments are xopt, fopt, exitflag, output, gradient, hessian. |
Highlight ‘xopt’ | xopt is the optimal value of x. |
Highlight ‘fopt’ | fopt is the optimal objective function value. |
Highlight ‘exitflag’ | exitflag is the status of execution. |
Highlight ‘Output’ | Output is structure containing detailed information about the optimization. |
Highlight ‘Gradient’ | Gradient is a vector containing the objective's gradient of the solution. |
Highlight ‘Hessian’ | Hessian is a matrix containing the Lagrangian's hessian of the solution. |
Highlight [xopt,fopt,exitflag,output,gradient,hessian]=fot_fminunc(f,x0) |
Here we see the Scilab code to define and solve the example.
We call the fot_fminunc function to solve the given problem. |
Press CTRL + s Click on execute button on scilab. |
Save the file by pressing Control and S keys simultaneously. To run the file, click on the Execute menu. Click on File with Echo from the drop-down menu. |
Change the window to Scilab console. |
Switch to the Scilab console to see the output. We see that it prints the
|
Show Slide Integer Nonlinear Programming |
We will now look at integer nonlinear programming problems. These are problems where some decision variables are constrained to be integers. |
Show Slide 6 Mathematical Formulation |
A general form of the unconstrained integer programming problem is as shown. |
Show Slide Example |
We will now solve this example to illustrate the use of fot_intfminunc. In this example, we will learn how to:
Some of the decision variables are integers. |
Show opt_intfminunc.sce in scilab editor. |
We will use the toolbox to solve this example. Open the Scilab console. Type editor on the Scilab console and press Enter. Open opt_intfminunc.sce in the Scilab editor. |
Highlight ‘f’ | f is the objective function. |
Highlight ‘x0’ | x0 is a vector containing the starting values of the decision variables. |
Highlight ‘intcon’ | intcon is a vector of the indices of the integer variables. |
Highlight ‘xopt, fopt, exitflag, output, gradient, hessian’ |
Now we will see the output arguments. Output arguments are xopt, fopt, exitflag, output, gradient, hessian |
Highlight ‘xopt’ | xopt is the optimal value of x. |
Highlight ‘fopt’ | fopt is the optimal objective function value. |
Highlight ‘exitflag’ | exitflag is the status of execution. |
Highlight ‘Gradient’ | Gradient is a vector containing the objective's gradient of the solution |
Highlight ‘Hessian’ | Hessian is a matrix containing the Lagrangian's hessian of the solution. |
Press CTRL + s Click on execute button on scilab. |
Save the file by pressing Control and S keys simultaneously. To run the file, click on the Execute menu. Click on File with Echo from the drop-down. |
Change the window to Scilab console. |
Switch to the Scilab console to see the output. We see that it prints the
|
Show Slide Summary |
This brings us to the end of this tutorial. Let us summarise. In this tutorial, we have learnt to:
|
Show Slide Assignment |
As an assignment, please do the following:
|
Show Slide Assignment |
|
Show Slide: About Spoken Tutorial Project |
The video at the following link summarises the Spoken Tutorial project. Please download and watch it. |
Show Slide: Spoken Tutorial Workshops |
The Spoken Tutorial Project Team conducts workshops and gives certificates. For more details, please write to us |
Show Slide: Answers for THIS Spoken Tutorial |
Please post your timed queries in this forum. |
Show Slide: FOSSEE Forum | Please post your general and technical queries on Scilab in this forum. |
Show Slide: Textbook Companion project |
The FOSSEE team coordinates the Textbook Companion project. We give Certificates and Honorarium to the contributors. For more details, please visit this site. |
Show Slide: Lab Migration |
The FOSSEE team coordinates the Lab Migration project. For more details, please visit this site. |
Show Slide: Acknowledgement |
Spoken Tutorial and FOSSEE projects are funded by MoE, Government of India. |
Show Slide : Thank you |
This is Anandajith TS, FOSSEE intern 2021, IIT Bombay signing off.
Thanks for joining. |