[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] Simulated Annealing
From: |
Fred J. |
Subject: |
Re: [Help-gsl] Simulated Annealing |
Date: |
Tue, 31 Oct 2006 03:42:08 -0800 (PST) |
John Gehman <address@hidden> wrote: G'day Fred,
I don't have the documentation handy at the moment, so just some general
guidance ...
What you've done is a systematic search of all parameter space. And even
though you've declared double type, you appear to be considering only
integer values for x and y. Maybe that's good enough, but if you consider
real double number, you might get a better extremes.
Simulated Annealing will help you if your "energy surface" (i.e. the
surface defined by z values for give (x,y) is relatively discontinuous,
i.e. very very flat in most areas with narrow bands of steep descent, or
strafed with lots of local minima/maxima which make it difficult to find
the global minimum/maximum.
On the other hand if your surface is reasonably smooth, and if you have an
analytic expression for the derivative of your function with respect to
both x and y, (or even if not), you could look into nonlinear least
squares fitting routines with or without derivatives, (or use the
empirical derivative-finding routines). Alternatively you can use the
minimizer functions which iteratively bracket the minimum until a
satisfactory minimum is found.
Regards,
john
> Hi
>
> I have a routine
> double myRou ( double x, double y ) { ... };
>
> the way I use it is run it with many combinations of x,y and find which
> x,y combination gives the lowest or highest retrun. so I do
> vector res;
> for(double i = 1; i < 1000; ++i) {
> for( double j = 1; j < 1000; ++j) {
> res.push_back( myRou( i, j );
> }
> }
> then I go to find the maximum or minimum values in res.
> with out the loop which ends up taking the whole day.
>
> is there some algorithm that can help me find the global min/max.
> with out the looping, I was reading about gsl Simulated Annealing
> http://www.gnu.org/software/gsl/manual/html_node/Trivial-example.html#Trivial-example
> but realy could not understand how to apply it to my function. if someone
> could please show a code on how to use myRou.
>
> thanks
G'day John
thanks for you help.
I was able to compile and run the following samle code in in one dimensional
cartesian space, but I am woundering how can I use it to work on 2-dim
configuratrion.
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_siman.h>
/* set up parameters for this simulated annealing run */
/* how many points do we try before stepping */
#define N_TRIES 200
/* how many iterations for each T? */
#define ITERS_FIXED_T 10
/* max step size in random walk */
#define STEP_SIZE 10
/* Boltzmann constant */
#define K 1.0
/* initial temperature */
#define T_INITIAL 0.002
/* damping factor for temperature */
#define MU_T 1.005
#define T_MIN 2.0e-6
gsl_siman_params_t params
= {N_TRIES, ITERS_FIXED_T, STEP_SIZE,
K, T_INITIAL, MU_T, T_MIN};
/* now some functions to test in one dimension */
double E1(void *xp)
{
double x = * ((double *) xp);
return exp(-pow((x-1.0),2.0))*sin(8*x);
}
double M1(void *xp, void *yp)
{
double x = *((double *) xp);
double y = *((double *) yp);
return fabs(x - y);
}
void S1(const gsl_rng * r, void *xp, double step_size)
{
double old_x = *((double *) xp);
double new_x;
double u = gsl_rng_uniform(r);
new_x = u * 2 * step_size - step_size + old_x;
memcpy(xp, &new_x, sizeof(new_x));
}
void P1(void *xp)
{
printf ("%12g", *((double *) xp));
}
int
main(int argc, char *argv[])
{
const gsl_rng_type * T;
gsl_rng * r;
double x_initial = 15.5;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc(T);
gsl_siman_solve(r, // const gsl_rng *, for steps generation
&x_initial, // void *, points to starting configuration and best
results once finished
E1, // gsl_siman_Efunc_t, specifies the space to search
S1, // gsl_siman_step_t, for steps generation
M1,
P1, // gsl_siman_print_t, if NULL (no print out), else stdout
NULL, // gsl_siman_copy_t, copyfunc,
NULL, // gsl_siman_copy_construct_t, copy_constructor
NULL, // gsl_siman_destroy_t, destructor
sizeof(double), // size_t, fixed size "updating configuration mode",
zero in the variable-size mode
params // gsl_siman_params_t,
);
return 0;
}
---------------------------------
Check out the New Yahoo! Mail - Fire up a more powerful email and get things
done faster.