-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcontextFit3.m
More file actions
40 lines (37 loc) · 1022 Bytes
/
contextFit3.m
File metadata and controls
40 lines (37 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [err,pt, testErr, exitflag] = contextFit3(f1,ftest,maxIter)
if (nargin < 5)
maxIter = 500;
end
lowLimits = zeros(f1.npar,1);
highLimits = lowLimits;
i1 = 1;
for imix = 1:length(f1.mixers)
mix = f1.mixers{imix};
if (strcmp(mix.funcType,'scale'))
lowLimits(i1) = -1.0;
highLimits(i1) = 2.0;
i1 = i1+1;
for i2 = 2:mix.npar
lowLimits(i1) = -inf;
highLimits(i1) = inf;
i1 = i1+1;
end
else
for i2 = 1:mix.npar
lowLimits(i1) = -inf;
highLimits(i1) = inf;
i1 = i1+1;
end
end
end
start = f1.getPars;
options = optimset('DiffMinChange',1.0e-4,'TolFun',1.0e-3, ...
'TolX',3.0e-3,'MaxFunEvals',maxIter);
[pt,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@f1.err, start,lowLimits,highLimits,options);
err = sqrt(residual*residual'/length(residual))*627.509;
if (~isempty(ftest))
testres = ftest.err(ftest.getPars);
testErr = sqrt(testres*testres'/length(testres))*627.509;
end
end