[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Multidimensional minimization problem
From: |
Mikko Olkkonen |
Subject: |
[Help-gsl] Multidimensional minimization problem |
Date: |
Tue, 18 Sep 2012 11:23:12 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0 |
Hello,
I am running multidimensional minimization along the lines of the
examples in chapter 36.9 of the manual. gsl_multimin_fminimizers seem to
converge to the correct answers when dimension of the problem is low.
e.g. setting VECLEN=10 (see code below) delivers:
>converged to minimum at
> 6606 f() = 0.000 size = 0.000
However when I raise dimension e.g. to 18 the algorithms seem to get
stuck into clearly wrong answer
>999999 f() = 237.603 size = 0.000
The mathematician inside me tells me that since the function has no
local minimums this function should be pretty straightforward to
minimize more or less regardless of the dimension of the problem and
regardless of the initial guess and stepsize and everything.
Thanks for any input how to minimize this kind of simple but highly
multidimensional function?
Mikko
I am compiling with
>gcc -c -g new.c
>gcc -L/usr/local/lib new.o -lgsl -lgslcblas -lm
and uname -a gives "Linux auriga 3.2.0-30-generic #48-Ubuntu SMP Fri Aug
24 16:54:40 UTC 2012 i686 i686 i386 GNU/Linux"
all of my code follows:
#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_multimin.h>
#define VECLEN 10 // <= works ok but higher value e.g. 18 does not
work anymore
#define MAXITER 999999
#define STEPSIZE 1e-2
#define TOLERANCE 1e-9
double my_f (const gsl_vector *v, void *params)
{
int *p = (int *)params;
int kk;
double sum,addi;
sum=0.0;
for (kk=0;kk<VECLEN;kk++) {
addi=gsl_vector_get(v,kk);
sum=sum+(addi-(double)kk)*(addi-(double)kk);
// printf("%5d %8.1f %12.4f %12.4f %12.4f
%12.5f\n",kk,(double)kk,addi,(addi-(double)kk),(addi-(double)kk)*(addi-(double)kk),sum);
}
return(sum);
}
int main(void)
{
double par[5];
const gsl_multimin_fminimizer_type *T =
gsl_multimin_fminimizer_nmsimplex;
gsl_multimin_fminimizer *s = NULL;
gsl_vector *ss, *x;
gsl_multimin_function minex_func;
size_t iter = 0;
int status;
double size;
/* Starting point */
x = gsl_vector_alloc (VECLEN);
gsl_vector_set_all (x, 5.0);
/* Set initial step sizes to 1 */
ss = gsl_vector_alloc (VECLEN);
gsl_vector_set_all (ss, STEPSIZE);
/* Initialize method and iterate */
minex_func.n = VECLEN;
minex_func.f = my_f;
minex_func.params = par;
s = gsl_multimin_fminimizer_alloc (T, VECLEN);
gsl_multimin_fminimizer_set (s, &minex_func, x, ss);
do
{
iter++;
status = gsl_multimin_fminimizer_iterate(s);
if (status) break;
size = gsl_multimin_fminimizer_size (s);
status = gsl_multimin_test_size (size, TOLERANCE);
if (status == GSL_SUCCESS) printf ("converged to minimum at\n");
printf ("%5d f() = %7.3f size = %.3f\n", iter, s->fval, size);
}
while (status == GSL_CONTINUE && iter < MAXITER);
gsl_vector_free(x);
gsl_vector_free(ss);
gsl_multimin_fminimizer_free (s);
return status;
}
- [Help-gsl] Multidimensional minimization problem,
Mikko Olkkonen <=