function K = mink(phi0,m0,n0) % minimizes F(k) = Psi(k) - % we'll be using the smoothed version global phi m n a m=m0; n=n0; phi = phi0; %a = 1; %K = randn(size(phi))'; %K = graddesc(K,phi); %K = fmincon(@myobj,K,[],[],[],[],-ones(size(K)),ones(size(K))); get_ccgenerators return function get_ccgenerators % tries to get the generators for the convex cone global G phi %G = []; %K = randn(size(phi))'; %%K = zeros(size(phi))'; %%i = randel(1:length(K)); %%K(i) = rand-.5; %G = fmincon(@myobj,K,[],[],[],[],-ones(size(K)),ones(size(K))); G = -eye(length(phi)); while 1 K = randn(size(phi))'; %K = K/max(abs(K)); %i = randel(1:length(K)); %K = zeros(size(phi))'; %K(i) = rand-.5 %K(i) = 2*flip-1; K = fmincon(@myobjG,K,[],[],[],[],-ones(size(K)),ones(size(K))); G = [G, K]; pinds = convhullinds(G) G = G(:,pinds); end return function y = myobjG(K) global phi G y = F(K,phi); % want K to be far from all elements in G KK = repmat(K,[1,size(G,2)]); y = y - 0.001*sum(sum((G-KK).^2)); return function y = myobj(K) global phi y = F(K,phi); return function f = F(K,phi) global m n f = Psi(K,m,n) - phi*K; %f = Psi(K,m,n); return function nd = ndF(K,phi) nd = Ndiff('mylocF',1,{K,phi}); nd = nd(:); KND = [K nd] return function y = pl(x) global m n a y = x.*(x>0); return function y = spl(x) global m n a y = log(1+exp(a*x))/a; return function z = softmax(x,y) z = x + pl(y-x); return function S = Psi1(K,m,n) S1 = Psi( K,m,n); S2 = Psi(-K,m,n); S = softmax(S1,S2); return function S = Psi(K,m,n) S = 0; for t=1:n S = S + sum(pl(K)); K = getK1(K,m,n-t+1); end return function K = graddesc(K,phi) d = 1; mu = .95; del0 = zeros(size(K)); goN = 1; while goN %K = K/max(abs(K)); nd = ndF(K,phi); del = d*nd + mu*del0; %K = K - del*nd; K = K - del; del0 = del; N = sum(abs(nd)); goN = (N>0.0000001); f = F(K,phi); fprintf('F(k) = %1.9f \n',f); end return