fminunc error message multiple variables
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
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
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!