1function [MAP,Eapx,x] = psfit_aph_weighted(E,n)
2w = (E(end).^(1/length(E))).^-(1:length(E));
3%% objective function weights
9E = (E(:) ./ Escale(:))
';
10w = (log(E(end)).^(1/length(E))).^-(1:length(E));
12x0 = rand(1,2*n); x0(1:n)=x0(1:n)/sum(x0(1:n));
21T0 = tic; % needed for outfun
22options=optimset( 'Display
','off
', 'LargeScale
','off
','MaxIter
',MAXITER, 'MaxFunEvals
',1e10, ...
23 'MaxSQPIter
',500, 'TolCon
',TOL, 'Algorithm
', 'interior-point
', 'OutputFcn
', @psfit_aph_weighted_outfun);
25%% optimization program
26[x, f]=fmincon(@objfun,x0,[],[],[],[],x0*0+EPSTOL,[],@nnlcon,options);
28MAP = {T,-T*ones(n,1)*alpha};
29MAP = map_scale(MAP, Eunscaled(1));
30MAP = map_normalize(MAP);
33 function [alpha,T] = topar(x)
35 T = diag(-1./(x((n+1):2*n))) + diag(1./(x((n+1):(2*n-1))),1);
38 function [c,ceq] = nnlcon(x)
41 Eapx(j)=factorial(j)*alpha*(-inv(T)^j)*ones(n,1);
44 ceq(1:3) = (w(1:3) .* abs( log(E(1:3)) - log(Eapx(1:3))))';
45 ceq(end+1:end+n) = sum(alpha) - 1;
48 function f = objfun(x)
51 Eapx(j)=factorial(j)*alpha*(-inv(T)^j)*ones(n,1);
53 f = w * abs( log(E) - log(Eapx) )
';