Curve fitting by Genetic Algorithm
Show older comments
Hi everybody, I have a very simple theoric problem but I don't know how to resolve it.
I just wanna do a curve fitting like this:

I want the red line to fit the red dashed one as much as possible in the [0.3 - 0.6] interval.
The red line is a 100x1 vector (x-axis) and 100x1 vector (y-axis).
The red dashed curve is given by this equation (much longer, cropped here):
function [ d2 ] = d2_current( alpha,beta,phi,N,V )
d2 = (4903985730770845.*N.*(((exp(alpha.*(phi - V.*(beta - 1))) + 1).*((alpha.^2.*beta.^2.*exp(alpha.*...
end
Where V is the dependent variable, the previous 100x1 vector (x-axis) corresponding to the [0.3 - 0.6] interval.
The equation depends on 4 independent parameters, each one of them may be included in these intervals:
beta; from to a 1
alpha; from 0 to 15
N; from 0 to 300
phi; from 0 to 3
I have to vary these parameters in order to obtain the best fitting, note that the parameters value must be the same for one single fitting.
The first thing I did was 4 different 'for' loops for each parameter and try to compare each single result with the red curve my means of the euclidean distance. (simplified code):
cont = 0;
for beta = 0:0.01:1
for alpha = 0:0.01:15
for N = 0:1:300
for phi = 0:0.01:3
distance_euclidean(cont,1) = norm(current_red_curve - current_red_dashed_curve);
cont = cont + 1;
end
end
end
end
minim_eucl = min(distance_euclidean);
The minimum euclidean distance would be the best fitting. For the graph example:
beta = 1;
alpha = 15;
N = 300;
phi = 0.45;
Everything is fine until this point, but there's a big problem: the computing time is just huge when the step in the 4 intervals decreases (needed because of the poor fitting).
Looking for better solutions I found the possible way to go: the genetic algorithm. I've been trying it on the Matlab optimization tool, but with no results.
Could somebody help me out?
Thank you very much for your help.
Regards,
8 Comments
Star Strider
on 18 Oct 2019
Post your data, and the correct ‘d2_current’ function.
What are your independent and dependent variables? What parameters do you want to estimate?
Juan Castillo
on 18 Oct 2019
Juan Castillo
on 22 Oct 2019
Star Strider
on 22 Oct 2019
‘The main goal here is look for the parameters which best fit both the black and the blue one.’
I doubt that is possible. The (Ve,ye) data plot a curve (blue pentagrams in your plot), and the (Vc,Ic) data plot a straight line (the black line in your plot).
‘What am I doing wrong?’
You are assuming that the parameters for your function that describe the blue pentagram data curve will also fit the black data straight line. They have absolutely nothing in common. If you have two data sets that were similar, with similar ranges and other characteristics in both the independent and dependent variables, you could probably get a parameter set that fit both of them (although neither as well as specific parameter estimates for each one). However here that is not possible.
Juan Castillo
on 23 Oct 2019
Star Strider
on 23 Oct 2019
The expression itself appears to me to be correct, although I have never done such an optimization. The problem of course is that you are attempthing to identify the same parameters from two different data sets of different lengths, with different characteristics, and over different ranges of the indpendent variable. I cannot imagine that this will ever be successful.
Juan Castillo
on 23 Oct 2019
Star Strider
on 23 Oct 2019
As always, my pleasure.
Accepted Answer
More Answers (1)
Alex Sha
on 19 Oct 2019
1 vote
Rerfer the results below:
Root of Mean Square Error (RMSE): 0.00353350868235726
Sum of Squared Residual: 0.00029965640659906
Correlation Coef. (R): 0.975244832242099
R-Square: 0.95110248281492
Adjusted R-Square: 0.946445576416342
Determination Coef. (DC): 0.902466880697908
Chi-Square: -0.0236084937698218
F-Statistic: 41.4027542316901
Parameter Best Estimate
---------- -------------
beta1 1
alpha 15
n 105.578188880725
phi 0.388542678989983

1 Comment
Juan Castillo
on 19 Oct 2019
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!


