minlbfgs_numdiff and the likelihood function [solved]

Hi all,

I would like to find the minimum of a likelihood function using minlbfgs_numdiff (numerical differentiation) in alglib. Clearly, my function depends on an array of data (vvv[]). I do not understand why it ends up in an infinite "nan" loop. Here is the driver I have created.
Have you got any suggestions, please?
Best,
A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void function1_func(const real_1d_array &x, double &func, void *ptr)
{
    
        int i;
   double a=0;
   double s = 0;
   double e=0;
   double err=0;
   for(i = 0; i<10; i++)
   {      
     e= vvv[i]-x[0];
     a= -0.5*log(2*PI)-0.5*(log(x[1])+(e*e)/x[1]);
     s=s+a;

   }
   func= (s);
    
}





edit: it was necessary to change func=s; to func=-s; and it works fine.
Last edited on
Topic archived. No new replies allowed.