필터 지우기
필터 지우기

fminunc error message multiple variables

조회 수: 2 (최근 30일)
mathxaz
mathxaz 2019년 1월 6일
댓글: Stephan 2019년 1월 6일
Hello everyone!
I want to minimize the following function that I wrote:
function ll = ll_wbl(A, N, Y, X, sum_ll)
%A=theta, A(1)=beta, A(2)=kappa
lambda=exp(X*A(1));
ll=N*log(A(2))+(A(2)-1).*log(Y)-A(2).*log(lambda)-(Y./lambda).^A(2);
ll=-ll;
if sum_ll==true
ll=sum(ll);
end
%grad=sum(Y.*X);
end
over the vector A by using fminunc:
clc; clear;
data = xlsread('ema1996_reduced.xls', 'Sheet1');
UNDUR = data(:,1);
UI = data(:,2);
RR = data(:,3);
RRUI=data(:,4);
DR=data(:,5);
DRUI=data(:,6);
LWAGE=data(:,7);
TENURE=data(:,8);
NONWHITE=data(:,9);
% Store as Y and X matrices
N = size(data, 1);
Y = UNDUR;
X = [ones(N, 1) UI RR RRUI DR DRUI LWAGE TENURE NONWHITE];
A0=zeros(2,1);
% Optmizer settings
options = optimoptions(@fminunc, 'Algorithm', 'quasi-newton');
% Estimate model
[A, fval, exitflag, output ] = fminunc(@ll_wbl, A0, options, Y, X, true);
Unfortunately, this doesn't work out somehow.
I get the following error:
Not enough input arguments.
Error in ll_wbl (line 9)
if sum_ll==true
Error in fminunc (line 278)
f = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINUNC cannot continue.
I don't understand what's going on here since I am a newbie. Maybe someone can help me out?
Thanks in advance!

채택된 답변

Stephan
Stephan 2019년 1월 6일
Hi,
fminunc is only able to pass the optimization variable to the objective function. Since your function needs additionally input arguments, you need to pass them to the objective function.
Read here:
Best regards
Stephan
  댓글 수: 12
mathxaz
mathxaz 2019년 1월 6일
Allright, I see the difference.
Then it might be useful to use sum(sum(ll)) although I still have to think about if it gives me what I want to :)
Thank you so much for your effort!!!
Stephan
Stephan 2019년 1월 6일
please accept useful answers. i wish you success !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stephan
Stephan 2019년 1월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by