## Constraints on a set of parameter in the likelihood function with fmincon

Alessandra Costa

### Alessandra Costa (view profile)

さんによって質問されました 2019 年 2 月 6 日

### Alessandra Costa (view profile)

さんによって 編集されました 2019 年 2 月 6 日
Alan Weiss

### Alan Weiss (view profile)

さんの 回答が採用されました
Hello to everyone, I setted a gamma loglikelihood function in Matlab, defined through a set of parameter theta, that is a 4 by 1 vector [w,a,b,eta] and variable x (a vector n by 1); by using the fmincon I would like to define some constraints. In particular, they are a>=0, b>=0 and a+b<1. The loglikelihood is a function of x and mi variables, where a is associated to x(t-1) and b to mi (t-1) but I've some difficulties in defining them. I think I can set lb=[-Inf 0 0 -Inf] but I don't know how to constrain the sum of a+b to be less than 1,or if I have to pass them in a anonymous function. The loglikood function refers to x, but I've also mi, in the specification that is created within the function by a for cycle.
Thank you in advance.

#### 0 件のコメント

サインイン to comment.

R2018b

## 2 件の回答

### Alan Weiss (view profile)

2019 年 2 月 6 日
採用された回答

I don't understand whether you are optimizing over x, over theta, or over both. If theta is fixed and you are optimizing over x, then you should write
[X,FVAL,EXITFLAG,OUTPUT] = fmincon(@(x)gammamle(theta,x),x0,A,b,[],[],lb,ub,[],options);
where x0 is your initial guess for x. In this case, ensure that your lower and upper bound vectors have the same length as your x0 vector, and the A and b matrices need to expect a variable of that size, too.
If you are optimizing over theta, then you should write
[X,FVAL,EXITFLAG,OUTPUT] = fmincon(@(theta)gammamle(theta,x),theta0,A,b,[],[],lb,ub,[],options);
where theta0 is your initial value of theta.
If you are optimizing over both x and theta, then you need to rewrite your objective function to accept a vector z = [x,theta] and parse out the variables in the function, something like
function f = myfun(z)
theta = z(1:4);
x = z(5:end);
% Your code here for computing y
end
Again, in this case, your lower and upper bounds should be the same length as z, and the A and b matrices need to be adjusted as well. The function call would be
[X,FVAL,EXITFLAG,OUTPUT] = fmincon(@myfun,z0,A,b,[],[],lb,ub,[],options);
Alan Weiss
MATLAB mathematical toolbox documentation

Alessandra Costa

### Alessandra Costa (view profile)

2019 年 2 月 6 日
Thank you for you answer. I'll follow you suggestions and I'll check my code.

サインイン to comment.

2019 年 2 月 6 日

### Matt J (view profile)

2019 年 2 月 6 日

Set
lb=[-Inf 0 0 -Inf];
ub=[];
A=[0 1 1 0];
b=1;

Alessandra Costa

### Alessandra Costa (view profile)

2019 年 2 月 6 日
I know I don't have equality constraints. I call the fmincon function with this command:
where gammamle(theta,x) is my function, defined through theta and x; theta is a 4*1 row vector of parameters and x is 4683*1 vector, referring to my variable of interest; then I specified theta0=[0.1,0.2,0.75,0.8] as initial points for the optimizations, ind1 is my variable of interest (ind1=x), and A, B, lb and ub are defined as you previously suggested. options refers only to the algorithm chosen. I don't know why I got this error
Matt J

### Matt J (view profile)

2019 年 2 月 6 日
You are creatively inventing your own syntax for fmincon, which of course has no hope of working. As you can see from the fmincon documentation, there is no 3rd input argument allowing you to input a "variable of interest", ind1.The 3rd and 4th arguments are meant to be your inequality data A,b.
Please clarify for us what a "variable of interest" means.
Alessandra Costa

### Alessandra Costa (view profile)

2019 年 2 月 6 日
No, I'm following a suggestion code from a microeconomic book, that suggests me to use this specification when I call the fmincon function. But thanks you for the answer

サインイン to comment.