1function [E1j,E3j,f]=kpcfit_sub_bcfit(E,SCVj,G2j,BC,BCLags,MaxIterBC, MaxRunsBC)
2%% optimization parameters
11NBC=norm(BC,2); % normalizing constants
for bicovariances
13% truncate bicorrelations when it gets negative
15for index=1:size(BCLags,1)
16 if find(diff(BCLags(index,:))<0)
23E1j=E(1).^(1/NumMAPs)*ones(1,NumMAPs);
27xparamset = {}; % record all the possible x params
28fset = []; % record the objective function values
for each param set
32 E2j(index)=(1+SCVj(index))*E1j(index)^2;
33 E3j(index)=(3/2+t)*E2j(index)^2/E1j(index);
39%fprintf(1,'bcfit: maximum number of solver iterations per run
is MaxIterBC = %d\n
', MaxIterBC);
43 fprintf(1,'bcfit: run %d of %d
',ind, MaxRunsBC);
47 options = optimset('LargeScale
','off
', ...
48 'MaxIter
',MaxIterBC, ...
49 'MaxFunEvals
',1e10, ...
53 'DiffMinChange
',1e-10, ...
54 'OutputFcn
',@(x,optimValues,state) kpcfit_sub_bcfit_outfun(x,optimValues,state,MaxIterBC,MaxTimeBC,tstart,f_best));
56 [x,f,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],0*x0+EPSTOL,[],@nnlcon,options);
59 fprintf(1,'(%3.3f sec, %d iter) f=%f
',toc, output.iterations, f);
66 fprintf(1,'**best**
',toc);
76 x0 = x0base .* [(0.25+1.75*rand(NumMAPs,1)); ones(NumMAPs,1)]';
79 E2j(index)=(1+SCVj(index))*x0(index)^2;
80 x0(NumMAPs+index)=(3/2+t)*E2j(index)^2/x0(index);
84[E1j,E3j]=xtopar(xparam_best);
85E1j(1)=E(1)/prod(E1j(2:end));
90 function [E1j,E3j]=xtopar(x)
92 E3j=x((NumMAPs+1):end);
93 E1j(1)=E(1)/prod(E1j(2:end));
95 function [c,ceq]=nnlcon(x)
100 c(end+1)=(2+EPSTOL)*E1j(j)^2-E2j(j); % E2j(j) > 2*E1j(j)^2
101 c(end+1)=(3/2+EPSTOL)*E2j(j)^2/E1j(j)-E3j(j);
103 % 3*E2j(j)^2/(2*E1j(j))
106 %
if SCV
for the first MMPP2
is > 1
107 % add the constraint that E2 > 2*E1^2
108 % and the constraint that E3 > 3*E2^2/(2*E1)
109 c(end+1)=(2+EPSTOL)*E1j(1)^2-E2j(1);
110 c(end+1)=(3/2+EPSTOL)*E2j(1)^2/E1j(1)-E3j(1);
113 temp = temp/(factorial(3))^(NumMAPs-1);
114 c(end+1) = temp/E(3) -2;
115 c(end+1) = 0.5 - temp/E(3);
117 c(end+1) = 1/3*E1j(j)/(E2j(j)-2*E1j(j)^2)*E3j(j)-1/2*E2j(j)^2/(E2j(j)-2*E1j(j)^2) - 1/(1e+16);
118 c(end+1) = 1e-16 - 1/3*E1j(j)/(E2j(j)-2*E1j(j)^2)*E3j(j)-1/2*E2j(j)^2/(E2j(j)-2*E1j(j)^2);
125 BCj=ones(1,size(BCLags,1));
127 [compMAP, subMaps, err] = kpcfit_sub_compose(E1j, SCVj, E3j, G2j);
133 % scale MAP to match E(1)
134 compMAP=map_scale(compMAP, E(1));
136 for indexL=1:size(BCLags,1)
137 BCj(indexL)=(map_joint(compMAP,BCLags(indexL,:),[1,1,1]));
140 f=norm(BC-BCj,2)/NBC;