Logo ROOT   6.13/01
Reference Guide
GSLMultiMinFunctionAdapter.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, 12/2006
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Header file for class GSLMultiMinFunctionAdapter
26 //
27 // Generic adapter for gsl_multimin_function signature
28 // usable for any c++ class which defines operator( )
29 //
30 // Created by: Lorenzo Moneta at Fri Nov 12 16:58:51 2004
31 //
32 // Last update: Fri Nov 12 16:58:51 2004
33 //
34 #ifndef ROOT_Math_GSLMultiMinFunctionAdapter
35 #define ROOT_Math_GSLMultiMinFunctionAdapter
36 
37 #include "gsl/gsl_vector.h"
38 
39 namespace ROOT {
40 namespace Math {
41 
42 
43 
44 
45  /**
46  Class for adapting any multi-dimension C++ functor class to C function pointers used by
47  GSL MultiMin algorithms.
48  The templated C++ function class must implement:
49 
50  <em> double operator( const double * x)</em>
51  and if the derivatives are required:
52  <em> void Gradient( const double * x, double * g)</em>
53 
54  This class defines static methods with will be used to fill the
55  \a gsl_multimin_function and
56  \a gsl_multimin_function_fdf structs used by GSL.
57  See for examples the
58  <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Providing-a-function-to-minimize.html#Providing-a-function-to-minimize">GSL online manual</A>
59 
60  @ingroup MultiMin
61 
62  */
63 
64 
65  template<class UserFunc>
67 
68  static double F( const gsl_vector * x, void * p) {
69 
70  UserFunc * function = reinterpret_cast< UserFunc *> (p);
71  // get pointer to data from gsl_vector
72  return (*function)( x->data );
73  }
74 
75 
76  static void Df( const gsl_vector * x, void * p, gsl_vector * g) {
77 
78  UserFunc * function = reinterpret_cast< UserFunc *> (p);
79  (*function).Gradient( x->data, g->data );
80 
81  }
82 
83  static void Fdf( const gsl_vector * x, void * p, double *f, gsl_vector * g ) {
84 
85  UserFunc * function = reinterpret_cast< UserFunc *> (p);
86 // *f = (*function) ( x );
87 // *df = (*function).Gradient( x );
88 
89  (*function).FdF( x->data, *f, g->data);
90  }
91 
92  };
93 
94 
95 } // namespace Math
96 } // namespace ROOT
97 
98 
99 #endif /* ROOT_Math_GSLMultiMinFunctionAdapter */
static double F(const gsl_vector *x, void *p)
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
static void Fdf(const gsl_vector *x, void *p, double *f, gsl_vector *g)
* x
Deprecated and error prone model selection interface.
Definition: TRolke.cxx:630
Namespace for new Math classes and functions.
Class for adapting any multi-dimension C++ functor class to C function pointers used by GSL MultiMin ...
static void Df(const gsl_vector *x, void *p, gsl_vector *g)