1function [resSCV,resG2,fobjAC]=kpcfit_sub_acfit(E,SA,SAlags,J,MaxIterAC, MaxRunsAC, MaxResAC, AnimateAC)
2%% optimization parameters
4MaxResAC=min([MaxResAC,MaxRunsAC]);
8SCV=(E(2)-E(1)^2)/E(1)^2;
9NSA=norm(SA,2); % normalization constant
for objective function
10SCVJ=SCV; % initialize nnlcon variable
22%% multi-start optimization
23fset = []; % record the objective function values
for each param set
24xparamset = {}; % record all results
29 x0=[(1+rand(J,1)); rand(J,1)]; x0=x0(:)
';
31 optimoptions = optimset('Algorithm
','interior-point
', ...
32 'LargeScale
','off
', ...
33 'MaxIter
',MaxIterAC, ...
34 'MaxFunEvals
',1e10, ...
36 'TolCon
',kpcfit_tol, ...
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);
41 [x,f]=fmincon(@objfun,x0,[],[],[],[],0*x0+kpcfit_tol,[],@nnlcon,optimoptions);
42 fprintf(1,'- objfun: %d (%3.3f sec)
',f,toc);
46 fprintf(1,'**best**
',toc);
52[vl,ind] = sort(fset,2,'ascend
');
58 [SCVj,G2j]=xtopar(xparamset{ind(i)});
59 G2j(find(G2j>1-kpcfit_tol))=1-kpcfit_tol;
62 fobjAC(i) = fset(1,ind(i));
66 function [SCVj,G2j]=xtopar(x)
71 function [c,ceq]=nnlcon(x)
76 c(end+1) = (0.5-kpcfit_tol)-SCVj(1); % SCVj(1) > 0.5
78 c(end+1) = (1+kpcfit_tol) - SCVj(j); % SCVj(j) > 1.1
80 %% G2 DECAY RATE CONSTRAINTS
82 c(end+1) = G2j(j) - (1-kpcfit_tol); % G2j(j) < 1
83 c(end+1) = kpcfit_tol - G2j(j); % G2j(j) > 0
89 [SCVJ,acfCoeff]=kpcfit_sub_eval_acfit(SCVj,G2j,SAlags);
91 loglog(SA); hold on; loglog(acfCoeff); ylim([1e-6,1]);
92 ylabel('autocorrelation \rho_k
');
93 xlabel('lag k - [log]
'); hold off;
96 f=norm((SA-acfCoeff),1)/NSA + (SCVJ - SCV)^2/SCV^2;