48 unur_set_default_debug(UNUR_DEBUG_ALL);
49 else if (debugLevel == 1)
50 unur_set_default_debug(UNUR_DEBUG_INIT);
52 unur_set_default_debug(UNUR_DEBUG_OFF);
75 if (
this == &rhs)
return *
this;
82 std::string s = dist +
" & " + method;
83 fGen = unur_str2gen(s.c_str() );
85 Error(
"Init",
"Cannot create generator object");
99 fDist = std::auto_ptr< TUnuranBaseDist>(distNew);
115 fDist = std::auto_ptr< TUnuranBaseDist>(distNew);
130 fDist = std::auto_ptr< TUnuranBaseDist>(distNew);
144 fDist = std::auto_ptr< TUnuranBaseDist>(distNew);
147 if (distr.
IsBinned()) fMethod =
"hist";
148 else if (distr.
NDim() > 1) fMethod =
"vempk";
159 if (
fRng == 0)
return false;
160 if (
fGen == 0)
return false;
163 if (
fUrng == 0)
return false;
164 unsigned int ret = 0;
167 if (ret != 0)
return false;
177 fUdistr = unur_distr_cont_new();
178 if (
fUdistr == 0)
return false;
179 unsigned int ret = 0;
180 ret = unur_distr_set_extobj(
fUdistr, &dist);
194 ret = unur_distr_cont_set_domain(
fUdistr,xmin,xmax);
196 Error(
"SetContDistribution",
"invalid domain xmin = %g xmax = %g ",xmin,xmax);
201 ret = unur_distr_cont_set_mode(
fUdistr, dist.
Mode());
203 Error(
"SetContDistribution",
"invalid mode given, mode = %g ",dist.
Mode());
210 Error(
"SetContDistribution",
"invalid area given, area = %g ",dist.
PdfArea());
215 return (ret ==0) ?
true :
false;
224 if (
fUdistr == 0)
return false;
225 unsigned int ret = 0;
226 ret |= unur_distr_set_extobj(
fUdistr, &dist );
240 if ( xmin != 0 || xmax != 0 ) {
241 ret = unur_distr_cvec_set_domain_rect(
fUdistr,xmin,xmax);
243 Error(
"SetMultiDistribution",
"invalid domain");
247 Error(
"SetMultiDistribution",
"domain setting not available in UNURAN 0.8.1");
252 const double * xmode = dist.
GetMode();
254 ret = unur_distr_cvec_set_mode(
fUdistr, xmode);
256 Error(
"SetMultiDistribution",
"invalid mode");
260 return (ret ==0) ?
true :
false;
267 if (dist.
NDim() == 1)
268 fUdistr = unur_distr_cemp_new();
272 if (
fUdistr == 0)
return false;
273 unsigned int ret = 0;
281 const double * pv = &(dist.
Data().front());
282 ret |= unur_distr_cemp_set_hist(
fUdistr, pv, nbins, min, max);
284 Error(
"SetEmpiricalDistribution",
"hist method not available in UNURAN 0.8.1");
288 const double * pv = &dist.
Data().front();
291 if (dist.
NDim() == 1)
292 ret |= unur_distr_cemp_set_data(
fUdistr, pv, n);
294 ret |= unur_distr_cvemp_set_data(
fUdistr, pv, n);
297 Error(
"SetEmpiricalDistribution",
"invalid distribution object");
308 fUdistr = unur_distr_discr_new();
309 if (
fUdistr == 0)
return false;
310 unsigned int ret = 0;
312 if (dist.
ProbVec().size() == 0) {
313 ret = unur_distr_set_extobj(
fUdistr, &dist );
325 ret = unur_distr_discr_set_domain(
fUdistr,xmin,xmax);
327 Error(
"SetDiscrDistribution",
"invalid domain xmin = %d xmax = %d ",xmin,xmax);
332 ret = unur_distr_discr_set_mode(
fUdistr, dist.
Mode());
334 Error(
"SetContDistribution",
"invalid mode given, mode = %d ",dist.
Mode());
341 Error(
"SetContDistribution",
"invalid sum given, mode = %g ",dist.
ProbSum());
346 return (ret ==0) ?
true :
false;
355 if (
fUdistr == 0)
return false;
357 struct unur_slist *mlist =
NULL;
361 Error(
"SetMethod",
"missing distribution information or syntax error");
362 if (mlist != 0) _unur_slist_free(mlist);
368 unur_set_use_distr_privatecopy (par,
false);
372 fGen = unur_init(par);
373 _unur_slist_free(mlist);
375 Error(
"SetMethod",
"initializing Unuran: condition for method violated");
386 return unur_sample_discr(
fGen);
393 return unur_sample_cont(
fGen);
399 if (
fGen == 0)
return false;
400 unur_sample_vec(
fGen,x);
410 if (
fGen == 0)
return false;
413 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
414 else if (debugLevel == 1)
415 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
417 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_OFF);
419 return (ret ==0) ?
true :
false;
428 fUdistr = unur_distr_poisson(p,1);
431 if (
fUdistr == 0)
return false;
443 fUdistr = unur_distr_binomial(par,2);
446 if (
fUdistr == 0)
return false;
456 if (!
fGen )
return false;
458 unur_distr_discr_set_pmfparams(
fUdistr,par,npar);
459 int iret = unur_reinit(
fGen);
460 if (iret)
Warning(
"ReInitDiscrDist",
"re-init failed - a full initizialization must be performed");
bool HasCdf() const
flag to control if distribution provides also a Cdf
int Mode() const
get the mode (x location of function maximum)
static double Pdpdf(const double *x, int coord, UNUR_DISTR *dist)
double dist(Rotation3D const &r1, Rotation3D const &r2)
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
bool InitBinomial(unsigned int ntot, double prob, const std::string &method="dstd")
Initialize method for the Binomial distribution Used to generate poisson numbers for a constant param...
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
bool ReInitDiscrDist(unsigned int npar, double *params)
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and meth...
static double Cdf(int x, const UNUR_DISTR *dist)
evaluate the cumulative function
TUnuran & operator=(const TUnuran &rhs)
Assignment operator.
static double Pdf(const double *x, UNUR_DISTR *dist)
evaluate the probality density function
const std::vector< double > & Data() const
Return reference to data vector (unbinned or binned data)
int SampleDiscr()
Sample discrete distributions User is responsible for having previously correctly initialized with TU...
UnuranRng class for interface ROOT random generators to Unuran.
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
bool IsLogPdf() const
flag to control if given function represent the log of a pdf
static double Dpdf(double x, const UNUR_DISTR *dist)
evaluate the derivative of the pdf
bool SetLogLevel(unsigned int iflag=1)
set log level
static int Dpdf(double *grad, const double *x, UNUR_DISTR *dist)
bool HasMode() const
check if distribution has a pre-computed mode
double distr(double *x, double *p)
std::auto_ptr< TUnuranBaseDist > fDist
virtual TUnuranContDist * Clone() const
Clone (required by base class)
This is the base class for the ROOT Random number generators.
bool InitPoisson(double mu, const std::string &method="dstd")
Initialize method for the Poisson distribution Used to generate poisson numbers for a constant parame...
void SetSeed(unsigned int seed)
set the seed for the random number generator
const double * GetUpperDomain() const
get the distribution upper domain values.
bool GetDomain(int &xmin, int &xmax) const
check if distribution has domain and return in case its domain
TUnuranDiscrDist class for one dimensional discrete distribution.
bool SetMultiDistribution(const TUnuranMultiContDist &dist)
TUnuranEmpDist class for describing empiral distributions.
void Error(const char *location, const char *msgfmt,...)
TUnuranEmpDist * Clone() const
Clone (required by base class)
const std::vector< double > & ProbVec() const
retrieve a reference to the vector of the probabilities : Prob(i) If the distribution is defined from...
bool SetContDistribution(const TUnuranContDist &dist)
const double * GetLowerDomain() const
get the distribution lower domain values.
static double Pmf(int x, const UNUR_DISTR *dist)
evaluate the probality mesh function
double LowerBin() const
Min value of binned data (return 0 for unbinned data)
virtual TUnuranMultiContDist * Clone() const
Clone (required by base class)
bool HasMode() const
flag to control if distribution provides the mode
static double Pdf(double x, const UNUR_DISTR *dist)
evaluate the probality density function
TUnuranMultiContDist class describing multi dimensional continuous distributions. ...
bool HasCdf() const
check if a cdf function is provided for the distribution
static double Cdf(double x, const UNUR_DISTR *dist)
evaluate the Cumulative distribution function, integral of the pdf
bool HasPdfArea() const
check if distribution has a pre-computed area below the Pdf
void Warning(const char *location, const char *msgfmt,...)
R__EXTERN TRandom * gRandom
TUnuran(TRandom *r=0, unsigned int log=0)
Constructor with a generator instance and given level of log output.
bool SetMethodAndInit()
change the method and initialize Unuran with the previously given distribution
bool IsBinned() const
Flag to control if data are binned.
bool IsLogPdf() const
flag to control if given function represent the log of a pdf
double ProbSum() const
return area of the pdf
bool SetDiscreteDistribution(const TUnuranDiscrDist &dist)
bool GetDomain(double &xmin, double &xmax) const
check if distribution has a defined domain and return in case its domain
bool HasProbSum() const
flag to control if distribution provides the total area of the probability function ...
double UpperBin() const
upper value of binned data (return 0 for unbinned data)
bool SetRandomGenerator()
unsigned int NDim() const
Number of data dimensions.
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
TUnuranContDist class describing one dimensional continuous distribution.
double Mode() const
return the mode (x location of maximum of the pdf)
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
unsigned int NDim() const
get number of dimension of the distribution
virtual TUnuranDiscrDist * Clone() const
Clone (required by base class)
double PdfArea() const
return area below the pdf
bool SetEmpiricalDistribution(const TUnuranEmpDist &dist)
const double * GetMode() const
get the mode (vector of coordinate positions of the maxima of the distribution) If a mode has not def...