levenberg-marquardt in lsqcurvefit

6 次查看(过去 30 天)
Hello
How do I use the levenberg-marquandt algortime in lsqcurve fit instead of the default trust-region-reflective algorithm?
[parameters,resnorm,residual,exitflag,output] = lsqcurvefit(heightModel,initialValues,filteredData(:,1),filteredData(:,2));
is the formula I use in my function
Can anyone help me out?
Thanks in advance
Niels

采纳的回答

Matt Kindig
Matt Kindig 2013-8-15
Pass in an options structure:
opts = optimset('Algorithm', 'levenberg-marquardt');
[parameters,resnorm,residual,exitflag,output] = lsqcurvefit(heightModel,initialValues,filteredData(:,1),filteredData(:,2),[],[],opts);
You can see the various options in the Help docs for lsqcurvefit, at
doc lsqcurvefit

更多回答(1 个)

Niels
Niels 2013-8-15
Thanks for answering
I have used this for individual fitting in the following construct:
CODE PART A
validFitPersons = true(nbValidPersons,1);
for i=1:nbValidPersons
personalData = data{validPersons(i),3};
personalData = personalData(personalData(:,1)>=minAge,:);
% Fit a specific model for all valid persons
try
opts = optimset('Algorithm', 'levenberg-marquardt');
[personalParams,personalRes,personalResidual] = lsqcurvefit(heightModel,initialValues,personalData(:,1),personalData(:,2),[],[],opts);
%catch
%x=1;
end
The intial starting values and the formula used to fit is given by:
CODE PART B
strcmpi(model,'jpa2')
% y = a.*(1-1/(1+(b_1(t+e))^c_1+(b_2(t+e))^c_2+(b_3(t+e))^c_3))
heightModel = @(params,ages) abs(params(1).*(1-1./(1+(params(2).* (ages+params(8) )).^params(5) +(params(3).* (ages+params(8) )).^params(6) +(params(4) .*(ages+params(8) )).^params(7) )));
modelStrings = {'a','b1','b2','b3','c1','c2','c3','e'};
% Define initial values
if strcmpi('male',gender)
initialValues = [175 0.35 0.12 0.076 0.43 2.8 20 0.34];
else
initialValues = [162 0.43 0.13 0.089 0.48 2.9 16 0.4];
end
Switching off the catch command in CODE PART A and adding the levenberg-marquandt command also in CODE PART A caused my data to be much closer towards the initial values then otherwise. This is a good thing.
How can I make my curve fitting stay looking much closer around my initial values and not spreading out too much?
Anyhelp?

Community Treasure Hunt

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

Start Hunting!

Translated by