Pass RSS as fitness error using GA tool optimisation

1 view (last 30 days)
I and need to use GA tool to optimize parameters for a system of ODE. I started with a simple ODE (dNdt=r*exp(-tN)). I loaded the data for N and t, so I need GA to optimize parameter r. Now I need to pass RSS as fitness function so instead of minimizing the function itself, I need to minimize the fitness error. I would greatly appreciate help (examples) with writing the fitness function.

Answers (2)

Alan Weiss
Alan Weiss on 11 Mar 2014
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Sophie
Sophie on 11 Mar 2014
My problem here is that my function is a differential equation (or a system of ODE) and i am really stuck in defining RSS for differential equation to measure the fit. Thanks a lot for your help.
Alan Weiss
Alan Weiss on 12 Mar 2014
This doesn't sound like a MATLAB problem, it sounds as if you don't know how to write a formula for the fitness function. Is that correct? If not, then please tell us the formula for your fitness function, and we might be able to help you get it into GA syntax.
But if this is correct, then perhaps you can say in words what you would like to minimize, subject to what kind of constraints, and then maybe we can try to help you formulate your problem more mathematically.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.


Sophie
Sophie on 13 Mar 2014
Yes, I guess it's math and Matlab question. So i am optimizing parameter x in my model dNdt=xexp(-tN). This is a simple problem that I need to understand to move on to a more complicated one. So i see my .m file that i will be passing to GA for minimization as:
function fitness=squared_residuals(N)
% this function will estimate how good Parameter fitted by GA fits my data
N=load (Nfile.txt)
T=load (Tfile.txt)
% this is the data i need to fit
fitness=residual sum of squares (@my_ODE, initial data)
% i can't figure out what my residual sum of squares should look like
function dNdt=my_ODE(x)
%This is the function i am fitting the data to, x is parameter i want to estimate
dNdt=x*exp(-tN)
End
End
I am sorry if it's too sloppy, I am just learning. I appreciate your help.
  2 Comments
Alan Weiss
Alan Weiss on 13 Mar 2014
Sophie, I am not sure what to tell you. It is possible that you have a simple model such as
dN/dt = -x*N(t)
which has the solution
N(t) = N(0)*exp(-x*t)
Or you could have the model that you say,
dN/dt = x*exp(-t*N(t))
which is a strange model to my eyes, but maybe that is what you have. In that case dN(t)/dt is strictly positive for positive values of x, so N(t) increases to some limiting value.
In any case, you have data Nobserved(Tobserved) for a number of times Tobserved. You want to find the parameter x, and possibly the parameter N(0), that makes you function N(t) fit the data best.
Usually the "best" fit is one that minimizes the sum of squares of the difference between the observations and the model. In other words, you want to minimize
sum( (Nobserved(Tobserved) - N(Tobserved))^2 )
To do so you need to make a function that takes your parameter x, or parameters x and N(0), and gives you a function N(T) for all values of T that you care about. You can get N(T) analytically for some models, or you can use ode45 or another MATLAB differential equation solver to give you the function N(T) for each x, N(0).
After that you can use any optimization routine you like, such as GA. I think you would be better served by lsqnonlin or lsqcurvefit, but your choice of optimization function is yours to make.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!