How to use fmincon as fminbd with two different variables
Afficher commentaires plus anciens
Hi there,
While trying to test different RL models, I've come to a concern, we define the model through a function "loglik" where I define the different input vectors and values through an iteration of different subjects (i) and I use fminbnd to search for the min value, being 0 and 1 the min and max limits. U and UU simply relates to two different vectors of data from two different agents.
hh = @(alpha)loglik_modelA(alpha,U,UU);
aa(i) = fminbnd(hh,0,1);
LL(i)=loglik_modelA(aa(i),U,UU);
This simply works perfectly fine, but the problem is when our model has more parameters, let's say for instance two alphas. I know fminbnd is thought for a single variable function, and I understand fmincon is the function that would help me with multiple variables. I've tried this piece of code based on the previous one, but it does not seem to work as I understand the logic behind fmincon might be slightly different.
hh = @(alpha1,alpha2)loglik_modelB(alpha1,alpha2,U,UU);
aa(i) = fmincon(hh,alpha1,alpha2,0,1); %I would expect aa(i) to be a 2D matrix
LL(i)=loglik_modelB(aa(i,1),aa(i,2),U,UU);
As usual, alphas are parameters associated to different prediction errors, and range from 0 to 1.
Any insight would be highly appreciated!
4 commentaires
John D'Errico
le 8 Juil 2021
I would start by reading the help for fmincon, no? In there, you will find examples of use.
Unai Vicente
le 8 Juil 2021
Modifié(e) : Unai Vicente
le 9 Juil 2021
Matt J
le 9 Juil 2021
with my level I don't see any example that is similar to what I am looking for
How are they dissimilar? Your question is about how to process a problem with two unknowns instead of one. Every single example in the fmincon documentation is a problem with 2 unknowns.
Unai Vicente
le 9 Juil 2021
Réponse acceptée
Plus de réponses (1)
Kapil Gupta
le 9 Juil 2021
0 votes
I assume you want to use multiple inputs for fminbnd. The following links have similar queries, you can check these out:
1 commentaire
Unai Vicente
le 9 Juil 2021
Modifié(e) : Unai Vicente
le 9 Juil 2021
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!