genetic algorithm for curve fitting

Hello Everyone
I want to Fit a curve (called MFit) on another curve (called M)
MFit is a function and defined by the following relation:
MFit = M0 + c0 * (h * z - log(z - z0 / z0))
and M is a 100-element vector. I want to fit MFit on M by choosing the right value of c0. z is a 100-element vector and M0,h and z0 are constants. What I have in mind is to define a target function as
Fun1 = abs(M - MFit)
so that by minimzing it, MFit will be fit. This is my proposed method:
MFit = @(c0) (M0 + c0 * (z - h * log((z + z0) / z0)));
Fun1 = @(c0) abs(M - MFit);
rng default
C0 = ga(Fun1,1);
but things go wrong when I run the code. Can anybody help me how I may solve this problem with genetic algorithm?

 Réponse acceptée

Star Strider
Star Strider le 28 Juin 2020
I would do something like this (with ‘M’ and the constants already existing in your workspace):
MFit = @(c0,M0,h,z,z0) (M0 + c0 * (z - h * log((z + z0) / z0)));
Fun1 = @(c0) norm(M - MFit(c0,M0,h,z,z0));
c0_est = ga(Fun1, 1);
The fitness funciton must return a scalar value. (The ga call can be further optimised by using an optons structure.)
.

4 commentaires

Proman
Proman le 28 Juin 2020
Modifié(e) : Proman le 28 Juin 2020
I believe you are absolutely correct.
Thank you for your direction. What I expected to see in fact was a more fit curve however, rather than this. Would you be more kind to help me enhance the optimization?
Star Strider
Star Strider le 28 Juin 2020
As always, my pleasure!
With only one parameter, further optimisation is likely not possible, although running ga in a loop to see the best parameter estimate is. For that, you need to record the second output of ga that is the final fitness value. The lowest one corresponds to the parameter estimate creating the best fit.
If you want to fit either only ‘c0’ or all the parameters, the attached code (that I wrote to fit a differential equation) is the prorotype I use for more general ga regressions.
Proman
Proman le 28 Juin 2020
Many thanks for your productive direction Sir
Star Strider
Star Strider le 28 Juin 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by