yanera_mdmin_simplex.c

Go to the documentation of this file.
00001 /*============================================================================
00002 Copyright 2006 Thad Harroun, Kevin Yager
00003 
00004 This file is part of "yanera 2.0".
00005 
00006 "yanera 2.0" is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
00007 
00008 "yanera 2.0" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00009 
00010 You should have received a copy of the GNU General Public License along with "yanera 2.0"; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 
00011 =============================================================================*/
00018 #include "yanera.h"
00019 #include "yanera_mdmin_simplex.h"
00020 #include "yanera_mdmin.h"
00021 #include "yanera_util.h"
00022 /*============================================================================*/
00023 int yanera_mdmin_simplex_main(yanera_container *yanera)
00024 {
00025   int                         i, j, count;
00026   int                         status;
00027   gsl_vector                 *guess, *step_size;
00028   gsl_multimin_function       mdmin_func;
00029   gsl_multimin_fminimizer    *solvr;
00030   
00031   /* Inital guess is the paramters as they were passed into here */
00032   count = 0;
00033   for (i=0; i<yanera->parameters.n; i++) 
00034   {
00035     if (yanera->parameters.f[i] == NO)
00036     { count += 1; }
00037   }
00038   guess = gsl_vector_alloc(count);
00039   step_size = gsl_vector_alloc(count);
00040   for (i=0, j=0; i<yanera->parameters.n; i++) 
00041   {
00042     if (yanera->parameters.f[i] == NO)
00043     {
00044       gsl_vector_set(guess, j, yanera->parameters.p[i]);
00045       gsl_vector_set(step_size, j, yanera->parameters.p[i]/100.0);
00046       j++;
00047     }
00048   }
00049 
00050   mdmin_func.f      = &mdmin_simplex_f;
00051   mdmin_func.n      = count;
00052   mdmin_func.params = (void *)yanera;
00053   
00054   solvr = gsl_multimin_fminimizer_alloc( \
00055                   yanera->misc.fit_method_mdmin_simplex, count);
00056   
00057   /*==================================================*/
00058   count = 0;
00059   gsl_multimin_fminimizer_set(solvr, &mdmin_func, guess, step_size);
00060   yanera_report(yanera, count, solvr);
00061 
00062   do
00063   {
00064     count++;
00065     
00066     status = gsl_multimin_fminimizer_iterate(solvr);
00067     if (status != GSL_SUCCESS) 
00068     {
00069       fprintf(stderr,"STATUS: %s\n", gsl_strerror(status));
00070       break;
00071     }
00072     
00073     yanera_report(yanera, count, solvr);
00074     
00075     status = gsl_multimin_test_size(solvr->size, 1.0e-5);
00076     
00077     if (status == GSL_SUCCESS) 
00078     {
00079       fprintf(stderr,"STATUS: %s\n", gsl_strerror(status));
00080     }
00081     
00082   } while ((status == GSL_CONTINUE) && (count < yanera->misc.fit_iterations));
00083 
00084   yanera_report(yanera, -1, solvr);
00085 
00086   gsl_multimin_fminimizer_free(solvr);
00087   gsl_vector_free(guess);
00088   gsl_vector_free(step_size);
00089   return GSL_SUCCESS;
00090 }
00091 /*============================================================================*/
00092 double mdmin_simplex_f(const gsl_vector *parameters, \
00093                        void *yanera_pointer)
00094 {
00095   int     i, j;
00096   double  tmp;
00097   yanera_container  *yanera;
00098   /*
00099   ** r =>> residual
00100   */
00101   yanera = (yanera_container *)yanera_pointer;
00102   /*
00103   **  Load the params back into the parameter array.
00104   */
00105   for(i=0, j=0; i<yanera->parameters.n; i++)
00106   {
00107     if (yanera->parameters.f[i] == NO)
00108     {
00109       yanera->parameters.p[i] = gsl_vector_get(parameters, j);
00110       j++;
00111     }
00112   }
00113 
00114   tmp = mdmin_chisq(yanera);
00115   
00116   return tmp;
00117 }

Generated on Thu May 29 10:56:33 2008 by  doxygen 1.5.5