Matlab Code Assistance for Multistart or GA
Show older comments
I want to apply MultiStart global optimization technique for curve fitting and parameter estimation from data set and system of ordinary differential equation. I am new for that concept. I have Number of infected cases for time serious data and want to fit with my model. I am wondering if you could assist me how to estimate using that technique? I will be very happy if you send me any prototype matlabcode!
Any help is appreciated!
Answers (2)
Nihal Reddy
on 13 Apr 2023
0 votes
I understand you require resources and reference examples for implementing MultiStart optimization technique in MATLAB.
Please refer to the following MATLAB documentation for more information and examples-
- How GlobalSearch and MultiStart Work - MATLAB & Simulink (mathworks.com)
- Find multiple local minima - MATLAB (mathworks.com)
- Using MultiStart for Optimization Problems - Video - MATLAB (mathworks.com)
Hope this helps!
Alan Weiss
on 14 Apr 2023
0 votes
Perhaps more relevant documentation is here:
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
11 Comments
Temesgen
on 15 Apr 2023
Temesgen
on 18 Apr 2023
Alan Weiss
on 18 Apr 2023
For more help, you need to give more information. I do not have your data so cannot try running your code. And I do not know what you see as output when you run your code, so have no idea what you see as a problem.
But I am suspicious about several lines:
err = norm(qdata - Ihh(tmeasure))
options = optimset('Display','iter','PlotFcns',@optimplotfval);
[x,fval,exitflag,output] = fmincon(@(par)ExpData(abs(par)),p0,[],[],[],[],[0 0],[],[],options) %Initiation of fminsearch
- You use fmincon as the minimizer, and the norm of the difference as the objective function. I think that this is a mistake. You should use lsqnonlin as the minimizer and the vector of differences as the objective function.
- Your lower bound is [0 0]. That implies that you have just two variables. Or maybe it means that only your first two variables have lower bounds. But it looks wrong to me.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Alan Weiss
on 18 Apr 2023
Edited: Alan Weiss
on 18 Apr 2023
I tried looking at your code but I got confused at what you are trying to do.
The idea should be as follows.
- Read the data and get a bunch of known, unchanging parameters.
- Put all the parameters that you want to fit into a vector x. How many components are in this vector? That should be exactly the same as the number of components in the vector x0. Also in the vector lb.
- Write an ODE function. This needs to have the syntax dydt = odefun(t,y). Include the data in this function. See Passing Extra Parameters.
- Write an ODE solver function. This is something like function fout = myfun(@odefun,tspan,y0), where myfun calls ode45 and where tspan is the set of times for your ODE, and y0 has the same number of elements as x0. The output fout is a matrix with one row per time step and one column for each component of the ODE. You might need to pass data into this function as well.
- After you have debugged the ODE, so that it gives you the expected output for given inputs, you can try to optimize the ODE. Really, you need to take things one step at a time, and make sure that you know how to pass the data around. Get the ODE solver working before you try to optimize anything.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Temesgen
on 19 Apr 2023
Alan Weiss
on 19 Apr 2023
Here is what I would like for you to do.
Create an ODE solver that takes the parameter x in your problem, meaning a vector of 13 components that you are trying to fit, and gives a solution to the ODE. In other words, I am asking you to create a function that takes x and returns an ODE solution.
In order to do that you need to understand what an ODE solution is for your problem. How many components are in the solution? How many time steps does it represent? What is the size of the solution, 12 by 10 or what?
I am NOT asking you to optimize anything. I can show you how to do that next. What I want is a clear, unambiguous, and working piece of code that takes a set of parameters x and gives a matrix representing the ODE solution at a set of times.
If you need help for this step, that is OK, we can discuss the details as you work on it. But I want to see you do that first before we talk about optimization.
Alan Weiss
MATLAB mathematical toolbox documentation
Temesgen
on 19 Apr 2023
Alan Weiss
on 19 Apr 2023
See if you like how this looks. I did not use MultiStart; before we do that you have to see how you like the plain lsqnonlin solution.
Alan Weiss
MATLAB mathematical toolbox documentation
Alan Weiss
on 20 Apr 2023
OK, I clearly misunderstood what are the parameters to vary in your problem. And I am not sure that I understood correctly what you are trying to match, meaning which data are you trying to fit and which output of the ODE you want to match.
Once more I ask you to perform the following.
- Give a function F(x) that is the ODE solver, taking your parameters x to a solution y(t). Obviously, I am not sure what that function is in the code that you gave me.
- After that we can try to identify the data that you want F(x) to fit. We will call an optimizer and minimize the sum of squares of some parts of y(t) minus some data d(t).
So I am asking you to give F(x). Not to optimize it, just give clear, unambiguous, working code that takes an input set of parameters x and returns an ODE solution y(t).
Alan Weiss
MATLAB mathematical toolbox documentation
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!