From: Michael Shesko on 5 Apr 2010 09:10 I've been trying to use an nlinfit to fit two models (one is 1-parameter and one is 2-parameter) to a set of data. The model is a simple 11 state ode model called via an S-function. % parameter initial guess pinit = [1]; % guess kad PARAMS=statset('DerivStep',10^-12); % read 'help fminunc' for assistance w/ this call [params1,resi1,jac1,sig1]=nlinfit(big_X,big_Y,@(pinit,big_X) flinfit_obj_1p(pinit,tydata),[pinit],PARAMS) pinit = [1;1]; % guess kad, kdes [params2,resi2,jac2,sig2]=nlinfit(big_X,big_Y,@(pinit,big_X) flinfit_obj_2p(pinit,tydata),[pinit],PARAMS) As seen in the statset, I've fiddled with DerivStep and have tried using robust fitting as well. The problem always becomes that after the initial guesses, nlinfit changes the parameters extremely rapidly, causing the s-function to return a dx with value Inf. The objective function outputs the kad value at each iteration to show this. >> CSTR_paramfinder_12param For your convenience, warnings have been supressed. kad = 1.0000e-005 kad = 1.0000e-005 kad = 1.0000e-005 kad = -4.4448e+005 ??? Error using ==> CSTR_paramfinder_12param>flinfit_obj_1p at 236 State derivatives returned by S-function 'CSTR_1p_ode' in 'CSTR_model_1p/S-Function' during flag=1 call must be a real vector of length 11. Error in ==> CSTR_paramfinder_12param>@(pinit,big_X)flinfit_obj_1p(pinit,tydata) at 44 [params1,resi1,jac1,sig1]=nlinfit(big_X,big_Y,@(pinit,big_X) flinfit_obj_1p(pinit,tydata),[pinit],PARAMS) Error in ==> nlinfit>LMfit at 299 yfit = model(beta,X); Error in ==> nlinfit at 171 [beta_ls,J] = LMfit(X,y, model,beta,options,0,maxiter); Error in ==> CSTR_paramfinder_12param at 44 [params1,resi1,jac1,sig1]=nlinfit(big_X,big_Y,@(pinit,big_X) flinfit_obj_1p(pinit,tydata),[pinit],PARAMS) How do you fix these kinds of things? The better option would be to limit the step change at each iteration, but putting bounds on the parameters would also be an option. Is there any way to do this with nlinfit?
From: Peter Perkins on 5 Apr 2010 09:40 On 4/5/2010 9:10 AM, Michael Shesko wrote: > As seen in the statset, I've fiddled with DerivStep and have tried using > robust fitting as well. The problem always becomes that after the > initial guesses, nlinfit changes the parameters extremely rapidly, > causing the s-function to return a dx with value Inf. Michael, it's hard to say for sure, but this is often a symptom of either 1) a noisy objective function, so that the derivatives are not accurate, or 2) initial parameter values that are very far away from the solution, giving derivatives that are very large. Choosing a good initial parameter guess is important in nonlinear least squares. ALso, 1e-12 is most likely too small a step for the numerical derivatives. Hope this helps.
|
Pages: 1 Prev: really need a help Next: fill makes text on figure fuzzy |