25 #include <queso/FiniteDistribution.h>
33 const std::vector<double>& inpWeights)
36 m_prefix ((std::string)(prefix)+
"fd_"),
37 m_weights(inpWeights.size(),0.)
44 <<
", inpWeights.size() = " << inpWeights.size()
48 unsigned int numOfZeroWeights = 0;
49 unsigned int numRareCases = 0;
53 for (
unsigned int i = 0; i < inpWeights.size(); ++i) {
54 double previousSum = sumCheck;
55 sumCheck += inpWeights[i];
56 if (sumCheck == previousSum) {
60 if ((sumCheck - 1) > 1.e-8) {
61 std::cerr <<
"In FiniteDistribution::constructor()"
62 <<
": sumCheck - 1 = " << sumCheck - 1.
67 if (sumCheck > 1.) sumCheck = 1.;
69 std::pair<std::map<double,unsigned int>::iterator,
bool> ret;
70 ret =
m_map.insert(std::map<double,unsigned int>::value_type(sumCheck,i));
71 if (ret.second ==
true) {
78 <<
": WARNING, map insertion failed"
86 if ((1 - sumCheck) > 1.e-8) {
87 std::cerr <<
"In FiniteDistribution::constructor()"
88 <<
": 1 - sumCheck = " << 1. - sumCheck
96 <<
": inpWeights.size() = " << inpWeights.size()
97 <<
", numOfZeroWeights = " << numOfZeroWeights
98 <<
", numRareCases = " << numRareCases
99 <<
", m_map.size() = " <<
m_map.size()
100 <<
", m_weights.size() = " <<
m_weights.size()
131 const std::vector<double>&
144 unsigned int result = 0;
152 else if (aux == 1.) {
153 result =
m_map.find(aux)->second;
156 result =
m_map.upper_bound(aux)->second;
164 #if 0 // WE insert 'i' in map, not 'j'. So, the tests below don't make sense
165 if (result >=
m_map.size()) {
166 std::cerr <<
"In FiniteDistribution::sample()"
168 <<
", m_map.size() = " <<
m_map.size()
169 <<
", result = " << result
unsigned int displayVerbosity() const
const std::vector< double > & weights() const
Weights.
std::map< double, unsigned int > m_map
const BaseEnvironment & m_env
unsigned int sample() const
Samples.
const BaseEnvironment & env() const
Environment; access to protected attribute m_env.
#define queso_require_less_equal_msg(expr1, expr2, msg)
#define queso_require_equal_to_msg(expr1, expr2, msg)
std::vector< double > m_weights
#define queso_require_msg(asserted, msg)
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
#define queso_require_less_msg(expr1, expr2, msg)
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
virtual ~FiniteDistribution()
Virtual destructor.
#define queso_deprecated()
const RngBase * rngObject() const
Access to the RNG object.
FiniteDistribution(const BaseEnvironment &env, const char *prefix, const std::vector< double > &inpWeights)
Constructor.
virtual double uniformSample() const =0
Samples a value from a uniform distribution.