MATLAB Answers

How can I make sure I am using the right settings for the fmincon function?

1 view (last 30 days)
Sepideh Heydari
Sepideh Heydari on 21 Apr 2020
Answered: Alan Weiss on 23 Apr 2020
Hi there,
I have developed a model to replicate human behavior and in doing so, I have used several parameters. I set the parameter values manually so far, but now I want to optimize them to see what the best values are that would produce the closest output to human behavior. I am using fmincon to find the parameter value for each parameter (one parameter at a time), that minimizes my variable of interest. But I am not sure if I am using fmincon correctly. I have read the help examples a hundred times, but I just can't seem to understand the details of it. I don't understand what A, Aeq, b, beq, etc. are in my example. I don't understand if I should define a linear or nonlinear constraint. Every time I run the code, if I start the optimization with a different X0, I get drastically different optimized parameter value. And they are not even the best values all the time, because when I try the suggested optimized parameter value in the model, I see that the output of the model is not close to the behavioral data.
Could someone please help me with a more descriptive explanation of each element of the fmincon function, and what settings I should use to make sure I am doing this correctly?
right now this is my "main" script:
objective = @(x) function(x);
x0 = [0.8];
lb = [0];
ub = [2];
x = fmincon (objective,x0,[],[],[],[],lb,ub,[]);
this is my "constraint" function:
function [ c,ceq] = constraint( x )
c = x(1) - 0.99;
ceq =[];
end
and function (x) is the function where the actual modeling is happening. It calculates the difference between likelihood of choice in the behavioral experiment and the likelihood of choice in the model. My aim is to find parameters that minimize this difference in the likelihood of choice between model and human behavior. Here I am just passing one parameter to be optimized, but evetually (hopefully and ideally) I'd like to be able to optimize 3-4 parameters at once.
I'd really appreciate any help for this. Thanks!

  0 Comments

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 23 Apr 2020
You really should slow down to learn the tool that you are using a little bit better. Try working through the Getting Started nonlinear examples. You will see that you need to pass the nonlinear constraint function to fmincon in orther that it be used. Or maybe you will find the problem-based approach more natural.
Also, to do fitting of response, you most likely want to minimize the square of the difference between the observation and the prediction, or sum of squares of differences. Minimizing the difference usually leads the difference to a large negative value. See Nonlinear Least Squares.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

  0 Comments

Sign in to comment.


Translated by