Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
UnuranDistrAdapter.h
Go to the documentation of this file.
1 // @(#)root/unuran:$Id$
2 // Author: L. Moneta Wed Sep 27 11:22:07 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class UnuranDistr
12 
13 #ifndef ROOT_Math_UnuranDistr
14 #define ROOT_Math_UnuranDistr
15 
16 #include "unuran.h"
17 #include <iostream>
18 
19 #include <cmath>
20 
21 /**
22  Free functions adapter needed by UNURAN for onedimensional continuous distributions
23 */
24 
25 #include "TUnuranContDist.h"
26 #include "TUnuranMultiContDist.h"
27 #include "TUnuranDiscrDist.h"
28 
29 struct ContDist {
30 
31  typedef TUnuranContDist Distribution;
32 
33  /// evaluate the probality density function
34  static double Pdf(double x, const UNUR_DISTR * dist) {
35  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
36  return func->Pdf(x);
37  }
38  /// evaluate the derivative of the pdf
39  static double Dpdf(double x, const UNUR_DISTR * dist) {
40  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
41  return func->DPdf(x);
42  }
43 
44  /// evaluate the Cumulative distribution function, integral of the pdf
45  static double Cdf(double x, const UNUR_DISTR * dist) {
46  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
47  return func->Cdf(x);
48  }
49 
50 };
51 
52 /**
53  Free functions adapter needed by UNURAN for multidimensional cont distribution
54 */
55 struct MultiDist {
56 
57  typedef TUnuranMultiContDist Distribution;
58 
59  /// evaluate the probality density function
60  static double Pdf(const double * x, UNUR_DISTR * dist) {
61  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
62  return func->Pdf(x);
63  }
64 
65  // evaluate the gradient vector of the pdf
66  static int Dpdf(double * grad, const double * x, UNUR_DISTR * dist) {
67  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
68  func->Gradient(x,grad);
69  return 0;
70  }
71 
72  // provides the gradient components separatly (partial derivatives)
73  static double Pdpdf(const double * x, int coord, UNUR_DISTR * dist) {
74  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
75  return func->Derivative(x,coord);
76  }
77 
78 };
79 
80 
81 /**
82  Free functions adapter needed by UNURAN for one-dimensional discrete distribution
83 */
84 struct DiscrDist {
85 
86  typedef TUnuranDiscrDist Distribution;
87 
88 
89  /// evaluate the probality mesh function
90  static double Pmf(int x, const UNUR_DISTR * dist) {
91  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
92  return func->Pmf(x);
93  }
94 
95  /// evaluate the cumulative function
96  static double Cdf(int x, const UNUR_DISTR * dist) {
97  const Distribution * func = reinterpret_cast<const Distribution *> ( unur_distr_get_extobj(dist) );
98  return func->Cdf(x);
99  }
100 
101 };
102 
103 
104 
105 #endif /* ROOT_Math_UnuranDistr */