Logo ROOT   6.16/01
Reference Guide
UnuranDistr.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 UnuranDistr
23 Provides free function based on TF1 to be called by unuran
24*/
25
26
27template<class Function>
29
30 /// evaluate the probal
31 static double Pdf(double x, const UNUR_DISTR * dist) {
32 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
33 return func->operator()(x);
34 }
35
36 static double Dpdf(double x, const UNUR_DISTR * dist) {
37 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
38 return func->Derivative(x);
39 }
40
41 static double Cdf(double x, const UNUR_DISTR * dist) {
42 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
43 return func->Cdf(x);
44 }
45
46};
47
48/**
49 free functions for multidimensional functions
50 needed bby UNURAN
51*/
52template<class Function>
54
55 /// evaluate the probality density function
56 static double Pdf(const double * x, UNUR_DISTR * dist) {
57 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
58 assert( func != 0);
59 return func->operator()(x);
60 }
61
62
63 static int Dpdf(double * grad, const double * x, UNUR_DISTR * dist) {
64 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
65 func->Gradient(x,grad);
66 return 0;
67 }
68
69 // provides the gradient componets separatly
70 static double Pdpdf(const double * x, int coord, UNUR_DISTR * dist) {
71 const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
72 return func->Gradient(x,coord);
73 }
74
75 static double Logpdf(const double * x, UNUR_DISTR * dist) {
76// const Function * func = reinterpret_cast<const Function *> ( unur_distr_get_extobj(dist) );
77// assert( func != 0);
78// double y = func->operator()(x);
79// // if ( y < std::numeric_limits<double>::min() )
80 return std::log( Pdf(x,dist) );
81 }
82
83 static int Dlogpdf(double * grad, const double * x, UNUR_DISTR * dist) {
84 int dim = unur_distr_get_dim(dist);
85 double pdf = Pdf(x,dist);
86 int ret = Dpdf(grad,x,dist);
87 for (int i = 0; i < dim; ++i) {
88 grad[i] /= pdf;
89 }
90 return ret;
91 }
92
93 static double Pdlogpdf(const double * x, int coord, UNUR_DISTR * dist) {
94 return Pdpdf(x,coord,dist)/ Pdf(x,dist);
95 }
96
97};
98
99
100
101#endif /* ROOT_Math_UnuranDistr */
double log(double)
struct unur_distr UNUR_DISTR
Definition: TUnuran.h:70
Double_t(* Function)(Double_t)
Definition: Functor.C:4
Double_t x[n]
Definition: legend1.C:17
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
free functions for multidimensional functions needed bby UNURAN
Definition: UnuranDistr.h:53
static int Dlogpdf(double *grad, const double *x, UNUR_DISTR *dist)
Definition: UnuranDistr.h:83
static double Pdlogpdf(const double *x, int coord, UNUR_DISTR *dist)
Definition: UnuranDistr.h:93
static double Pdpdf(const double *x, int coord, UNUR_DISTR *dist)
Definition: UnuranDistr.h:70
static int Dpdf(double *grad, const double *x, UNUR_DISTR *dist)
Definition: UnuranDistr.h:63
static double Pdf(const double *x, UNUR_DISTR *dist)
evaluate the probality density function
Definition: UnuranDistr.h:56
static double Logpdf(const double *x, UNUR_DISTR *dist)
Definition: UnuranDistr.h:75
UnuranDistr Provides free function based on TF1 to be called by unuran.
Definition: UnuranDistr.h:28
static double Cdf(double x, const UNUR_DISTR *dist)
Definition: UnuranDistr.h:41
static double Dpdf(double x, const UNUR_DISTR *dist)
Definition: UnuranDistr.h:36
static double Pdf(double x, const UNUR_DISTR *dist)
evaluate the probal
Definition: UnuranDistr.h:31