maximize a log-likelihood function

4 views (last 30 days)
Isma
Isma on 2 Jun 2015
Answered: Alan Weiss on 2 Jun 2015
Hi all,
I am looking for an advice in regards the following task:
I've set up a function
function proba = pdf(x,a,b,c,d);
where a,b,c,d are scalars and x a vector. So far I am happy with the output.
After defining the log-likelihood function in a separate function-m file such as:
%_llik.m
function loglik=_llik(theta,data);
loglik=-sum(log(pdf(data,theta1,theta2,theta3,theta4)));
I've run from a script file (optimization without constraints):
theta0=[1.3,0.89,0.034,0.0056]
[theta_eq,fval,exitflag,output,grad,hessian] = ...
fminunc(@(theta) _llik(theta,data),theta0)
that unfortunately returns:
Undefined function '_llik' for input arguments of type 'double'.
Error in @(theta) _llik(theta,data)
Error in fminunc (line 254)
f = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.
Error using edit (line 66)
Undefined function or variable 'theta'.
Hence my questions:
1/ are the errors due to my function proba which should be re-built in array terms such as:
function proba = pdf(data,theta(1),theta(2),theta(3),theta(4));
2/ Having read a bit of documentation on @fmincon, is it possible 'clearly' to illustrate how can I add constraints on
0<theta(1)<=2;
-1<=theta(2)<=1;
0<=theta(3)<=+inf;
-inf<=theta(4)<=+inf; % belongs to R not sure if it's worth constraining it to -inf;+inf
Actually I am not sure if i can set:
lb=[0,-1,0,-inf] and ub = [2,1,+inf,+inf]
Thanks in advance
  1 Comment
David Young
David Young on 2 Jun 2015
Might be a red herring, but I wonder about that initial underscore. Is it in the m-file name? If so, could there be a system problem with filenames beginning with underscore that stops their being found? Might be worth the experiment of renaming the file and the function.

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 2 Jun 2015
You are quite right, the way to keep the function from stepping out of bounds is to set the bounds exactly as you guessed:
lb = [0,-1,0,-Inf];
ub = [2,1,Inf,Inf];
Make sure that you pass the bounds to fmincon correctly:
[x,fval,exitflag] = fmincon(@_llik,theta0,[],[],[],[],lb,ub)
Alan Weiss
MATLAB mathematical toolbox documentation

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!