简体   繁体   中英

matlab curve fitting: restrictions on parameters

I have 5 non-parametric models all with 5 to 8 parameters. This models are used to fit longitudinal data y(t) with t being time. Every datafile is fitted by all 5 models for comparison. The model itself cannot be altered.

For fitting starting values are used and these are fitted into a lsqcurvefit model using a levenberg-marquardt algortihm. So I've written a script for several models and one function for curvefitting

if i perform the curve fitting a lot of the starting values are wandering off to extreme values. This is the thing I want to avoid since these parameters should stay in the proximity off it's starting values and should only change between a well defined range or so that only curve fits within a standard deviation are included.Important to note here is that this restrictions should be imposed during the curve fitting (iterative numerization techique) and not afterwards.

The function I've written to fit models into height:

% Fit a specific model for all valid persons
    try
        opts = optimoptions(@lsqcurvefit, 'Algorithm', 'levenberg-marquardt'); 
        [personalParams,personalRes,personalResidual] = lsqcurvefit(heightModel,initialValues,personalData(:,1),personalData(:,2),[],[],opts);
    catch
        x=1;
    end

The function I've written for one of my models

   elseif strcmpi(model,'jpss')
    % y = h_1(1-(1/(1+((t+0.75)^c_1/d_1)+((t+0.75)^c_2/d_2)+((t+0.75)^c_3/d_3)))
%     heightModel = @(params,ages) params(1).*(1-1./(1+((ages+0.75).^params(2))./params(3) + ((ages+0.75).^params(4))./params(5) + ((ages+0.75).^params(6))./params(7)));
    heightModel = @(params,ages) params(1).*(1-1./(1+(((ages+0.75)./params(3)).^params(2)) + (((ages+0.75)./params(5)).^params(4)) + ((ages+0.75)./params(7)).^params(6))); % Adapted 25/07
    modelStrings = {'h1','c1','d1','c2','d2','c3','d3'};

    % Define initial values
if strcmpi('male',gender)
    initialValues = [174.8 0.6109 2.9743 3.614 9.88 22.393 13.59];
else
    initialValues = [162.7 0.6546 2.43 4.011 8.579 18.394 11.846];
end    

What I would like to do:

Is it possible to place restrictions on every startingvalue @initial values? Putting restrictions on lsqcurvefit wouldn't be a good idea I think since there are different models with different starting values and different ranges that are allowed.

I had 2 things in my mind: 1. using range and place this between the initial values initialValues = [162.7 0.6546 2.43 4.011 8.579 18.394 11.846]` if range a1=[150,180]; range a2=[0.3,0.8] and so one

  1. place lb and ub restrictions seperatly on all my initialvalues between lsqcurvefit if Heightmodel='name model' initial value* 1.2 and lb = initial value* 0.8

Can someone give me some hints or pointers because I can't make it work.

Thanks in advance

Lucy

Could somebody help me out

You state: there are different models with different starting values and different ranges that are allowed. This is where you can use ub and lb . How to do this is outlined in the lsqcurvefit documentation:

 X=LSQCURVEFIT(FUN,X0,XDATA,YDATA,LB,UB) defines a set of lower and upper bounds on the design variables, X, so that the solution is in the range LB <= X <= UB. Use empty matrices for LB and UB if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; set UB(i) = Inf if X(i) is unbounded above. 

For instance in the following example the parameters are constrained within limits during the fit. The lower bound ( lb ) and upper bound ( ub ) are set to 20% below and above the starting values, respectively.

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) )));
initialValues = [161.92 0.4173 0.1354 0.090 0.540 2.87 14.281 0.3701];
lb = 0.8*initialValues; % <-- lower bound is 20% smaller than initial par values
ub = 1.2*initialValues;
[parsout,resnorm,residual] = lsqcurvefit(heightModel,initialValues,t,ht,lb,ub);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM