KrisLibrary  1.0.0
sample.h
Go to the documentation of this file.
1 #ifndef MATH_SAMPLE_H
2 #define MATH_SAMPLE_H
3 
4 #include <vector>
5 
10 namespace Math {
13  struct Interval;
14  struct ClosedIntervalSet;
15 
21 int WeightedSample(const std::vector<Real>& weights);
23 int WeightedSample(const std::vector<Real>& weights,Real totWeight);
26 int CumulativeWeightedSample(const std::vector<Real>& partialSumWeights);
27 
35 void RandomAllocate(std::vector<int>& num,size_t total);
37 void RandomAllocate(std::vector<int>& num,size_t total,const std::vector<Real>& weights);
38 
40 Real Sample(const Interval& s);
42 Real Sample(const ClosedIntervalSet& s);
43 
45 void SampleCircle(Real r, Real& x, Real& y);
47 void SampleDisk(Real r, Real& x, Real& y);
48 
50 void SampleTriangle(Real& x, Real& y);
51 
53 void SampleBall(Real r, Real& x, Real& y, Real& z);
55 void SampleSphere(Real r, Real& x, Real& y, Real& z);
56 
58 void SampleHyperBall(Real r,std::vector<Real>& v);
60 void SampleHyperSphere(Real r,std::vector<Real>& v);
61 
62 } //namespace Math
65 #endif
void SampleHyperBall(Real r, std::vector< Real > &v)
Uniformly samples from a hyper-ball of dimension v.size()
Definition: sample.cpp:215
Real Sample(const Interval &s)
Uniformly samples the given intervals.
Definition: sample.cpp:116
void SampleBall(Real r, Real &x, Real &y, Real &z)
Uniform distribution on boundary of a sphere with radius r.
Definition: sample.cpp:189
void SampleSphere(Real r, Real &x, Real &y, Real &z)
Uniform distribution inside a sphere with radius r.
Definition: sample.cpp:179
void SampleTriangle(Real &x, Real &y)
Uniform distribution in the triangle whose vertices are (0,0),(1,0),(0,1)
Definition: sample.cpp:167
void SampleHyperSphere(Real r, std::vector< Real > &v)
Uniformly samples from a hyper-sphere of dimension v.size()
Definition: sample.cpp:198
int CumulativeWeightedSample(const std::vector< Real > &partialSumWeights)
Definition: sample.cpp:33
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
void SampleDisk(Real r, Real &x, Real &y)
Uniform distribution inside a circle with radius r.
Definition: sample.cpp:159
void SampleCircle(Real r, Real &x, Real &y)
Uniform distribution on boundary of a circle with radius r.
Definition: sample.cpp:152
void RandomAllocate(vector< int > &num, size_t total)
allocates total samples within the buckets in num, roughly evenly
Definition: sample.cpp:41
int WeightedSample(const vector< Real > &weights)
Samples an integer with weighted probability.
Definition: sample.cpp:13