00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_GSL_MISER_H
00024 #define O2SCL_GSL_MISER_H
00025
00026 #include <iostream>
00027 #include <o2scl/collection.h>
00028 #include <o2scl/mcarlo_inte.h>
00029 #include <o2scl/gsl_rnga.h>
00030 #include <gsl/gsl_monte.h>
00031 #include <gsl/gsl_monte_miser.h>
00032
00033 #ifndef DOXYGENP
00034 namespace o2scl {
00035 #endif
00036
00037
00038
00039
00040
00041 template<class param_t, class func_t, class rng_t=gsl_rnga,
00042 class vec_t=ovector_view> class gsl_miser :
00043 public mcarlo_inte<param_t,func_t,rng_t,vec_t> {
00044
00045 public:
00046
00047 virtual ~gsl_miser() {}
00048
00049
00050 virtual int minteg_err(func_t &func, size_t ndim,
00051 const vec_t &a, const vec_t &b, param_t &pa,
00052 double &res, double &err)
00053 {
00054 gm_parms gmp={&func,(void *)&pa};
00055 gsl_monte_function gfunc={gsl_func,ndim,&gmp};
00056
00057 int ncalls=this->n_points;
00058
00059 double *aa=new double[ndim], *bb=new double[ndim];
00060 for(size_t i=0;i<ndim;i++) {
00061 aa[i]=a[i];
00062 bb[i]=b[i];
00063 }
00064
00065 gsl_monte_miser_state *s=gsl_monte_miser_alloc(ndim);
00066 gsl_monte_miser_integrate(&gfunc,aa,bb,ndim,ncalls,
00067 this->def_rng.get_gsl_rng(),s,&res,&err);
00068 gsl_monte_miser_free(s);
00069
00070 delete[] aa;
00071 delete[] bb;
00072
00073 return 0;
00074
00075 }
00076
00077
00078 virtual const char *type() { return "gsl_miser"; }
00079
00080 protected:
00081
00082 #ifndef DOXYGEN_INTERNAL
00083
00084
00085 static double gsl_func(double *x, size_t dim, void *pa) {
00086 gm_parms *gp=(gm_parms *)pa;
00087 ovector_array aa(dim,x);
00088 return (*gp->func)(dim,aa,*((param_t *)(gp->vp)));
00089 }
00090
00091
00092 typedef struct gm_parms_s {
00093 func_t *func;
00094 void *vp;
00095 } gm_parms;
00096
00097 #endif
00098
00099 };
00100
00101 #ifndef DOXYGENP
00102 }
00103 #endif
00104
00105 #endif
00106