Choosing Initial values for non-linear fitting and running Genetic Algorithm
Mostrar comentarios más antiguos
Note: This is a question based on suggestions/answers based on another question I had asked: link, but now a slightly different one.
Here is a summary: I am running an optics to calibrate an optical device. For this I need to fit a curve between two variables, voltage and phase. There are 7 different parameters
F= @(a,V) a(1).*(a(2) - a(3) - (a(2).*a(4))./(a(2).^2.*cos(a(5) - 2.*atan(exp(-(V - a(6))./a(7)))).^2 + a(4).^2.*sin(a(5) - 2.*atan(exp(-(V - a(6))./a(7)))).^2).^(1/2))
This is the best fit I could arrive at but however would prefer something that fits even better. [Atleast from x axis starting from 0.8 Volts]

I had some struggles to find the starting point of the parameters for such problems. It was suggested that I use either a global optimization algorithm like (Genetic Algorithm etc) to get some good starting values. However, I when I run the genetic algorithm, the program keeps running and doesn't stop at all. (I ran it for over 15 hours). Any suggestions on where things could have gone wrong? Also, is there any way I can keep better improving the parameter values that the algorithm predicts on loop?
Here are the constrains on the parameter
- a(1): (about 20000, 80000) - This is the ratio of the thickness of a crystal and the wavelength of the laser we are using.
- a(2) and a(4): (about 1.4-1.8) - Both these are refractive indices.
- No strict range on a(3)
- a(6) : Around (0.3-0.9) - These are some voltages in V.
- a(7): Around (0.3-2)- Again some voltage in V.
- a(5)- No strict range on this too
I am running a huge code but here is a part of the script which uses the GA or Multi-Start algorithm:
%Some nonsense that You might not need
function [volt,inten] = IntVoltFit(volt,inten,Phase)
syms G B net n n_e d z V1 Vo Vc b A n_c n_del p k
inten=inten/max(inten);
inten=inten-min(inten);
theta=b-(2*atan(exp(-((V1-Vc)/Vo))))
net=(n_e*n)/(sqrt((n*cos(theta))^2+(n_e*sin(theta))^2));
T = 1-(cos(d*(n-net-n_del)));
delta=d*(n-net-n_del+n_c)
sympref('PolynomialDisplayStyle','ascend');
latex(taylor(delta,V1,'ExpansionPoint',2,'Order',1))
b=[-26.05,20,-1.456,0.179,1.594,2.795];
Fit=@(b,V) b(1)+(b(2).*atan(b(3).*V+b(4).*V.^3+b(5))+b(6).*V);
latex(taylor(Fit(b,V1),V1,'ExpansionPoint',2,'Order',2))
%PROBABLY the relevant part for this question
V=volt
F= @(a,V) a(1).*(a(2) - a(3) - (a(2).*a(4))./(a(2).^2.*cos(a(5) - 2.*atan(exp(-(V - a(6))./a(7)))).^2 + a(4).^2.*sin(a(5) - 2.*atan(exp(-(V - a(6))./a(7)))).^2).^(1/2))
ftns= @(a_fit) norm(F(a_fit,V)-Phase)
[a_fit]=gamultiobj(ftns,7, [],[],[],[],[-Inf;-Inf;-Inf;-Inf;-Inf;-Inf;-Inf],[Inf;Inf;Inf;Inf;Inf;Inf;Inf]);
fprintf(1,'\tRate Constants:\n')
for k1 = 1:numel(a_fit)
fprintf(1, '\t\ta(%2d) = %8.5f\n', k1, a_fit(k1))
end
figure
plot(V, Phase, '.b')
hold on
plot(V, F(a_fit,V), '-r')
hold off
grid
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









