LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
kpcfit_sub_acfit.m
1function [resSCV,resG2,fobjAC]=kpcfit_sub_acfit(E,SA,SAlags,J,MaxIterAC, MaxRunsAC, MaxResAC, AnimateAC)
2%% optimization parameters
3MaxTimeAC = 10; % 10sec
4MaxResAC=min([MaxResAC,MaxRunsAC]);
5
6
7%% other variables
8SCV=(E(2)-E(1)^2)/E(1)^2;
9NSA=norm(SA,2); % normalization constant for objective function
10SCVJ=SCV; % initialize nnlcon variable
11%%
12global MAXITER;
13global MAXCHECKITER;
14global T0;
15global lgkx;
16global stagnval;
17global stagniter;
18lgkx = [];
19stagnval = 0;
20stagniter = 0;
21
22%% multi-start optimization
23fset = []; % record the objective function values for each param set
24xparamset = {}; % record all results
25xparam_best = [];
26f_best = inf;
27bestindex = 0;
28for i = 1:MaxRunsAC
29 x0=[(1+rand(J,1)); rand(J,1)]; x0=x0(:)';
30 tstart = tic();
31 optimoptions = optimset('Algorithm','interior-point', ...
32 'LargeScale','off', ...
33 'MaxIter',MaxIterAC, ...
34 'MaxFunEvals',1e10, ...
35 'MaxSQPIter',50, ...
36 'TolCon',kpcfit_tol, ...
37 'Display','off', ...
38 'OutputFcn',@(x,optimValues,state) kpcfit_sub_acfit_outfun(x,optimValues,state,MaxIterAC,MaxTimeAC,tstart,f_best));
39 fprintf(1,'acfit: run %d of %d ',i,MaxRunsAC);
40 tic;
41 [x,f]=fmincon(@objfun,x0,[],[],[],[],0*x0+kpcfit_tol,[],@nnlcon,optimoptions);
42 fprintf(1,'- objfun: %d (%3.3f sec) ',f,toc);
43 xparamset{end+1} = x;
44 fset(1,end+1) = f;
45 if f < f_best
46 fprintf(1,'**best**',toc);
47 f_best = f;
48 xparam_best = x;
49 end
50 fprintf(1,'\n',toc);
51end
52[vl,ind] = sort(fset,2,'ascend');
53
54resG2 = {};
55resSCV = {};
56fobjAC = [];
57for i = 1:MaxResAC
58 [SCVj,G2j]=xtopar(xparamset{ind(i)});
59 G2j(find(G2j>1-kpcfit_tol))=1-kpcfit_tol;
60 resSCV{end+1} = SCVj;
61 resG2{end+1} = G2j;
62 fobjAC(i) = fset(1,ind(i));
63end
64
65%%
66 function [SCVj,G2j]=xtopar(x)
67 SCVj = x(1:J);
68 G2j = x((J+1):end);
69 end
70
71 function [c,ceq]=nnlcon(x)
72 [SCVj,G2j]=xtopar(x);
73 ceq=[];
74 c=[];
75 %% SCV CONSTRAINTS
76 c(end+1) = (0.5-kpcfit_tol)-SCVj(1); % SCVj(1) > 0.5
77 for j=2:J
78 c(end+1) = (1+kpcfit_tol) - SCVj(j); % SCVj(j) > 1.1
79 end
80 %% G2 DECAY RATE CONSTRAINTS
81 for j=1:J
82 c(end+1) = G2j(j) - (1-kpcfit_tol); % G2j(j) < 1
83 c(end+1) = kpcfit_tol - G2j(j); % G2j(j) > 0
84 end
85 end
86
87 function f=objfun(x)
88 [SCVj,G2j]=xtopar(x);
89 [SCVJ,acfCoeff]=kpcfit_sub_eval_acfit(SCVj,G2j,SAlags);
90 if AnimateAC
91 loglog(SA); hold on; loglog(acfCoeff); ylim([1e-6,1]);
92 ylabel('autocorrelation \rho_k ');
93 xlabel('lag k - [log]'); hold off;
94 pause(0.001)
95 end
96 f=norm((SA-acfCoeff),1)/NSA + (SCVJ - SCV)^2/SCV^2;
97 end
98
99end