All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mcarlo_miser.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl 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
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /* monte/miser.c
24  *
25  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Michael Booth
26  *
27  * This program is free software; you can redistribute it and/or modify
28  * it under the terms of the GNU General Public License as published by
29  * the Free Software Foundation; either version 3 of the License, or (at
30  * your option) any later version.
31  *
32  * This program is distributed in the hope that it will be useful, but
33  * WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35  * General Public License for more details.
36  *
37  * You should have received a copy of the GNU General Public License
38  * along with this program; if not, write to the Free Software
39  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40  * 02110-1301, USA.
41  */
42 #ifndef O2SCL_MCARLO_MISER_H
43 #define O2SCL_MCARLO_MISER_H
44 
45 /** \file mcarlo_miser.h
46  \brief File defining \ref o2scl::mcarlo_miser
47 */
48 #include <iostream>
49 
50 #include <boost/numeric/ublas/vector.hpp>
51 
52 #include <o2scl/misc.h>
53 #include <o2scl/mcarlo.h>
54 
55 #include <gsl/gsl_math.h>
56 #include <gsl/gsl_monte.h>
57 #include <gsl/gsl_machine.h>
58 #include <gsl/gsl_monte_miser.h>
59 
60 #ifndef DOXYGEN_NO_O2NS
61 namespace o2scl {
62 #endif
63 
64  /** \brief Multidimensional integration using the MISER Monte Carlo
65  algorithm (GSL)
66 
67  This class uses recursive stratified sampling to estimate the
68  value of an integral over a hypercubic region.
69 
70  By default the minimum number of calls to estimate the variance
71  is 16 times the number of dimensions. This ratio is
72  stored in \ref calls_per_dim. By default the minimum number of
73  calls per bisection is 32 times \ref calls_per_dim times
74  the number of dimensions. This ratio is stored in
75  \ref bisection_ratio. These ratios are employed by
76  \ref minteg_err().
77 
78  Alternatively, the user can directly set these minimums by \ref
79  set_min_calls() and \ref set_min_calls_per_bisection() and use
80  \ref miser_minteg_err() which ignores \ref calls_per_dim and
81  \ref bisection_ratio.
82 
83  If \ref mcarlo::verbose is greater than zero, then the
84  status of the integration is output at every level of bisection
85  less than \ref n_levels_out. If it is greater than 1, then the
86  boundaries of the current region are also output. Finally, if it
87  is greater than 2, a keypress is required after each output.
88 
89  Based on \ref Press90 .
90  */
91  template<class func_t=multi_funct11,
93  class rng_t=int, class rng_dist_t=rng_gsl>
94  //class rng_t=std::mt19937,
95  //class rng_dist_t=std::uniform_real_distribution<double> >
96  class mcarlo_miser : public mcarlo<func_t,vec_t,rng_t,rng_dist_t> {
97 
98  public:
99 
102 
103  /** \brief Number of calls per dimension (default 16)
104  */
106 
107  /** \brief Factor to set \ref min_calls_per_bisection (default 32)
108  */
110 
111  /** \brief Introduce random variation into bisection (default 0.0)
112 
113  From GSL documentation:
114  \verbatim
115  This parameter introduces a random fractional variation of size
116  DITHER into each bisection, which can be used to break the
117  symmetry of integrands which are concentrated near the exact
118  center of the hypercubic integration region. The default value of
119  dither is zero, so no variation is introduced. If needed, a
120  typical value of DITHER is 0.1.
121  \endverbatim
122  */
123  double dither;
124 
125  /** \brief Specify fraction of function calls for estimating variance
126  (default 0.1)
127 
128  From GSL documentation:
129  \verbatim
130  This parameter specifies the fraction of the currently available
131  number of function calls which are allocated to estimating the
132  variance at each recursive step. The default value is 0.1.
133  \endverbatim
134  */
136 
137  /** \brief How estimated variances for two sub-regions are combined
138  (default 2.0)
139 
140  The error handler will be called if this is less than zero.
141 
142  From GSL documentation:
143  \verbatim
144  This parameter controls how the estimated variances for the two
145  sub-regions of a bisection are combined when allocating points.
146  With recursive sampling the overall variance should scale better
147  than 1/N, since the values from the sub-regions will be obtained
148  using a procedure which explicitly minimizes their variance. To
149  accommodate this behavior the MISER algorithm allows the total
150  variance to depend on a scaling parameter \alpha,
151 
152  \Var(f) = {\sigma_a \over N_a^\alpha} + {\sigma_b \over N_b^\alpha}.
153 
154  The authors of the original paper describing MISER recommend the
155  value \alpha = 2 as a good choice, obtained from numerical
156  experiments, and this is used as the default value in this
157  implementation.
158  \endverbatim
159  */
160  double alpha;
161 
162  /** \brief Minimum number of calls to estimate the variance
163 
164  This is set by minteg() and minteg_err() to be \ref
165  calls_per_dim times the number of dimensions in the problem. The
166  default value of calls_per_dim is 16 (which is the GSL default).
167 
168  From GSL documentation:
169  \verbatim
170  This parameter specifies the minimum number of function calls
171  required for each estimate of the variance. If the number of
172  function calls allocated to the estimate using ESTIMATE_FRAC falls
173  below MIN_CALLS then MIN_CALLS are used instead. This ensures
174  that each estimate maintains a reasonable level of accuracy.
175  \endverbatim
176  */
177  int set_min_calls(size_t &mc) {
178  min_calls=mc;
179  return 0;
180  }
181 
182  /** \brief Minimum number of calls required to proceed with bisection
183 
184  This is set by minteg() and minteg_err() to be \ref
185  calls_per_dim times \ref bisection_ratio times the number of
186  dimensions in the problem. The default values give 512 times the
187  number of dimensions (also the GSL default).
188 
189  From GSL documentation:
190  \verbatim
191  This parameter specifies the minimum number of function calls
192  required to proceed with a bisection step. When a recursive step
193  has fewer calls available than MIN_CALLS_PER_BISECTION it performs
194  a plain Monte Carlo estimate of the current sub-region and
195  terminates its branch of the recursion.
196  \endverbatim
197  */
198  int set_min_calls_per_bisection(size_t &mcb) {
200  return 0;
201  }
202 
203  /** \brief The number of recursive levels to output when verbose is
204  greater than zero (default 5)
205  */
206  size_t n_levels_out;
207 
208 #ifndef DOXYGEN_INTERNAL
209 
210  protected:
211 
212  /// Minimum number of calls to estimate the variance
213  size_t min_calls;
214 
215  /// Minimum number of calls required to proceed with bisection
217 
218  /// The number of dimensions of memory allocated
219  size_t dim;
220 
221  /// \name Arrays which contain a value for each dimension
222  //@{
223  /// The current midpoint
225  /// The left variance
227  /// The right variance
229  /// The maximum function value in the left half
231  /// The maximum function value in the right half
233  /// The minimum function value in the left half
235  /// The minimum function value in the right half
237  /// The sum in the left half
239  /// The sum in the right half
241  /// The sum of the squares in the left half
243  /// The sum of the squares in the right half
245  /// The number of evaluation points in the left half
247  /// The number of evaluation points in the right half
249  //@}
250 
251  /** \brief Estimate the variance
252 
253  \future Remove the reference to GSL_POSINF and replace with a
254  function parameter.
255  */
256  virtual int estimate_corrmc(func_t &func, size_t ndim,
257  const vec_t &xl, const vec_t &xu,
258  size_t calls, double &res,
259  double &err, const ubvector &lxmid,
260  ubvector &lsigma_l, ubvector &lsigma_r) {
261  size_t i, n;
262 
263  double m=0.0, q=0.0;
264  double vol=1.0;
265 
266  for (i=0;i<dim;i++) {
267  vol*=xu[i]-xl[i];
268  hits_l[i]=hits_r[i]=0;
269  fsum_l[i]=fsum_r[i]=0.0;
270  fsum2_l[i]=fsum2_r[i]=0.0;
271  lsigma_l[i]=lsigma_r[i]=-1;
272  }
273 
274  for (n=0;n<calls;n++) {
275  double fval;
276 
277  unsigned int j=(n/2) % dim;
278  unsigned int side=(n % 2);
279 
280  for (i=0;i<dim;i++) {
281 
282  // The equivalent of gsl_rng_uniform_pos()
283  double z;
284  do {
285  z=this->rng_dist(this->rng);
286  } while (z==0);
287 
288  if (i != j) {
289  x[i]=xl[i]+z*(xu[i]-xl[i]);
290  } else {
291  if (side == 0) {
292  x[i]=lxmid[i]+z*(xu[i]-lxmid[i]);
293  } else {
294  x[i]=xl[i]+z*(lxmid[i]-xl[i]);
295  }
296  }
297  }
298 
299  fval=func(ndim,x);
300 
301  /* recurrence for mean and variance */
302  {
303  double d=fval-m;
304  m+=d/(n+1.0);
305  q+=d*d*(n/(n+1.0));
306  }
307 
308  /* compute the variances on each side of the bisection */
309  for (i=0;i<dim;i++) {
310  if (x[i] <= lxmid[i]) {
311  fsum_l[i]+=fval;
312  fsum2_l[i]+=fval*fval;
313  hits_l[i]++;
314  } else {
315  fsum_r[i]+=fval;
316  fsum2_r[i]+=fval*fval;
317  hits_r[i]++;
318  }
319  }
320  }
321 
322  for (i=0;i<dim;i++) {
323  double fraction_l=(lxmid[i]-xl[i])/(xu[i]-xl[i]);
324 
325  if (hits_l[i] > 0) {
326  fsum_l[i] /= hits_l[i];
327  lsigma_l[i]=sqrt(fsum2_l[i]-fsum_l[i]*fsum_l[i]/hits_l[i]);
328  lsigma_l[i]*=fraction_l*vol/hits_l[i];
329  }
330 
331  if (hits_r[i] > 0) {
332  fsum_r[i] /= hits_r[i];
333  lsigma_r[i]=sqrt(fsum2_r[i]-fsum_r[i]*fsum_r[i]/hits_r[i]);
334  lsigma_r[i]*=(1-fraction_l)*vol/hits_r[i];
335  }
336  }
337 
338  res=vol*m;
339 
340  if (calls<2) {
341  err=GSL_POSINF;
342  } else {
343  err=vol*sqrt(q/(calls*(calls-1.0)));
344  }
345 
346  return success;
347  }
348 
349  /// The most recent integration point
350  vec_t x;
351 
352 #endif
353 
354  public:
355 
356  mcarlo_miser() {
357  estimate_frac=0.1;
358  alpha=2.0;
359  dither=0.0;
360  min_calls=100;
362  dim=0;
363  n_levels_out=5;
364  calls_per_dim=16;
365  bisection_ratio=32;
366  }
367 
368  virtual ~mcarlo_miser() {
369  }
370 
371  /// Allocate memory
372  virtual int allocate(size_t ldim) {
373 
374  if (ldim==0) {
375  O2SCL_ERR2("Can't allocate zero memory in ",
376  "mcarlo_miser::allocate().",exc_efailed);
377  }
378 
379  if (ldim!=dim) {
380  x.resize(ldim);
381  xmid.resize(ldim);
382  sigma_l.resize(ldim);
383  sigma_r.resize(ldim);
384  fmax_l.resize(ldim);
385  fmax_r.resize(ldim);
386  fmin_l.resize(ldim);
387  fmin_r.resize(ldim);
388  fsum_l.resize(ldim);
389  fsum_r.resize(ldim);
390  fsum2_l.resize(ldim);
391  fsum2_r.resize(ldim);
392  hits_l.resize(ldim);
393  hits_r.resize(ldim);
394  }
395 
396  dim=ldim;
397 
398  return 0;
399  }
400 
401  /** \brief Integrate function \c func over the hypercube from
402  \f$ x_i=\mathrm{xl}_i \f$ to \f$ x_i=\mathrm{xu}_i \f$ for
403  \f$ 0<i< \f$ ndim-1
404 
405  \note The values of \ref min_calls and \ref
406  min_calls_per_bisection should be set before calling this
407  function. The default values if not set are 100 and 3000
408  respectively, which correspond to the GSL default setting
409  for a 6 dimensional problem.
410  */
411  virtual int miser_minteg_err(func_t &func, size_t ndim, const vec_t &xl,
412  const vec_t &xu, size_t calls, size_t level,
413  double &res, double &err) {
414 
415  if (min_calls==0 || min_calls_per_bisection==0) {
416  O2SCL_ERR2("Variables min_calls or min_calls_per_bisection ",
417  "are zero in mcarlo_miser::miser_minteg_err().",
418  exc_einval);
419  }
420 
421  size_t n, estimate_calls, calls_l, calls_r;
422  size_t i;
423  size_t i_bisect;
424  int found_best;
425 
426  double res_est=0, err_est=0;
427  double res_r=0, err_r=0, res_l=0, err_l=0;
428  double xbi_l, xbi_m, xbi_r, s;
429 
430  double vol;
431  double weight_l, weight_r;
432 
433  for (i=0;i<dim;i++) {
434  if (xu[i] <= xl[i]) {
435  std::string str="Upper limit, "+dtos(xu[i])+", must be greater "+
436  "than lower limit, "+dtos(xl[i])+", in mcarlo_miser::"+
437  "miser_minteg_err().";
438  O2SCL_ERR(str.c_str(),exc_einval);
439  }
440  if (xu[i]-xl[i]>GSL_DBL_MAX) {
441  O2SCL_ERR2("Range of integration is too large ",
442  "in mcarlo_miser::miser_minteg_err().",exc_einval);
443  }
444  }
445 
446  if (alpha<0) {
447  std::string str="Parameter alpha, "+dtos(alpha)+", must be non-"+
448  "negative in mcarlo_miser::mister_minteg_err().";
449  O2SCL_ERR(str.c_str(),exc_einval);
450  }
451 
452  /* [GSL] Compute volume */
453 
454  vol=1;
455 
456  for (i=0;i<dim;i++) {
457  vol*=xu[i]-xl[i];
458  }
459 
460  if (calls<min_calls_per_bisection) {
461  double m=0.0, q=0.0;
462 
463  if (calls<2) {
464  O2SCL_ERR2("Insufficient calls for subvolume ",
465  "in mcarlo_miser::miser_minteg_err().",exc_einval);
466  }
467 
468  for (n=0;n<calls;n++) {
469  /* Choose a random point in the integration region */
470 
471  for (i=0;i<dim;i++) {
472 
473  // The equivalent of gsl_rng_uniform_pos()
474  double rdn;
475  do {
476  rdn=this->rng_dist(this->rng);
477  } while (rdn==0);
478 
479  x[i]=xl[i]+rdn*(xu[i]-xl[i]);
480  }
481 
482  {
483  double fval;
484  fval=func(ndim,x);
485 
486  /* [GSL] recurrence for mean and variance */
487 
488  double d=fval-m;
489  m+=d/(n+1.0);
490  q+=d*d*(n/(n+1.0));
491  }
492  }
493 
494  res=vol*m;
495 
496  err=vol*sqrt(q/(calls*(calls-1.0)));
497 
498  return success;
499  }
500 
501  // The equivalent of what's in GSL but rewritten with explicit
502  // typecasts
503  size_t prod=(size_t)(((double)calls)*estimate_frac);
504  estimate_calls=(min_calls > prod ? min_calls : prod);
505 
506  if (estimate_calls<4*dim) {
507  O2SCL_ERR2("Insufficient calls to sample all halfspaces ",
508  "in mcarlo_miser::miser_minteg_err().",exc_esanity);
509  }
510 
511  // [GSL] Flip coins to bisect the integration region with some fuzz
512 
513  for (i=0;i<dim;i++) {
514  s=(this->rng_dist(this->rng)-0.5) >= 0.0 ? dither : -dither;
515  xmid[i]=(0.5+s)*xl[i]+(0.5-s)*xu[i];
516  }
517 
518  /*
519  [GSL] The idea is to chose the direction to bisect based on
520  which will give the smallest total variance. We could (and may
521  do so later) use MC to compute these variances. But the NR guys
522  simply estimate the variances by finding the min and max
523  function values for each half-region for each bisection.
524  */
525  estimate_corrmc(func,dim,xl,xu,estimate_calls,
526  res_est,err_est,xmid,sigma_l,sigma_r);
527 
528  // [GSL] We have now used up some calls for the estimation
529 
530  calls -= estimate_calls;
531 
532  // [GSL] Now find direction with the smallest total "variance"
533 
534  {
535  double best_var=GSL_DBL_MAX;
536  double beta=2.0/(1.0+alpha);
537  found_best=0;
538  i_bisect=0;
539  weight_l=weight_r=1.0;
540 
541  for (i=0;i<dim;i++) {
542  if (sigma_l[i] >= 0 && sigma_r[i] >= 0) {
543  // [GSL] Estimates are okay
544  double var=pow (sigma_l[i], beta)+pow (sigma_r[i], beta);
545 
546  if (var <= best_var) {
547  found_best=1;
548  best_var=var;
549  i_bisect=i;
550  weight_l=pow (sigma_l[i], beta);
551  weight_r=pow (sigma_r[i], beta);
552  if (weight_l==0 && weight_r==0) {
553  weight_l=1;
554  weight_r=1;
555  }
556  }
557  } else {
558  if (sigma_l[i]<0) {
559  O2SCL_ERR2("No points in left-half space ",
560  "in mcarlo_miser::miser_minteg_err().",
561  exc_esanity);
562  }
563  if (sigma_r[i]<0) {
564  O2SCL_ERR2("No points in right-half space ",
565  "in mcarlo_miser::miser_minteg_err().",
566  exc_esanity);
567  }
568  }
569  }
570  }
571 
572  if (!found_best) {
573  // [GSL] All estimates were the same, so chose a direction at
574  // random
575  i_bisect=((int)(this->rng_dist(this->rng)*(dim-1.0e-10)));
576  //std::uniform_int_distribution<int> int_dist(0,dim-1);
577  //i_bisect=int_dist(this->rng);
578  //gsl_rnga gr;
579  //i_bisect=gr.random_int(dim);
580  }
581 
582  xbi_l=xl[i_bisect];
583  xbi_m=xmid[i_bisect];
584  xbi_r=xu[i_bisect];
585 
586  // [GSL] Get the actual fractional sizes of the two "halves", and
587  // distribute the remaining calls among them
588  {
589  double fraction_l=fabs ((xbi_m-xbi_l)/(xbi_r-xbi_l));
590  double fraction_r=1-fraction_l;
591 
592  double a=fraction_l*weight_l;
593  double b=fraction_r*weight_r;
594 
595  calls_l=(size_t)(min_calls+(calls-2*min_calls)*a/(a+b));
596  calls_r=(size_t)(min_calls+(calls-2*min_calls)*b/(a+b));
597  }
598 
599  if (this->verbose>0 && level<n_levels_out) {
600  std::cout << "mcarlo_miser: level,calls_l,calls_r,calls,min_calls_pb: "
601  << level << " " << calls_l << " " << calls_r << " " << calls << " "
602  << min_calls_per_bisection << std::endl;
603  std::cout << "\tres,err: " << res_est << " " << err_est << std::endl;
604  if (this->verbose>1) {
605  std::cout << "\ti,left,mid,right: " << i_bisect << " "
606  << xbi_l << " " << xbi_m << " " << xbi_r << std::endl;
607  for(size_t j=0;j<dim;j++) {
608  std::cout << "\t\ti,low,high: " << j << " " << xl[j] << " " << xu[j]
609  << std::endl;
610  }
611  }
612  if (this->verbose>2) {
613  char ch;
614  std::cin >> ch;
615  }
616  }
617 
618  /* [GSL] Compute the integral for the left hand side of the
619  bisection. Due to the recursive nature of the algorithm we must
620  allocate some new memory for the integration limits for each
621  recursive call
622  */
623  {
624  int status;
625 
626  vec_t xu_tmp(dim);
627 
628  for (i=0;i<dim;i++) {
629  xu_tmp[i]=xu[i];
630  }
631 
632  xu_tmp[i_bisect]=xbi_m;
633 
634  status=miser_minteg_err(func,dim,xl,xu_tmp,calls_l,level+1,
635  res_l,err_l);
636 
637  if (status != success) {
638  return status;
639  }
640  }
641 
642  // [GSL] Compute the integral for the right hand side of the
643  // bisection
644  {
645  int status;
646 
647  vec_t xl_tmp(dim);
648 
649  for (i=0;i<dim;i++) {
650  xl_tmp[i]=xl[i];
651  }
652 
653  xl_tmp[i_bisect]=xbi_m;
654 
655  status=miser_minteg_err(func,dim,xl_tmp,xu,calls_r,level+1,
656  res_r,err_r);
657 
658  if (status != success) {
659  return status;
660  }
661  }
662 
663  res=res_l+res_r;
664  err=sqrt(err_l*err_l+err_r*err_r);
665 
666  return 0;
667  }
668 
669  /** \brief Integrate function \c func from x=a to x=b.
670 
671  This function is just a wrapper to miser_minteg_err() which
672  allocates the memory if necessary, sets \c min_calls and \c
673  min_calls_per_bisection, calls \ref miser_minteg_err(), and then
674  frees the previously allocated memory.
675  */
676  virtual int minteg_err(func_t &func, size_t ndim, const vec_t &a,
677  const vec_t &b, double &res, double &err) {
678  if (ndim!=dim) allocate(ndim);
681  int ret=miser_minteg_err(func,ndim,a,b,this->n_points,0,res,err);
682  // Set these to back to zero to ensure that if
683  // miser_minteg_err() is called directly, the user sets
684  // min_calls and min_calls_per_bisection first.
685  min_calls=0;
687  return ret;
688  }
689 
690  /** \brief Integrate function \c func over the hypercube from
691  \f$ x_i=a_i \f$ to \f$ x_i=b_i \f$ for
692  \f$ 0<i< \f$ ndim-1
693 
694  This function is just a wrapper to minteg_err() which allocates
695  the memory, sets min_calls and min_calls_per_bisection, calls
696  miser_minteg_err(), and then frees the previously allocated
697  memory.
698  */
699  virtual double minteg(func_t &func, size_t ndim, const vec_t &a,
700  const vec_t &b) {
701  double res;
702  minteg_err(func,ndim,a,b,res,this->interror);
703  return res;
704  }
705 
706  /// Return string denoting type ("mcarlo_miser")
707  virtual const char *type() { return "mcarlo_miser"; }
708 
709  };
710 
711 #ifndef DOXYGEN_NO_O2NS
712 }
713 #endif
714 
715 #endif
716 
ubvector_size_t hits_r
The number of evaluation points in the right half.
Definition: mcarlo_miser.h:248
size_t calls_per_dim
Number of calls per dimension (default 16)
Definition: mcarlo_miser.h:105
size_t bisection_ratio
Factor to set min_calls_per_bisection (default 32)
Definition: mcarlo_miser.h:109
ubvector_size_t hits_l
The number of evaluation points in the left half.
Definition: mcarlo_miser.h:246
rng_dist_t rng_dist
The random number distribution.
Definition: mcarlo.h:68
sanity check failed - shouldn't happen
Definition: err_hnd.h:65
invalid argument supplied by user
Definition: err_hnd.h:59
size_t dim
The number of dimensions of memory allocated.
Definition: mcarlo_miser.h:219
unsigned long n_points
Number of integration points (default 1000)
Definition: mcarlo.h:65
ubvector fmin_l
The minimum function value in the left half.
Definition: mcarlo_miser.h:234
ubvector sigma_r
The right variance.
Definition: mcarlo_miser.h:228
size_t min_calls
Minimum number of calls to estimate the variance.
Definition: mcarlo_miser.h:213
generic failure
Definition: err_hnd.h:61
virtual int estimate_corrmc(func_t &func, size_t ndim, const vec_t &xl, const vec_t &xu, size_t calls, double &res, double &err, const ubvector &lxmid, ubvector &lsigma_l, ubvector &lsigma_r)
Estimate the variance.
Definition: mcarlo_miser.h:256
ubvector fmax_l
The maximum function value in the left half.
Definition: mcarlo_miser.h:230
double estimate_frac
Specify fraction of function calls for estimating variance (default 0.1)
Definition: mcarlo_miser.h:135
ubvector xmid
The current midpoint.
Definition: mcarlo_miser.h:224
int set_min_calls_per_bisection(size_t &mcb)
Minimum number of calls required to proceed with bisection.
Definition: mcarlo_miser.h:198
double alpha
How estimated variances for two sub-regions are combined (default 2.0)
Definition: mcarlo_miser.h:160
ubvector sigma_l
The left variance.
Definition: mcarlo_miser.h:226
virtual int minteg_err(func_t &func, size_t ndim, const vec_t &a, const vec_t &b, double &res, double &err)
Integrate function func from x=a to x=b.
Definition: mcarlo_miser.h:676
rng_t rng
The random number generator.
Definition: mcarlo.h:71
ubvector fsum2_l
The sum of the squares in the left half.
Definition: mcarlo_miser.h:242
virtual const char * type()
Return string denoting type ("mcarlo_miser")
Definition: mcarlo_miser.h:707
int verbose
Verbosity.
Definition: inte_multi.h:64
vec_t x
The most recent integration point.
Definition: mcarlo_miser.h:350
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
Monte-Carlo integration [abstract base].
Definition: mcarlo.h:53
ubvector fsum2_r
The sum of the squares in the right half.
Definition: mcarlo_miser.h:244
size_t min_calls_per_bisection
Minimum number of calls required to proceed with bisection.
Definition: mcarlo_miser.h:216
ubvector fsum_l
The sum in the left half.
Definition: mcarlo_miser.h:238
virtual int allocate(size_t ldim)
Allocate memory.
Definition: mcarlo_miser.h:372
ubvector fmin_r
The minimum function value in the right half.
Definition: mcarlo_miser.h:236
size_t n_levels_out
The number of recursive levels to output when verbose is greater than zero (default 5) ...
Definition: mcarlo_miser.h:206
double interror
The uncertainty for the last integration computation.
Definition: inte_multi.h:110
Multidimensional integration using the MISER Monte Carlo algorithm (GSL)
Definition: mcarlo_miser.h:96
int set_min_calls(size_t &mc)
Minimum number of calls to estimate the variance.
Definition: mcarlo_miser.h:177
ubvector fsum_r
The sum in the right half.
Definition: mcarlo_miser.h:240
std::function< double(size_t, const boost::numeric::ublas::vector< double > &)> multi_funct11
Multi-dimensional function typedef.
Definition: multi_funct.h:45
virtual int miser_minteg_err(func_t &func, size_t ndim, const vec_t &xl, const vec_t &xu, size_t calls, size_t level, double &res, double &err)
Integrate function func over the hypercube from to for ndim-1.
Definition: mcarlo_miser.h:411
Success.
Definition: err_hnd.h:47
ubvector fmax_r
The maximum function value in the right half.
Definition: mcarlo_miser.h:232
virtual double minteg(func_t &func, size_t ndim, const vec_t &a, const vec_t &b)
Integrate function func over the hypercube from to for ndim-1.
Definition: mcarlo_miser.h:699
double dither
Introduce random variation into bisection (default 0.0)
Definition: mcarlo_miser.h:123

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..