ROOT logo
ROOT » MATH » UNURAN » TUnuranDiscrDist

class TUnuranDiscrDist: public TUnuranBaseDist


   TUnuranDiscrDist class for one dimensional discrete distribution.
   It is used by TUnuran to generate integer random numbers according to this distribution via
   TUnuran::SampleDiscr().

   The class can be constructed from a one-dimensional function (TF1 pointer)
   representing the discrete distribution (probability mesh function)
   (for example a TF1("f","TMath::PoissonI(x,[0])") ) or from a
   vector of probability, used by passing an iterator specifying the begin and the end of the vector.
   In the latter case the domain of the distribution will be defined by the vector, while in the first case is by
   default (0,+inf).
   a Method to set the domain of the distribution ( SetDomain ) is provided and it defines the range
   of the generated random numbers.

   The derivatives of the pdf which are used by some UNURAN methods are estimated numerically in the
   Derivative() method.
   Some extra information (like distribution mode, cdf function, probability sum, etc..)
   can be set as well otherwise will be estimated internally if required.



Function Members (Methods)

public:
TUnuranDiscrDist(const ROOT::Math::IGenFunction& func)
TUnuranDiscrDist(TF1* func)
TUnuranDiscrDist(const TUnuranDiscrDist&)
TUnuranDiscrDist(double* begin, double* end)
virtual~TUnuranDiscrDist()
doubleCdf(int x) const
static TClass*Class()
static TClass*TUnuranBaseDist::Class()
virtual TUnuranDiscrDist*Clone() const
virtual TUnuranBaseDist*TUnuranBaseDist::Clone() const
boolGetDomain(int& xmin, int& xmax) const
boolHasCdf() const
boolHasMode() const
boolHasProbSum() const
virtual TClass*IsA() const
virtual TClass*TUnuranBaseDist::IsA() const
intMode() const
TUnuranDiscrDist&operator=(const TUnuranDiscrDist& rhs)
TUnuranBaseDist&TUnuranBaseDist::operator=(const TUnuranBaseDist&)
doublePmf(int x) const
doubleProbSum() const
const vector<double>&ProbVec() const
voidSetCdf(const ROOT::Math::IGenFunction& cdf)
voidSetCdf(TF1* cdf)
voidSetDomain(int xmin, int xmax)
voidSetMode(int mode)
voidSetProbSum(double sum)
virtual voidShowMembers(TMemberInspector& insp, char* parent)
virtual voidTUnuranBaseDist::ShowMembers(TMemberInspector& insp, char* parent)
virtual voidStreamer(TBuffer& b)
virtual voidTUnuranBaseDist::Streamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
voidTUnuranBaseDist::StreamerNVirtual(TBuffer& b)

Data Members

private:
const ROOT::Math::IBaseFunctionOneDim*fCdfpointer to the cumulative distribution function
boolfHasDomainflag to control if distribution has a defined domain (otherwise is [0,INT_MAX])
boolfHasModeflag to control if distribution has a pre-computed mode
boolfHasSumflag to control if distribution has a pre-computed sum of the probabilities
intfModemode of the distribution
boolfOwnFuncflag to control if distribution owns the funcitno pointers
vector<double>fPVecVector of the probabilities
vector<double>fPVecSumVector of the sum of the probabilities
const ROOT::Math::IBaseFunctionOneDim*fPmfpointer to a function calculating the probability
doublefSumtotal sum of the probabilities in the given domain
intfXmaxupper value of the domain
intfXminlower value of the domain

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TUnuranDiscrDist(const ROOT::Math::IGenFunction & func )
      Constructor from a generic function object specifying the pdf

TUnuranDiscrDist(TF1 * func )
      Constructor from a TF1 objects specifying the pdf

TUnuranDiscrDist(double* begin, double* end)
      Constructor from a vector of probability

{}
virtual ~TUnuranDiscrDist()
      Destructor

TUnuranDiscrDist(const TUnuranDiscrDist &)
      Copy constructor

TUnuranDiscrDist * Clone() const
      Clone (required by base class)

{ return new TUnuranDiscrDist(*this); }
void SetCdf(const ROOT::Math::IGenFunction & cdf)
      set cdf distribution from a generic function interface. If a method requires it
      and is not set it is estimated numerically

void SetCdf(TF1 * cdf)
      set cdf distribution from a TF1 pointer.  If a method requires it
      and is not set it is estimated numerically

void SetDomain(int xmin, int xmax)
      Set the distribution domain, by default the domain is [0,INT_MAX]
      If xmin >= xmax a domain is removed

void SetMode(int mode)
      set the mode of the distribution (location of maximum probability)

{ fMode = mode; fHasMode=true;}
void SetProbSum(double sum)
      set the value of the sum of the probabilities in the given domain

{ fSum = sum; fHasSum=true; }
bool GetDomain(int& xmin, int& xmax) const
      check if distribution has domain and return in case its domain

int Mode() const
      get the mode   (x location of function maximum)

{ return fMode; }
double ProbSum() const
      return area of the pdf

{ return fSum; }
bool HasMode() const
      flag to control if distribution provides the mode

{ return fHasMode; }
bool HasProbSum() const
      flag to control if distribution provides the total area of the probability function

{ return fHasSum; }
bool HasCdf() const
      flag to control if distribution provides also a Cdf

{ return fCdf != 0; }
const std::vector<double> & ProbVec() const
      retrieve a reference to the vector of the probabilities : Prob(i)
      If the distribution is defined from a function (i.e. for distribution with undefined domain)
      the vector is empty.

{ return fPVec; }
double Pmf(int x) const
      evaluate the distribution (probability mesh function) at the integer value x.
      Used internally by UnuRan
      For integer values outside the domain the function must return 0.0

double Cdf(int x) const
       evaluate the integral (cdf)  on the given domain