24 typedef typename Real_::DoubleType Double_;
56 if (list.size() == 0) { sample.clear();
return; }
58 for (
szt i = 0; i < count; ++i)
64 void choose(
const vector<T>& list,
szt count, vector<T>& chosen, vector<szt>& unchosen)
const
67 if (chosenSize == 0) { chosen.clear(); unchosen.clear();
return; }
70 unchosen.resize(list.size());
71 for (
szt i = 0; i < unchosen.size(); ++i) unchosen[i] = i;
74 chosen.resize(chosenSize);
75 for (
szt i = 0; i < chosenSize; ++i)
79 chosen[i] = list[unchosen[index]];
80 unchosen.erase(unchosen.begin() + index);
89 for (
szt i = list.size() - 1; i > 0; --i)
103 template<
class Range>
104 static tuple<Real,Real,Real>
mean(
const Range& samples)
106 auto res =
reduce(samples, make_tuple(
Real(0), Real_::inf, -Real_::inf),
107 [](tuple<Real,Real,Real> a,
Real e) {
return make_tuple(get<0>(a) + e,
Alge::min(get<1>(a), e),
Alge::max(get<2>(a), e)); });
108 szt n = end(samples) - begin(samples);
109 get<0>(res) = n > 0 ? get<0>(res) / n : 0;
114 template<
class Range>
118 szt n = end(samples) - begin(samples);
119 return n > 1 ? sumDev / (n-1) : 0;
140 <<
"N: " << val.
n <<
endl
145 <<
"Std Err: " << val.
stdErr
151 template<
class Range>
155 d.
n = end(samples) - begin(samples);
Algebra.
Definition: Alge.h:13
void setGen(RandomGen &gen)
Set random generator to use for all methods.
Definition: Random.h:45
static Real variance(const Range &samples, Real mean)
Estimate the sample variance given the mean. This is the unbiased estimator (mean over all possible s...
Definition: Random.h:115
Random number generator interface.
Definition: Gen.h:11
Interpolation math.
Definition: Quat.h:10
void shuffle(vector< T > &list) const
Randomly permute a list. The entire list will be shuffled into a random order. All permutations have ...
Definition: Random.h:86
Accum reduce(Range &&, Seqs &&..., Accum &&initVal, Func &&)
Accumulate a series of sequences into an output.
static Real sqrt(Real x)
Square Root.
Definition: Alge.h:63
static std::common_type< Num, Num2 >::type max(Num a, Num2 b)
Get the maximum of two numbers.
Definition: Alge.h:94
Vec2 dir2d() const
Generate a 2D random unit direction.
Definition: Random.cpp:58
Random_< Real > Random
Definition: Random.h:166
Real min
Minimum sample value.
Definition: Random.h:132
static std::common_type< Num, Num2 >::type min(Num a, Num2 b)
Get the minimum of two numbers.
Definition: Alge.h:89
Real stdDev
Sample standard deviation.
Definition: Random.h:134
ostream & indentInc(ostream &os)
Increase stream indent level by 1.
Definition: Stream.h:32
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
ostream & indentDec(ostream &os)
Decrease stream indent level by 1.
Definition: Stream.h:34
String of bytes.
Definition: Bytes.h:26
bool boolean() const
Generate random bool true/false.
Definition: Random.h:50
szt n
Sample size.
Definition: Random.h:130
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
Real stdErr
Standard error of the mean (ie. standard deviation of the sample-mean estimate of the population mean...
Definition: Random.h:135
Discrete_< int64 > Discrete_d
Definition: Discrete.h:52
static Real stdErr(Real sampleSize, Real stddev)
Calculate the standard error of the mean. This is how well the sample mean appoximates the population...
Definition: Random.h:126
Random_< Double > Random_d
Definition: Random.h:168
Real max
Maximum sample value.
Definition: Random.h:133
static DistStats stats(const Range &samples)
Calculate distribution statistics.
Definition: Random.h:152
double Real
Definition: Real.h:14
Vec3 dir() const
Generate a random unit direction.
Definition: Random.cpp:9
static Num sqr(Num x)
Square.
Definition: Alge.h:60
friend ostream & operator<<(ostream &os, const DistStats &val)
Definition: Random.h:137
Random_(RandomGen &gen)
Construct with random generator to use for all methods.
Definition: Random.h:42
Real mean
Sample mean.
Definition: Random.h:131
Bytes deviceEntropy(szt count)
Retrieve count bytes of entropy from the host device.
Definition: Random.h:16
Random_()
Definition: Random.h:40
Generate random integer variate between min and max inclusive with uniform (flat) distribution...
Definition: Discrete.h:20
Random-related methods.
Definition: Random.h:21
static Real stdDev(Real variance)
Calculate the standard deviation given the variance.
Definition: Random.h:123
void sample(const vector< T > &list, szt count, vector< T > &sample) const
Randomly choose count items from the list with replacement, so an item can be sampled more than once...
Definition: Random.h:54
void choose(const vector< T > &list, szt count, vector< T > &chosen, vector< szt > &unchosen) const
Randomly choose count items from a list without replacement, so an item can't be chosen more than onc...
Definition: Random.h:64
RandomGen & getGen() const
Get random generator.
Definition: Random.h:47
Generate a normally (Gaussian) distributed random variate.
Definition: Gaussian.h:26
static tuple< Real, Real, Real > mean(const Range &samples)
Estimate the sample mean, returns a tuple of (mean, min, max)
Definition: Random.h:104
ostream & endl(ostream &os)
End line and apply any indentation to the next line.
Definition: Stream.h:40
Global Honeycomb namespace.
Random_< Float > Random_f
Definition: Random.h:167