/usr/include/root/TUnuran.h is in libroot-math-unuran-dev 5.34.19+dfsg-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | // @(#)root/unuran:$Id$
// Author: L. Moneta Tue Sep 26 16:25:09 2006
/**********************************************************************
* *
* Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
* *
* *
**********************************************************************/
// Header file for class TUnuran
#ifndef ROOT_TUnuran
#define ROOT_TUnuran
#include <string>
#ifndef ROOT_Math_TUnuranBaseDist
#include "TUnuranBaseDist.h"
#endif
class TUnuranContDist;
class TUnuranDiscrDist;
class TUnuranMultiContDist;
class TUnuranEmpDist;
#include <memory>
//______________________________________________________________________
/**
TUnuran class.
Interface to the UNU.RAN package for generating non uniform random
numbers. This class wraps the UNU.RAN calls in C++ methods.
It provides methods for initializing Unuran and then to sample the
desired distribution.
It provides support for initializing UNU.RAN in these following way (various signatures
for TUnuran::Init)
- with string API via TUnuran::Init passing the distribution type and the method
- using a one-dimensional distribution object defined by TUnuranContDist
- using a multi-dimensional distribution object defined by TUnuranMultiContDist
- using a discrete one-dimensional distribution object defined by TUnuranDiscrDist
- using an empirical distribution defined by TUnuranEmpDist
- using pre-defined distributions. Presently only support for Poisson (TUnuran::InitPoisson)
and Binomial (TUnuran::InitBinomial) are provided. Other distributions can however be generated
using the previous methods (in particular via the string API)
The sampling is provided via these methods:
- TUnuran::Sample() returns a double for all one-dimensional distribution
- TUnuran::SampleDiscr() returns an integer for one-dimensional discrete distribution
- TUnuran::Sample(double *) sample a multi-dimensional distribution. A pointer to a vector with
size at least equal to the distribution dimension must be passed
In addition is possible to set the random number generator in the constructor of the class, its seed
via the TUnuran::SetSeed() method.
*/
///////////////////////////////////////////////////////////////////////
//class TUnuranGenerator;
struct unur_gen;
typedef struct unur_gen UNUR_GEN;
// struct unur_urng_generic;
// typedef struct unur_urng_generic UNUR_URNG;
struct unur_distr;
typedef struct unur_distr UNUR_DISTR;
struct unur_urng;
typedef struct unur_urng UNUR_URNG;
class TRandom;
class TH1;
class TUnuran {
public:
/**
Constructor with a generator instance and given level of log output
*/
TUnuran (TRandom * r = 0, unsigned int log = 0);
/**
Destructor
*/
~TUnuran ();
private:
// usually copying is non trivial, so we make this unaccessible
/**
Copy constructor
*/
TUnuran(const TUnuran &);
/**
Assignment operator
*/
TUnuran & operator = (const TUnuran & rhs);
public:
/**
initialize with Unuran string interface
*/
bool Init(const std::string & distr, const std::string & method);
/**
Initialize method for continuous one-dimensional distribution.
User must provide a distribution object (which is copied inside) and a string for a method.
For the list of available method for 1D cont. distribution see the
<A href="http://statmath.wu-wien.ac.at/unuran/doc/unuran.html#Methods_005ffor_005fCONT">UnuRan doc</A>.
A re-initialization is needed whenever distribution parameters have been changed.
*/
bool Init(const TUnuranContDist & distr, const std::string & method = "auto");
/**
Initialize method for continuous multi-dimensional distribution.
User must provide a distribution object (which is copied inside) and a string for a method.
For the list of available method for multivariate cont. distribution see the
<A href="http://statmath.wu-wien.ac.at/unuran/doc/unuran.html#Methods_005ffor_005fCVEC">UnuRan doc</A>
A re-initialization is needed whenever distribution parameters have been changed.
*/
bool Init(const TUnuranMultiContDist & distr, const std::string & method = "hitro");
/**
Initialize method for continuous one-dimensional discrete distribution.
User must provide a distribution object (which is copied inside) and a string for a method.
For the list of available method for 1D discrete distribution see the
<A href="http://statmath.wu-wien.ac.at/unuran/doc/unuran.html#Methods_005ffor_005fDISCR">UnuRan doc</A>
A re-initialization is needed whenever distribution parameters have been changed.
*/
bool Init(const TUnuranDiscrDist & distr, const std::string & method = "auto");
/**
Initialize method for continuous empirical distribution.
User must provide a distribution object (which is copied inside) and a string for a method.
The distribution object can represent binned (only 1D) or unbinned (1D or multi-dim) data
The method for the unbinned empirical distribution are based on the kernel smoothing, see
<A href="http://statmath.wu-wien.ac.at/software/unuran/doc/unuran.html#EMPK">UnuRan doc</A>
A re-initialization is needed whenever distribution parameters have been changed.
*/
bool Init(const TUnuranEmpDist & distr, const std::string & method = "empk");
/**
Initialize method for the Poisson distribution
Used to generate poisson numbers for a constant parameter mu of the Poisson distribution.
Use after the method TUnuran::SampleDiscr to generate the numbers.
The flag reinit perform a fast re-initialization when only the distribution parameters
are changed in the subsequent calls.
If the same TUnuran object is used to generate with other distributions it cannot be used.
*/
bool InitPoisson(double mu, const std::string & method = "dstd");
/**
Initialize method for the Binomial distribution
Used to generate poisson numbers for a constant parameters (n,p) of the Binomial distribution.
Use after the method TUnuran::SampleDiscr to generate the numbers.
The flag reinit perform a fast re-initialization when only the distribution parameters
are changed in the subsequent calls.
If the same TUnuran object is used to generate with other distributions it cannot be used.
*/
bool InitBinomial(unsigned int ntot, double prob, const std::string & method = "dstd");
/**
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and method
It is implemented now only for predefined discrete distributions like the poisson or the binomial
*/
bool ReInitDiscrDist(unsigned int npar, double * params);
/**
Sample 1D distribution
User is responsible for having previously correctly initialized with TUnuran::Init
*/
double Sample();
/**
Sample multidimensional distributions
User is responsible for having previously correctly initialized with TUnuran::Init
*/
bool SampleMulti(double * x);
/**
Sample discrete distributions
User is responsible for having previously correctly initialized with TUnuran::Init
*/
int SampleDiscr();
/**
set the random engine.
Must be called before init to have effect
*/
void SetRandom(TRandom * r) {
fRng = r;
}
/**
return instance of the random engine used
*/
TRandom * GetRandom() {
return fRng;
}
/**
set the seed for the random number generator
*/
void SetSeed(unsigned int seed);
/**
set log level
*/
bool SetLogLevel(unsigned int iflag = 1);
/**
set stream for log and error (not yet implemented)
*/
bool SetLogStream() { return false;}
/**
used Unuran method
*/
const std::string & MethodName() const { return fMethod; }
protected:
bool SetRandomGenerator();
bool SetContDistribution(const TUnuranContDist & dist );
bool SetMultiDistribution(const TUnuranMultiContDist & dist );
bool SetDiscreteDistribution(const TUnuranDiscrDist & dist );
bool SetEmpiricalDistribution(const TUnuranEmpDist & dist );
/**
change the method and initialize Unuran with the previously given distribution
*/
bool SetMethodAndInit();
// private:
UNUR_GEN * fGen; //pointer to the UnuRan C generator struct
UNUR_DISTR * fUdistr; //pointer to the UnuRan C distribution struct
UNUR_URNG * fUrng; // pointer to Unuran C random generator struct
std::auto_ptr<TUnuranBaseDist> fDist; // pointer for distribution wrapper
TRandom * fRng; //pointer to ROOT random number generator
std::string fMethod; //string representing the method
};
#endif /* ROOT_Math_TUnuran */
|