fminsearch (matlab) taking too much time -



fminsearch (matlab) taking too much time -

function a=obj(b,y, yl, tempcyc, cyc, yzero, age, agesq, educ, ageav, agesqav, educav, qv, year1, year2, year3, year4, year5, year6, year7, workregion1, workregion2, workregion3, workregion4, workregion5, workregion6, workregion7, workregion8, workregion9, workregion10, workregion11, workregion12, workregion13, workregion14, workregion15, workregion16, qw) a=0; i=1:715 s=0; m=1:12 p=1; t=1:8 p=p*(normcdf((2*y(i,t)-1)*(b(1)*yl(i,t)+b(2)*tempcyc(i,t)+b(3)*cyc(i,t)+b(4)*yzero(i,t)+b(5)*age(i,t)+b(6)*agesq(i,t)+b(7)*educ(i,t)+b(8)*ageav(i,t)+b(9)*agesqav(i,t)+b(10)*educav(i,t)+b(11)*1+b(12)*sqrt(2)*qv(m,1)+b(13)*year1(i,t)+b(14)*year2(i,t)+b(15)*year3(i,t)+b(16)*year4(i,t)+b(17)*year5(i,t)+b(18)*year6(i,t)+b(19)*year7(i,t)+b(20)*workregion1(i,t)+b(21)*workregion2(i,t)+b(22)*workregion3(i,t)+b(23)*workregion4(i,t)+b(24)*workregion5(i,t)+b(25)*workregion6(i,t)+b(26)*workregion7(i,t)+b(27)*workregion8(i,t)+b(28)*workregion9(i,t)+b(29)*workregion10(i,t)+b(30)*workregion11(i,t)+b(31)*workregion12(i,t)+b(32)*workregion13(i,t)+b(33)*workregion14(i,t)+b(34)*workregion15(i,t)+b(35)*workregion16(i,t)))); end s=s+qw(m,1)*p; end a=a+log(s/sqrt(pi)); a=-a; end

this objective function minimizing (actually maximizing; minimizing -a) , parameters estimating b=[b(1)............b(35)]. y, yl, tempcyc,.........., qw matrices imported data. objective function consists of product(across t=1:8) nested within sum (across m=1:12) in turn nested within sum (across n=1:715). , below code using fminsearch unconstrained minimization.

% %% minimization start=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; iter=50000; options=optimset('display','iter','maxiter',iter,'maxfunevals',100000); [b, fval, exitflag, output]=fminsearch(@(b)obj(b,y, yl, tempcyc, cyc, yzero, age, agesq, educ, ageav, agesqav, educav, qv, year1, year2, year3, year4, year5, year6, year7, workregion1, workregion2, workregion3, workregion4, workregion5, workregion6, workregion7, workregion8, workregion9, workregion10, workregion11, workregion12, workregion13, workregion14, workregion15, workregion16, qw), start, options);% %% results fprintf('[b] : % 1.4e % 1.4e %1.4e % 1.4e % 1.4e % 1.4e \n',...b(1),b(2),b(3),b(4), b(5),b(6),b(7),b(8), b(9),b(10),b(11),b(12), b(13),b(14),b(15),b(16), b(17),b(18),b(19),b(20), b(21),b(22),b(23),b(24), b(25),b(26),b(27),b(28), b(29),b(30),b(31),b(32), b(33),b(34), b(35)); end

the problem optmization results not show after 12+ hours (it still reflecting, expanding, contracting inside, etc.) give me thought on how create process faster?

thank you.

this not finish reply question; suggestion on how improve write code, half answer.

i write calling script this:

%% minimization b0 = zeros(1,35); iter = 5e4; options=optimset(... 'display' , 'iter',... 'maxiter' , iter,... 'maxfunevals', 1e5); info = {... yl, tempcyc, cyc, yzero, age, agesq, educ, ageav, agesqav, educav, qv, ... year1, year2, year3, year4, year5, year6, year7, ... workregion1, workregion2, workregion3, workregion4, workregion5, ... workregion6, workregion7, workregion8, workregion9, workregion10, ... workregion11, workregion12, workregion13, workregion14, workregion15, ... workregion16 }; [b, fval, exitflag, output] = fminsearch(@(b)obj(b, y,data,qw), b0, options); %% print results fprintf('[b]:'); fprintf('%1.4e', b); fprintf('\n');

(actually, wrap info in cells instead of having 16 workregions , 7 years etc. may not creator of data, may not possible)

you re-write objective function this:

function = obj(b, y, others, qw) = 0; spi = -0.5*log(pi); bb = num2cell(b); ii = 1:715 p = prod( normcdf((2*y(ii,1:8)-1) .* cellfun(@(x,y) x(ii,1:8).*y, others, bb)) ); s = sum( p*qw(1:12,1) ); = + log(s) + spi; end = -a; end

probably outer loop can simplified vectorized form. cannot test correctness of (or whether runs @ all), because don't have access data. trust thought -- can @ to the lowest degree read code, , spot error yourself.

matlab fminsearch

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -