42 #ifndef BPP_NUMERIC_RANDOM_RANDOMTOOLS_H
43 #define BPP_NUMERIC_RANDOM_RANDOMTOOLS_H
46 #include "../../Exceptions.h"
47 #include "../VectorExceptions.h"
48 #include "../VectorTools.h"
122 template<
class intType>
133 static void setSeed(
long seed);
188 static T
pickOne(std::vector<T>& v,
bool replace =
false)
192 size_t pos = RandomTools::giveIntRandomNumberBetweenZeroAndEntry<size_t>(v.size());
218 size_t pos = RandomTools::giveIntRandomNumberBetweenZeroAndEntry<size_t>(v.size());
240 static void getSample(
const std::vector<T>& vin, std::vector<T>& vout,
bool replace =
false)
242 if (vout.size() > vin.size() && !replace)
246 for (
size_t i = 0; i < vout.size(); i++)
251 std::vector<size_t> hat(vin.size());
252 std::iota(hat.begin(), hat.end(), 0);
253 std::random_shuffle(hat.begin(), hat.end());
254 for (
size_t i = 0; i < vout.size(); i++)
255 vout[i] = vin[hat[i]];
275 static T
pickOne(std::vector<T>& v, std::vector<double>& w,
bool replace =
false)
285 size_t pos = v.size() - 1;
286 for (
size_t i = 0; i < v.size(); ++i)
321 static T
pickOne(
const std::vector<T>& v,
const std::vector<double>& w)
331 size_t pos = v.size() - 1;
332 for (
size_t i = 0; i < v.size(); ++i)
358 while (pos < w.size() - 1)
393 static void getSample(
const std::vector<T>& vin,
const std::vector<double>& w, std::vector<T>& vout,
bool replace =
false)
395 if (vout.size() > vin.size() && !replace)
396 throw IndexOutOfBoundsException(
"RandomTools::getSample (with weights): size exceeded v.size.", vout.size(), 0, vin.size());
397 std::vector<size_t> hat(vin.size());
398 std::iota(hat.begin(), hat.end(), 0);
401 for (
size_t i = 0; i < vout.size(); i++)
402 vout[i] = vin[
pickOne(hat, w)];
406 std::vector<double> w2(w);
407 for (
size_t i = 0; i < vout.size(); i++)
409 vout[i] = vin[
pickOne(hat, w2,
false)];
424 static std::vector<size_t>
randMultinomial(
size_t n,
const std::vector<double>& probs);
451 static double qNorm(
double prob);
472 static double qNorm(
double prob,
double mu,
double sigma);
480 static double lnGamma(
double alpha) {
return std::lgamma(alpha); }
498 static double incompleteGamma(
double x,
double alpha,
double ln_gamma_alpha);
515 static double qChisq(
double prob,
double v);
527 return pGamma(x, v / 2, 0.5);
538 static double qGamma(
double prob,
double alpha,
double beta)
540 return qChisq(prob, 2.0 * (alpha)) / (2.0 * (beta));
553 static double pGamma(
double x,
double alpha,
double beta)
555 if (alpha < 0)
throw Exception(
"RandomTools::pGamma. Negative alpha is not allowed.");
556 if (beta < 0)
throw Exception(
"RandomTools::pGamma. Negative beta is not allowed.");
557 if (alpha == 0.)
return 1.;
583 static double pNorm(
double z);
595 static double pNorm(
double z,
double mu,
double sigma);
607 static double lnBeta(
double alpha,
double beta);
622 static double incompleteBeta(
double x,
double alpha,
double beta);
623 static double pBeta(
double x,
double alpha,
double beta)
641 static double qBeta(
double prob,
double alpha,
double beta);
Exception thrown when an empty vector was found.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Index out of bounds exception class.
This is the interface for the Random Number Generators.