X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=minimise.c;fp=minimise.c;h=d7cc86dcd1571fa4e9c375dbc2f47f0eb0d29ee0;hb=bc3b5b8813e120b28b3148d8c7412fa9937f6cb1;hp=0000000000000000000000000000000000000000;hpb=e6ff377c3c846274fa3d7d98e83512d5e4226f56;p=moebius2.git diff --git a/minimise.c b/minimise.c new file mode 100644 index 0000000..d7cc86d --- /dev/null +++ b/minimise.c @@ -0,0 +1,175 @@ +/* + * use of GSL + */ + + /* We want to do multidimensional minimisation. + * + * We don't think there are any local minima. Or at least, if there + * are, the local minimum which will be found from the starting + * state is the one we want. + * + * We don't want to try to provide a derivative of the cost + * function. That's too tedious (and anyway the polynomial + * approximation to our our cost function sometimes has high degree + * in the inputs which means the quadratic model implied by most of + * the gradient descent minimisers is not ideal). + * + * This eliminates most of the algorithms. Nelder and Mead's + * simplex algorithm is still available and we will try that. + * + * In our application we are searching for the optimal locations of + * N actualvertices in D3 (3) dimensions - ie, we are searching for + * the optimal metapoint in an N*D3-dimensional space. + * + * So eg with X=Y=100, the simplex will contain 300 metavertices + * each of which is an array of 300 doubles for the actualvertex + * coordinates. Hopefully this won't be too slow ... + */ + +#include "common.h" + +#include +#include + +#include +#include + +#include "half.h" +#include "minimise.h" + +const char *input_file, *output_file; +char *output_file_tmp; + +static void printing_init(void); + +static gsl_multimin_fminimizer *minimiser; + +static const double stop_epsilon= 1e-6; + +static double minfunc_f(const gsl_vector *x, void *params) { + struct Vertices vs; + + assert(x->size == DIM); + assert(x->stride == 1); + map_dimensions(x->data, vs.a); + return compute_energy(&vs); +} + +int main(int argc, const char *const *argv) { + gsl_multimin_function multimin_function; + double size; + struct Vertices initial_full; + double initial_half[DIM], step_size[DIM]; + FILE *initial_f; + gsl_vector initial_gsl, step_size_gsl; + int r, i; + + if (argc!=3 || argv[1][0]=='-' || strncmp(argv[2],"-o",2)) + { fputs("usage: minimise -o