Reputation:
I have a function that gives me a likelihood which I want to maximize. The problem is that I need to give 4 parameters that I need to estimate. I have this function:
[likelihood, z0, z1, z2, z3]= myfun(g, g1, g2, x1, g3, x2, x3)
that in output gives likelihood how can I maximize it? I know all the g
but I do not know the x
and I should estimate them with maximization of the likelihood. Moreover I do not know the z
as well.
I guess I should do fminsearch but I could not find documentation with parameter estimation like this.
Upvotes: 1
Views: 255
Reputation: 1880
fminsearch
seems like it would do just fine here - you just have to make inputs that abstract the search problem in the way that function expects. Here I think this means creating a function that:
Assuming that 0
is a sensible initial value for all x
parameters, this would look something like this:
x = fminsearch(@(x) -myfun(g, g1, g2, x(1), g3, x(2), x(3)), [0,0,0]);
x1 = x(1);
x2 = x(2);
x3 = x(3);
To find out the z
values and resulting likelihood
from the search result returned, you can then simply put the result back into myfun
:
[likelihood, z0, z1, z2, z3] = myfun(g, g1, g2, x1, g3, x2, x3)
Upvotes: 1