[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] conjugate gradient problem
From: |
James Bergstra |
Subject: |
Re: [Help-gsl] conjugate gradient problem |
Date: |
Sun, 29 Jan 2006 03:14:32 -0500 |
User-agent: |
Mutt/1.4.2.1i |
> this 'temp1' returned is supposed to be printed by s->f in main(). 's' is
> actually passed to 'gsl_multimin_fdfminimizer_iterate (s)'; in each iteration
> But a different value is printed in main. To be precise its printing the
> value of arr[0]* arr[1] & NOT arr[0]*arr[1]+ temp3.
>
> Now temp3 uses term[i] array, which is calculated like exp(-20*linear
> constraint1) + exp(-20*linearconstraint2) + ..... +
> exp(-20*linearconstraintN). in another function.
I have three ideas, of which perhaps none will be useful...
1.
You are adding exp(-LARGENUMBER*??) several times, which might be very small
compared with arr[0]*arr[1] and cause a rounding error.
2.
You are mis-understanding the role of s->f in main(). This variable stores
the current lowest value found in the codomain. In the later stages of
minimization,
not every call to your function will reveal a new lowest point.
3.
You are forgetting my_fdf(). Perhaps your printf statements are duplicated in
my_fdf, but you are accidentally returning the wrong value in my_fdf ?
> Now my another 2 problems are:
> 2> for this constrained case the output never prints the 'Minima Found'.
That's normal. Iterative minimization routines do not reliably converge in a
reasonnable time. You can try other minimization routines too... each of them
works well sometimes.
> 3> After some 10 iterations the function value & variable values does not
> change any more with iterations. & at the same time for each iteration it
> enters into my_f(ie, the function where the function 'xy' is calculated).
> Initially for each iteration it enters my_f only once (as is expected)
> but as th function & variable values stops changing it enters the my_f
> function succesively more no. of times for each iteration. ... why should it
> be like that ??
Good question. I have almost no idea, but you could look at the references in
the manual, or even just google for conjugate-gradient. The issue is
theoretical, and it's related to the algorithm. It is not a bug in the library.
Good luck.
--
james bergstra
http://www-etud.iro.umontreal.ca/~bergstrj
On Sun, Jan 29, 2006 at 12:39:18AM +0530, Debashree.Sen wrote:
>
> hi,
> i am using GSL for doing multidimensional minimization of a non-linear
> functions of dimensions ( max 20-30). I was trying to minimize a quadratic
> function by employing exponential barrier method on it ( for non-linear
> programming problem of operation research).
> The function to be minimised is 'xy'. this is how i have defined my function:
>
> /*This is the multidimensional quadratic function being minimised*/
>
> double my_f (const gsl_vector *v, void *params)
> {
> printf("\ninside my_f\n");
> double *dp = (double *)params;
>
> /*Variable declarations*/
> double temp = 0;
> double temp0 = 0, temp2 = 0;
> double temp1 = 0, temp3 = 0;
> int i=0, j=0, k;
>
> /*Initialising the multi-dim array*/
> for(;i<ndim;i++)
> arr[i] = gsl_vector_get(v, i);
> for(i=0;i<num;i++)
> temp3+=exp(-LARGENUMBER*term[i]); // Largenumber can be
> anything say 10-20--here
> this is the
> exponential barrier
>
> printf("temp= %lf",temp3);
>
> temp1 = arr[0]*arr[1]+temp3; // a function of the
> type , say , x*y
> printf("func value: %lf", temp1); -------------> at this stage
> value calculated is correct
>
> return temp1; //The final function value
>
> }
>
>