UnuranDistrAdapter.h

Go to the documentation of this file.
00001 // @(#)root/unuran:$Id: UnuranDistrAdapter.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: L. Moneta Wed Sep 27 11:22:07 2006
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class UnuranDistr
00012 
00013 #ifndef ROOT_Math_UnuranDistr
00014 #define ROOT_Math_UnuranDistr
00015 
00016 #include "unuran.h"
00017 #include <iostream>
00018 
00019 #include <cmath>
00020 
00021 /** 
00022    Free functions adapter needed by UNURAN for onedimensional continous distributions
00023 */ 
00024 
00025 #include "TUnuranContDist.h"
00026 #include "TUnuranMultiContDist.h"
00027 #include "TUnuranDiscrDist.h"
00028 
00029 struct ContDist {
00030 
00031    typedef TUnuranContDist Distribution; 
00032 
00033    /// evaluate the probality density function
00034    static double Pdf(double x, const UNUR_DISTR * dist) {  
00035       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00036       return func->Pdf(x);      
00037    }   
00038    /// evaluate the derivative of the pdf
00039    static double Dpdf(double x,  const UNUR_DISTR * dist) { 
00040       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00041       return func->DPdf(x);            
00042    }
00043 
00044    /// evaluate the Cumulative distribution function, integral of the pdf
00045    static double Cdf(double x,  const UNUR_DISTR * dist) { 
00046       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00047       return func->Cdf(x);            
00048    }
00049 
00050 }; 
00051 
00052 /**
00053    Free functions adapter needed by UNURAN for multidimensional cont distribution
00054 */
00055 struct MultiDist {
00056 
00057    typedef TUnuranMultiContDist Distribution; 
00058 
00059    /// evaluate the probality density function
00060    static double Pdf(const double * x, UNUR_DISTR * dist) {  
00061       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00062       return func->Pdf(x);      
00063    }   
00064 
00065    // evaluate the gradient vector of the pdf
00066    static int Dpdf(double * grad, const double * x,  UNUR_DISTR * dist) { 
00067       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00068       func->Gradient(x,grad);
00069       return 0; 
00070    }
00071    
00072    // provides the gradient components separatly (partial derivatives)
00073    static double Pdpdf(const double * x, int coord, UNUR_DISTR * dist) { 
00074       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00075       return func->Derivative(x,coord);
00076    }
00077 
00078 }; 
00079 
00080 
00081 /**
00082    Free functions adapter needed by UNURAN for one-dimensional discrete distribution
00083 */
00084 struct DiscrDist {
00085 
00086    typedef TUnuranDiscrDist Distribution; 
00087 
00088 
00089    /// evaluate the probality mesh function
00090    static double Pmf(int x, const UNUR_DISTR * dist) {  
00091       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00092       return func->Pmf(x);      
00093    }   
00094 
00095    /// evaluate the cumulative function
00096    static double Cdf(int x,  const UNUR_DISTR * dist) { 
00097       const Distribution * func = reinterpret_cast<const Distribution *> (  unur_distr_get_extobj(dist) ); 
00098       return func->Cdf(x);            
00099    }
00100 
00101 }; 
00102 
00103 
00104 
00105 #endif /* ROOT_Math_UnuranDistr */

Generated on Tue Jul 5 14:43:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1