2016-10-06 2 views
0

MATLAB의 fminunc 함수 최적화 과정을 분석하고 있습니다.MATLAB fminunc 그래디언트 기록

모든 반복에서 그래디언트 값의 배열을 얻을 수있는 방법이 있습니까?

감사합니다.

답변

1

예, 그렇습니다. Output Function을 사용해야합니다.

function optim_test 
    grad_array= []; % initial array size is unknown 
    f= @(x)x(1).^2+x(2).^4; % just for example 
    options= optimset('OutputFcn',@outfun); % set the output function 
    x= fminunc(f,[1 1],options); 
    disp(grad_array); 

    function stop = outfun(x, optimValues, state) 
     grad_array(end+1,:)= optimValues.gradient; 
     stop= false; 
    end 
end 
+0

감사합니다. – colge

관련 문제