how to optimize maximum like-hood function?
Mostrar comentarios más antiguos
I try to use maximum like-hood approach to calculate some parameters. But I do not know the specific expression of the posibility density function. I write code like this:
i = 2:1000;
p0 = [1, 1, 1];
[x, fval] = fminunc(@(x)(-sum(log(pdf(data(i), t(i), data(i-1), t(i-1), x(1), x(2), x(3))))), p0);
( the function pdf can return a posibility density function when you give a set of input, data(i), t(i), data(i-1), t(i-1), x(1), x(2), x(3). )
And I think I should sum all the natural logarithm of posibility density function and put the result in to an optimizer, so I write these codes. But it can not run well. There is an error says Failure in initial objective function evaluation. FMINUNC cannot continue. However, if I give i a specific number, such as 2 or 3, it can work. But in this way, I can't use other data. I have 1000 thousand pairs of data(i) and t(i).
6 comentarios
Torsten
el 16 de Nov. de 2018
Before calling fminunc, call your objective function as
z = -sum(log(pdf(data(i),data(i-1),t(i-1),p0(1),p0(2),p0(3))))
and see whether z is a proper value.
Zonghao
el 16 de Nov. de 2018
Zonghao
el 16 de Nov. de 2018
Write a function
function obj = fun(p,t,data)
...
end
include your loop within this function and return the result -sum(log(.... in the variable "obj".
The call to "fminunc" will be
[p, fval] = fminunc(@(p)fun(p,t,data),p0)
Best wishes
Torsten.
Zonghao
el 16 de Nov. de 2018
Respuestas (0)
Categorías
Más información sobre Choose a Solver en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!