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);
56 if (
fGen !=
nullptr) unur_free(
fGen);
65 std::string s = dist +
" & " + method;
66 fGen = unur_str2gen(s.c_str() );
67 if (
fGen ==
nullptr) {
68 Error(
"Init",
"Cannot create generator object");
113 fDist.reset(distNew);
127 fDist.reset(distNew);
142 if (
fRng ==
nullptr)
return false;
143 if (
fGen ==
nullptr)
return false;
146 if (
fUrng ==
nullptr)
return false;
147 unsigned int ret = 0;
150 if (ret != 0)
return false;
160 fUdistr = unur_distr_cont_new();
161 if (
fUdistr ==
nullptr)
return false;
162 unsigned int ret = 0;
163 ret = unur_distr_set_extobj(
fUdistr, &dist);
164 if ( ! dist.IsLogPdf() ) {
179 Error(
"SetContDistribution",
"invalid domain xmin = %g xmax = %g ",
xmin,
xmax);
183 if (dist.HasMode() ) {
184 ret = unur_distr_cont_set_mode(
fUdistr, dist.Mode());
186 Error(
"SetContDistribution",
"invalid mode given, mode = %g ",dist.Mode());
190 if (dist.HasPdfArea() ) {
191 ret = unur_distr_cont_set_pdfarea(
fUdistr, dist.PdfArea());
193 Error(
"SetContDistribution",
"invalid area given, area = %g ",dist.PdfArea());
198 return (ret ==0) ? true :
false;
206 fUdistr = unur_distr_cvec_new(dist.NDim() );
207 if (
fUdistr ==
nullptr)
return false;
208 unsigned int ret = 0;
209 ret |= unur_distr_set_extobj(
fUdistr, &dist );
210 if ( ! dist.IsLogPdf() ) {
221 const double *
xmin = dist.GetLowerDomain();
222 const double *
xmax = dist.GetUpperDomain();
223 if (
xmin !=
nullptr ||
xmax !=
nullptr ) {
226 Error(
"SetMultiDistribution",
"invalid domain");
230 Error(
"SetMultiDistribution",
"domain setting not available in UNURAN 0.8.1");
235 const double * xmode = dist.GetMode();
236 if (xmode !=
nullptr) {
237 ret = unur_distr_cvec_set_mode(
fUdistr, xmode);
239 Error(
"SetMultiDistribution",
"invalid mode");
243 return (ret ==0) ? true :
false;
250 if (dist.NDim() == 1)
251 fUdistr = unur_distr_cemp_new();
253 fUdistr = unur_distr_cvemp_new(dist.NDim() );
255 if (
fUdistr ==
nullptr)
return false;
256 unsigned int ret = 0;
260 if (dist.IsBinned() ) {
261 int nbins = dist.Data().size();
262 double min = dist.LowerBin();
263 double max = dist.UpperBin();
264 const double * pv = &(dist.Data().front());
265 ret |= unur_distr_cemp_set_hist(
fUdistr, pv, nbins, min, max);
267 Error(
"SetEmpiricalDistribution",
"hist method not available in UNURAN 0.8.1");
271 const double * pv = &dist.Data().front();
273 int n = dist.Data().size()/dist.NDim();
274 if (dist.NDim() == 1)
275 ret |= unur_distr_cemp_set_data(
fUdistr, pv,
n);
277 ret |= unur_distr_cvemp_set_data(
fUdistr, pv,
n);
280 Error(
"SetEmpiricalDistribution",
"invalid distribution object");
291 fUdistr = unur_distr_discr_new();
292 if (
fUdistr ==
nullptr)
return false;
293 unsigned int ret = 0;
295 if (dist.ProbVec().empty()) {
296 ret = unur_distr_set_extobj(
fUdistr, &dist );
303 ret |= unur_distr_discr_set_pv(
fUdistr, &dist.ProbVec().front(), dist.ProbVec().size() );
310 Error(
"SetDiscrDistribution",
"invalid domain xmin = %d xmax = %d ",
xmin,
xmax);
314 if (dist.HasMode() ) {
315 ret = unur_distr_discr_set_mode(
fUdistr, dist.Mode());
317 Error(
"SetContDistribution",
"invalid mode given, mode = %d ",dist.Mode());
321 if (dist.HasProbSum() ) {
322 ret = unur_distr_discr_set_pmfsum(
fUdistr, dist.ProbSum());
324 Error(
"SetContDistribution",
"invalid sum given, mode = %g ",dist.ProbSum());
329 return (ret ==0) ? true :
false;
336 if (
fUdistr ==
nullptr)
return false;
338 struct unur_slist *mlist =
nullptr;
341 if (par ==
nullptr) {
342 Error(
"SetMethod",
"missing distribution information or syntax error");
343 if (mlist !=
nullptr) _unur_slist_free(mlist);
349 unur_set_use_distr_privatecopy (par,
false);
352 if (
fGen !=
nullptr ) unur_free(
fGen);
353 fGen = unur_init(par);
354 _unur_slist_free(mlist);
355 if (
fGen ==
nullptr) {
356 Error(
"SetMethod",
"initializing Unuran: condition for method violated");
365 if (!
fGen)
return std::string();
366 return std::string(unur_gen_info(
fGen, extended));
372 if (!
fGen)
return std::string();
373 return std::string(unur_get_genid(
fGen));
380 return unur_get_dimension(
fGen);
386 if (!
fGen)
return -1;
387 return unur_distr_get_type (unur_get_distr(
fGen));
391 if (!
fGen)
return false;
392 return unur_distr_is_cont (unur_get_distr(
fGen));
395 if (!
fGen)
return false;
396 return unur_distr_is_cvec (unur_get_distr(
fGen));
399 if (!
fGen)
return false;
400 return unur_distr_is_discr (unur_get_distr(
fGen));
403 if (!
fGen)
return false;
404 return unur_distr_is_cemp (unur_get_distr(
fGen));
410 assert(
fGen !=
nullptr);
411 return unur_sample_discr(
fGen);
417 assert(
fGen !=
nullptr);
418 return unur_sample_cont(
fGen);
424 if (
fGen ==
nullptr)
return false;
425 unur_sample_vec(
fGen,
x);
435 if (
fGen ==
nullptr)
return false;
438 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
439 else if (debugLevel == 1)
440 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_ALL);
442 ret |= unur_chg_debug(
fGen, UNUR_DEBUG_OFF);
444 return (ret ==0) ? true :
false;
456 if (
fUdistr ==
nullptr)
return false;
467 fUdistr = unur_distr_binomial(par,2);
470 if (
fUdistr ==
nullptr)
return false;
480 if (!
fGen )
return false;
482 unur_distr_discr_set_pmfparams(
fUdistr,par,npar);
483 int iret = unur_reinit(
fGen);
484 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.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
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.
TUnuranContDist * Clone() const override
Clone (required by base class)
TUnuranDiscrDist class for one dimensional discrete distribution.
TUnuranDiscrDist * Clone() const override
Clone (required by base class)
TUnuranEmpDist class for describing empirical distributions.
unsigned int NDim() const
Number of data dimensions.
TUnuranEmpDist * Clone() const override
Clone (required by base class)
bool IsBinned() const
Flag to control if data are binned.
TUnuranMultiContDist class describing multi dimensional continuous distributions.
TUnuranMultiContDist * Clone() const override
Clone (required by base class)
std::string GetGenId() const
Return an ID string about the unuran generator method.
bool IsDistCont() const
Return true for a univariate continuous distribution.
bool SetMethodAndInit()
change the method and initialize Unuran with the previously given distribution
int SampleDiscr()
Sample discrete distributions.
std::unique_ptr< TUnuranBaseDist > fDist
bool SetDiscreteDistribution(const TUnuranDiscrDist &dist)
int GetDistType() const
Return the type of the distribution.
bool InitBinomial(unsigned int ntot, double prob, const std::string &method="dstd")
Initialize method for the Binomial distribution.
bool SetContDistribution(const TUnuranContDist &dist)
std::string GetInfo(bool extended=false)
Return an information string about the used Unuran generator method.
bool SampleMulti(double *x)
Sample multidimensional distributions.
bool ReInitDiscrDist(unsigned int npar, double *params)
Reinitialize UNURAN by changing the distribution parameters but maintaining same distribution and met...
TUnuran(TRandom *r=nullptr, unsigned int log=0)
Constructor with a generator instance and given level of log output.
bool IsDistMultiCont() const
Return true for a multivariate continuous distribution.
bool Init(const std::string &distr, const std::string &method)
Initialize with Unuran string API interface.
bool SetRandomGenerator()
bool SetLogLevel(unsigned int iflag=1)
set log level
bool SetMultiDistribution(const TUnuranMultiContDist &dist)
bool IsDistEmpirical() const
Return true for an empirical distribution.
double Sample()
Sample 1D distribution.
bool SetEmpiricalDistribution(const TUnuranEmpDist &dist)
bool InitPoisson(double mu, const std::string &method="dstd")
Initialize method for the Poisson distribution.
int GetDimension() const
Return the dimension of unuran generator method.
void SetSeed(unsigned int seed)
set the seed for the random number generator
bool IsDistDiscrete() const
Return true for a discrete distribution.
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.