44 unur_set_default_debug(UNUR_DEBUG_ALL);
45 else if (debugLevel == 1)
46 unur_set_default_debug(UNUR_DEBUG_INIT);
48 unur_set_default_debug(UNUR_DEBUG_OFF);
71 if (
this == &rhs)
return *
this;
78 std::string s = dist +
" & " + method;
79 fGen = unur_str2gen(s.c_str() );
81 Error(
"Init",
"Cannot create generator object");
111 fDist.reset(distNew);
126 fDist.reset(distNew);
140 fDist.reset(distNew);
155 if (
fRng == 0)
return false;
156 if (
fGen == 0)
return false;
159 if (
fUrng == 0)
return false;
160 unsigned int ret = 0;
163 if (ret != 0)
return false;
173 fUdistr = unur_distr_cont_new();
174 if (
fUdistr == 0)
return false;
175 unsigned int ret = 0;
176 ret = unur_distr_set_extobj(
fUdistr, &dist);
177 if ( ! dist.IsLogPdf() ) {
192 Error(
"SetContDistribution",
"invalid domain xmin = %g xmax = %g ",
xmin,
xmax);
196 if (dist.HasMode() ) {
197 ret = unur_distr_cont_set_mode(
fUdistr, dist.Mode());
199 Error(
"SetContDistribution",
"invalid mode given, mode = %g ",dist.Mode());
203 if (dist.HasPdfArea() ) {
204 ret = unur_distr_cont_set_pdfarea(
fUdistr, dist.PdfArea());
206 Error(
"SetContDistribution",
"invalid area given, area = %g ",dist.PdfArea());
211 return (ret ==0) ? true :
false;
219 fUdistr = unur_distr_cvec_new(dist.NDim() );
220 if (
fUdistr == 0)
return false;
221 unsigned int ret = 0;
222 ret |= unur_distr_set_extobj(
fUdistr, &dist );
223 if ( ! dist.IsLogPdf() ) {
234 const double *
xmin = dist.GetLowerDomain();
235 const double *
xmax = dist.GetUpperDomain();
239 Error(
"SetMultiDistribution",
"invalid domain");
243 Error(
"SetMultiDistribution",
"domain setting not available in UNURAN 0.8.1");
248 const double * xmode = dist.GetMode();
250 ret = unur_distr_cvec_set_mode(
fUdistr, xmode);
252 Error(
"SetMultiDistribution",
"invalid mode");
256 return (ret ==0) ? true :
false;
263 if (dist.NDim() == 1)
264 fUdistr = unur_distr_cemp_new();
266 fUdistr = unur_distr_cvemp_new(dist.NDim() );
268 if (
fUdistr == 0)
return false;
269 unsigned int ret = 0;
273 if (dist.IsBinned() ) {
274 int nbins = dist.Data().size();
275 double min = dist.LowerBin();
276 double max = dist.UpperBin();
277 const double * pv = &(dist.Data().front());
278 ret |= unur_distr_cemp_set_hist(
fUdistr, pv, nbins, min, max);
280 Error(
"SetEmpiricalDistribution",
"hist method not available in UNURAN 0.8.1");
284 const double * pv = &dist.Data().front();
286 int n = dist.Data().size()/dist.NDim();
287 if (dist.NDim() == 1)
288 ret |= unur_distr_cemp_set_data(
fUdistr, pv,
n);
290 ret |= unur_distr_cvemp_set_data(
fUdistr, pv,
n);
293 Error(
"SetEmpiricalDistribution",
"invalid distribution object");
304 fUdistr = unur_distr_discr_new();
305 if (
fUdistr == 0)
return false;
306 unsigned int ret = 0;
308 if (dist.ProbVec().size() == 0) {
309 ret = unur_distr_set_extobj(
fUdistr, &dist );
316 ret |= unur_distr_discr_set_pv(
fUdistr, &dist.ProbVec().front(), dist.ProbVec().size() );
323 Error(
"SetDiscrDistribution",
"invalid domain xmin = %d xmax = %d ",
xmin,
xmax);
327 if (dist.HasMode() ) {
328 ret = unur_distr_discr_set_mode(
fUdistr, dist.Mode());
330 Error(
"SetContDistribution",
"invalid mode given, mode = %d ",dist.Mode());
334 if (dist.HasProbSum() ) {
335 ret = unur_distr_discr_set_pmfsum(
fUdistr, dist.ProbSum());
337 Error(
"SetContDistribution",
"invalid sum given, mode = %g ",dist.ProbSum());
342 return (ret ==0) ? true :
false;
351 if (
fUdistr == 0)
return false;
353 struct unur_slist *mlist = NULL;
357 Error(
"SetMethod",
"missing distribution information or syntax error");
358 if (mlist != 0) _unur_slist_free(mlist);
364 unur_set_use_distr_privatecopy (par,
false);
368 fGen = unur_init(par);
369 _unur_slist_free(mlist);
371 Error(
"SetMethod",
"initializing Unuran: condition for method violated");
382 return unur_sample_discr(
fGen);
389 return unur_sample_cont(
fGen);
395 if (
fGen == 0)
return false;
396 unur_sample_vec(
fGen,
x);
406 if (
fGen == 0)
return false;
409 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
410 else if (debugLevel == 1)
411 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
413 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_OFF);
415 return (ret ==0) ? true :
false;
424 fUdistr = unur_distr_poisson(p,1);
427 if (
fUdistr == 0)
return false;
439 fUdistr = unur_distr_binomial(par,2);
442 if (
fUdistr == 0)
return false;
452 if (!
fGen )
return false;
454 unur_distr_discr_set_pmfparams(
fUdistr,par,npar);
455 int iret = unur_reinit(
fGen);
456 if (iret)
Warning(
"ReInitDiscrDist",
"re-init failed - a full initizialization must be performed");
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
R__EXTERN TRandom * gRandom
This is the base class for the ROOT Random number generators.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
TUnuranContDist class describing one dimensional continuous distribution.
virtual TUnuranContDist * Clone() const
Clone (required by base class)
TUnuranDiscrDist class for one dimensional discrete distribution.
virtual TUnuranDiscrDist * Clone() const
Clone (required by base class)
TUnuranEmpDist class for describing empiral distributions.
unsigned int NDim() const
Number of data dimensions.
TUnuranEmpDist * Clone() const
Clone (required by base class)
bool IsBinned() const
Flag to control if data are binned.
TUnuranMultiContDist class describing multi dimensional continuous distributions.
virtual TUnuranMultiContDist * Clone() const
Clone (required by base class)
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
int SampleDiscr()
Sample discrete distributions User is responsible for having previously correctly initialized with TU...
std::unique_ptr< TUnuranBaseDist > fDist
bool SetDiscreteDistribution(const TUnuranDiscrDist &dist)
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...
bool SetContDistribution(const TUnuranContDist &dist)
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
bool ReInitDiscrDist(unsigned int npar, double *params)
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and meth...
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
bool SetRandomGenerator()
bool SetLogLevel(unsigned int iflag=1)
set log level
bool SetMultiDistribution(const TUnuranMultiContDist &dist)
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
bool SetEmpiricalDistribution(const TUnuranEmpDist &dist)
bool InitPoisson(double mu, const std::string &method="dstd")
Initialize method for the Poisson distribution Used to generate poisson numbers for a constant parame...
TUnuran & operator=(const TUnuran &rhs)
Assignment operator.
void SetSeed(unsigned int seed)
set the seed for the random number generator
static double Cdf(double x, const UNUR_DISTR *dist)
evaluate the Cumulative distribution function, integral of the pdf
static double Pdf(double x, const UNUR_DISTR *dist)
evaluate the probality density function
static double Dpdf(double x, const UNUR_DISTR *dist)
evaluate the derivative of the pdf
static double Pmf(int x, const UNUR_DISTR *dist)
evaluate the probality mesh function
static double Cdf(int x, const UNUR_DISTR *dist)
evaluate the cumulative function
static double Pdf(const double *x, UNUR_DISTR *dist)
evaluate the probality density function
static int Dpdf(double *grad, const double *x, UNUR_DISTR *dist)
static double Pdpdf(const double *x, int coord, UNUR_DISTR *dist)
UnuranRng class for interface ROOT random generators to Unuran.