|
|
| 95 |
virtual double GetValue() = 0; |
95 |
virtual double GetValue() = 0; |
| 96 |
virtual uint32_t GetInteger(); |
96 |
virtual uint32_t GetInteger(); |
| 97 |
virtual RandomVariableBase* Copy(void) const = 0; |
97 |
virtual RandomVariableBase* Copy(void) const = 0; |
|
|
98 |
virtual void SerializeTo (std::ostream &os) const = 0; |
| 98 |
|
99 |
|
| 99 |
protected: |
100 |
protected: |
| 100 |
RngStream* m_generator; //underlying generator being wrapped |
101 |
RngStream* m_generator; //underlying generator being wrapped |
|
|
| 207 |
virtual double GetValue(double s, double l); |
208 |
virtual double GetValue(double s, double l); |
| 208 |
|
209 |
|
| 209 |
virtual RandomVariableBase* Copy(void) const; |
210 |
virtual RandomVariableBase* Copy(void) const; |
|
|
211 |
virtual void SerializeTo (std::ostream &os) const; |
| 210 |
|
212 |
|
| 211 |
private: |
213 |
private: |
| 212 |
double m_min; |
214 |
double m_min; |
|
|
| 257 |
return new UniformVariableImpl(*this); |
259 |
return new UniformVariableImpl(*this); |
| 258 |
} |
260 |
} |
| 259 |
|
261 |
|
|
|
262 |
void UniformVariableImpl::SerializeTo (std::ostream& os) const |
| 263 |
{ |
| 264 |
os << "Uniform:" << GetMin () << ":" << GetMax (); |
| 265 |
} |
| 266 |
|
| 260 |
UniformVariable::UniformVariable() |
267 |
UniformVariable::UniformVariable() |
| 261 |
: RandomVariable (UniformVariableImpl ()) |
268 |
: RandomVariable (UniformVariableImpl ()) |
| 262 |
{} |
269 |
{} |
|
|
| 309 |
virtual double GetValue(); |
316 |
virtual double GetValue(); |
| 310 |
virtual uint32_t GetInteger(); |
317 |
virtual uint32_t GetInteger(); |
| 311 |
virtual RandomVariableBase* Copy(void) const; |
318 |
virtual RandomVariableBase* Copy(void) const; |
|
|
319 |
virtual void SerializeTo (std::ostream& os) const; |
| 312 |
private: |
320 |
private: |
| 313 |
double m_const; |
321 |
double m_const; |
| 314 |
}; |
322 |
}; |
|
|
| 338 |
RandomVariableBase* ConstantVariableImpl::Copy() const |
346 |
RandomVariableBase* ConstantVariableImpl::Copy() const |
| 339 |
{ |
347 |
{ |
| 340 |
return new ConstantVariableImpl(*this); |
348 |
return new ConstantVariableImpl(*this); |
|
|
349 |
} |
| 350 |
|
| 351 |
void ConstantVariableImpl::SerializeTo (std::ostream& os) const |
| 352 |
{ |
| 353 |
os << "Constant:" << m_const; |
| 341 |
} |
354 |
} |
| 342 |
|
355 |
|
| 343 |
ConstantVariable::ConstantVariable() |
356 |
ConstantVariable::ConstantVariable() |
|
|
| 393 |
*/ |
406 |
*/ |
| 394 |
virtual double GetValue(); |
407 |
virtual double GetValue(); |
| 395 |
virtual RandomVariableBase* Copy(void) const; |
408 |
virtual RandomVariableBase* Copy(void) const; |
|
|
409 |
virtual void SerializeTo (std::ostream& os) const; |
| 396 |
private: |
410 |
private: |
| 397 |
double m_min; |
411 |
double m_min; |
| 398 |
double m_max; |
412 |
double m_max; |
|
|
| 439 |
return new SequentialVariableImpl(*this); |
453 |
return new SequentialVariableImpl(*this); |
| 440 |
} |
454 |
} |
| 441 |
|
455 |
|
|
|
456 |
void SequentialVariableImpl::SerializeTo (std::ostream& os) const |
| 457 |
{ |
| 458 |
// XXX: support other distributions |
| 459 |
os.setstate (std::ios_base::badbit); |
| 460 |
} |
| 461 |
|
| 442 |
SequentialVariable::SequentialVariable(double f, double l, double i, uint32_t c) |
462 |
SequentialVariable::SequentialVariable(double f, double l, double i, uint32_t c) |
| 443 |
: RandomVariable (SequentialVariableImpl (f, l, i, c)) |
463 |
: RandomVariable (SequentialVariableImpl (f, l, i, c)) |
| 444 |
{} |
464 |
{} |
|
|
| 484 |
*/ |
504 |
*/ |
| 485 |
virtual double GetValue(); |
505 |
virtual double GetValue(); |
| 486 |
virtual RandomVariableBase* Copy(void) const; |
506 |
virtual RandomVariableBase* Copy(void) const; |
|
|
507 |
virtual void SerializeTo (std::ostream& os) const; |
| 487 |
|
508 |
|
| 488 |
private: |
509 |
private: |
| 489 |
double m_mean; // Mean value of RV |
510 |
double m_mean; // Mean value of RV |
|
|
| 519 |
RandomVariableBase* ExponentialVariableImpl::Copy() const |
540 |
RandomVariableBase* ExponentialVariableImpl::Copy() const |
| 520 |
{ |
541 |
{ |
| 521 |
return new ExponentialVariableImpl(*this); |
542 |
return new ExponentialVariableImpl(*this); |
|
|
543 |
} |
| 544 |
|
| 545 |
void ExponentialVariableImpl::SerializeTo (std::ostream& os) const |
| 546 |
{ |
| 547 |
// XXX: support other distributions |
| 548 |
os.setstate (std::ios_base::badbit); |
| 522 |
} |
549 |
} |
| 523 |
|
550 |
|
| 524 |
ExponentialVariable::ExponentialVariable() |
551 |
ExponentialVariable::ExponentialVariable() |
|
|
| 578 |
*/ |
605 |
*/ |
| 579 |
virtual double GetValue(); |
606 |
virtual double GetValue(); |
| 580 |
virtual RandomVariableBase* Copy() const; |
607 |
virtual RandomVariableBase* Copy() const; |
|
|
608 |
virtual void SerializeTo (std::ostream& os) const; |
| 581 |
|
609 |
|
| 582 |
private: |
610 |
private: |
| 583 |
double m_mean; // Mean value of RV |
611 |
double m_mean; // Mean value of RV |
|
|
| 621 |
return new ParetoVariableImpl(*this); |
649 |
return new ParetoVariableImpl(*this); |
| 622 |
} |
650 |
} |
| 623 |
|
651 |
|
|
|
652 |
void ParetoVariableImpl::SerializeTo (std::ostream& os) const |
| 653 |
{ |
| 654 |
// XXX: support other distributions |
| 655 |
os.setstate (std::ios_base::badbit); |
| 656 |
} |
| 657 |
|
| 624 |
ParetoVariable::ParetoVariable () |
658 |
ParetoVariable::ParetoVariable () |
| 625 |
: RandomVariable (ParetoVariableImpl ()) |
659 |
: RandomVariable (ParetoVariableImpl ()) |
| 626 |
{} |
660 |
{} |
|
|
| 682 |
*/ |
716 |
*/ |
| 683 |
virtual double GetValue(); |
717 |
virtual double GetValue(); |
| 684 |
virtual RandomVariableBase* Copy(void) const; |
718 |
virtual RandomVariableBase* Copy(void) const; |
|
|
719 |
virtual void SerializeTo (std::ostream& os) const; |
| 685 |
|
720 |
|
| 686 |
private: |
721 |
private: |
| 687 |
double m_mean; // Mean value of RV |
722 |
double m_mean; // Mean value of RV |
|
|
| 720 |
return new WeibullVariableImpl(*this); |
755 |
return new WeibullVariableImpl(*this); |
| 721 |
} |
756 |
} |
| 722 |
|
757 |
|
|
|
758 |
void WeibullVariableImpl::SerializeTo (std::ostream& os) const |
| 759 |
{ |
| 760 |
// XXX: support other distributions |
| 761 |
os.setstate (std::ios_base::badbit); |
| 762 |
} |
| 763 |
|
| 723 |
WeibullVariable::WeibullVariable() |
764 |
WeibullVariable::WeibullVariable() |
| 724 |
: RandomVariable (WeibullVariableImpl ()) |
765 |
: RandomVariable (WeibullVariableImpl ()) |
| 725 |
{} |
766 |
{} |
|
|
| 762 |
*/ |
803 |
*/ |
| 763 |
virtual double GetValue(); |
804 |
virtual double GetValue(); |
| 764 |
virtual RandomVariableBase* Copy(void) const; |
805 |
virtual RandomVariableBase* Copy(void) const; |
|
|
806 |
virtual void SerializeTo (std::ostream& os) const; |
| 765 |
|
807 |
|
| 766 |
double GetMean (void) const; |
808 |
double GetMean (void) const; |
| 767 |
double GetVariance (void) const; |
809 |
double GetVariance (void) const; |
|
|
| 839 |
return new NormalVariableImpl(*this); |
881 |
return new NormalVariableImpl(*this); |
| 840 |
} |
882 |
} |
| 841 |
|
883 |
|
|
|
884 |
void NormalVariableImpl::SerializeTo (std::ostream& os) const |
| 885 |
{ |
| 886 |
os << "Normal:" << GetMean () << ":" << GetVariance (); |
| 887 |
double bound = GetBound (); |
| 888 |
if (bound != NormalVariableImpl::INFINITE_VALUE) |
| 889 |
{ |
| 890 |
os << ":" << bound; |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 842 |
double |
894 |
double |
| 843 |
NormalVariableImpl::GetMean (void) const |
895 |
NormalVariableImpl::GetMean (void) const |
| 844 |
{ |
896 |
{ |
|
|
| 883 |
*/ |
935 |
*/ |
| 884 |
virtual double GetValue(); |
936 |
virtual double GetValue(); |
| 885 |
virtual RandomVariableBase* Copy(void) const; |
937 |
virtual RandomVariableBase* Copy(void) const; |
|
|
938 |
virtual void SerializeTo (std::ostream& os) const; |
| 886 |
/** |
939 |
/** |
| 887 |
* \brief Specifies a point in the empirical distribution |
940 |
* \brief Specifies a point in the empirical distribution |
| 888 |
* \param v The function value for this point |
941 |
* \param v The function value for this point |
|
|
| 978 |
return new EmpiricalVariableImpl(*this); |
1031 |
return new EmpiricalVariableImpl(*this); |
| 979 |
} |
1032 |
} |
| 980 |
|
1033 |
|
|
|
1034 |
void EmpiricalVariableImpl::SerializeTo (std::ostream& os) const |
| 1035 |
{ |
| 1036 |
// XXX: support other distributions |
| 1037 |
os.setstate (std::ios_base::badbit); |
| 1038 |
} |
| 1039 |
|
| 981 |
void EmpiricalVariableImpl::CDF(double v, double c) |
1040 |
void EmpiricalVariableImpl::CDF(double v, double c) |
| 982 |
{ // Add a new empirical datapoint to the empirical cdf |
1041 |
{ // Add a new empirical datapoint to the empirical cdf |
| 983 |
// NOTE. These MUST be inserted in non-decreasing order |
1042 |
// NOTE. These MUST be inserted in non-decreasing order |
|
|
| 1034 |
IntEmpiricalVariableImpl(); |
1093 |
IntEmpiricalVariableImpl(); |
| 1035 |
|
1094 |
|
| 1036 |
virtual RandomVariableBase* Copy(void) const; |
1095 |
virtual RandomVariableBase* Copy(void) const; |
|
|
1096 |
virtual void SerializeTo (std::ostream& os) const; |
| 1037 |
/** |
1097 |
/** |
| 1038 |
* \return An integer value from this empirical distribution |
1098 |
* \return An integer value from this empirical distribution |
| 1039 |
*/ |
1099 |
*/ |
|
|
| 1053 |
RandomVariableBase* IntEmpiricalVariableImpl::Copy() const |
1113 |
RandomVariableBase* IntEmpiricalVariableImpl::Copy() const |
| 1054 |
{ |
1114 |
{ |
| 1055 |
return new IntEmpiricalVariableImpl(*this); |
1115 |
return new IntEmpiricalVariableImpl(*this); |
|
|
1116 |
} |
| 1117 |
|
| 1118 |
void IntEmpiricalVariableImpl::SerializeTo (std::ostream& os) const |
| 1119 |
{ |
| 1120 |
// XXX: support other distributions |
| 1121 |
os.setstate (std::ios_base::badbit); |
| 1056 |
} |
1122 |
} |
| 1057 |
|
1123 |
|
| 1058 |
double IntEmpiricalVariableImpl::Interpolate(double c1, double c2, |
1124 |
double IntEmpiricalVariableImpl::Interpolate(double c1, double c2, |
|
|
| 1091 |
*/ |
1157 |
*/ |
| 1092 |
virtual double GetValue(); |
1158 |
virtual double GetValue(); |
| 1093 |
virtual RandomVariableBase* Copy(void) const; |
1159 |
virtual RandomVariableBase* Copy(void) const; |
|
|
1160 |
virtual void SerializeTo (std::ostream& os) const; |
| 1094 |
private: |
1161 |
private: |
| 1095 |
uint32_t count; |
1162 |
uint32_t count; |
| 1096 |
uint32_t next; |
1163 |
uint32_t next; |
|
|
| 1118 |
return new DeterministicVariableImpl(*this); |
1185 |
return new DeterministicVariableImpl(*this); |
| 1119 |
} |
1186 |
} |
| 1120 |
|
1187 |
|
|
|
1188 |
void DeterministicVariableImpl::SerializeTo (std::ostream& os) const |
| 1189 |
{ |
| 1190 |
// XXX: support other distributions |
| 1191 |
os.setstate (std::ios_base::badbit); |
| 1192 |
} |
| 1193 |
|
| 1121 |
DeterministicVariable::DeterministicVariable(double* d, uint32_t c) |
1194 |
DeterministicVariable::DeterministicVariable(double* d, uint32_t c) |
| 1122 |
: RandomVariable (DeterministicVariableImpl (d, c)) |
1195 |
: RandomVariable (DeterministicVariableImpl (d, c)) |
| 1123 |
{} |
1196 |
{} |
|
|
| 1138 |
*/ |
1211 |
*/ |
| 1139 |
virtual double GetValue (); |
1212 |
virtual double GetValue (); |
| 1140 |
virtual RandomVariableBase* Copy(void) const; |
1213 |
virtual RandomVariableBase* Copy(void) const; |
|
|
1214 |
virtual void SerializeTo (std::ostream& os) const; |
| 1141 |
|
1215 |
|
| 1142 |
private: |
1216 |
private: |
| 1143 |
double m_mu; |
1217 |
double m_mu; |
|
|
| 1148 |
RandomVariableBase* LogNormalVariableImpl::Copy () const |
1222 |
RandomVariableBase* LogNormalVariableImpl::Copy () const |
| 1149 |
{ |
1223 |
{ |
| 1150 |
return new LogNormalVariableImpl (m_mu, m_sigma); |
1224 |
return new LogNormalVariableImpl (m_mu, m_sigma); |
|
|
1225 |
} |
| 1226 |
|
| 1227 |
void LogNormalVariableImpl::SerializeTo (std::ostream& os) const |
| 1228 |
{ |
| 1229 |
// XXX: support other distributions |
| 1230 |
os.setstate (std::ios_base::badbit); |
| 1151 |
} |
1231 |
} |
| 1152 |
|
1232 |
|
| 1153 |
LogNormalVariableImpl::LogNormalVariableImpl (double mu, double sigma) |
1233 |
LogNormalVariableImpl::LogNormalVariableImpl (double mu, double sigma) |
|
|
| 1240 |
*/ |
1320 |
*/ |
| 1241 |
virtual double GetValue(); |
1321 |
virtual double GetValue(); |
| 1242 |
virtual RandomVariableBase* Copy(void) const; |
1322 |
virtual RandomVariableBase* Copy(void) const; |
|
|
1323 |
virtual void SerializeTo (std::ostream& os) const; |
| 1243 |
|
1324 |
|
| 1244 |
private: |
1325 |
private: |
| 1245 |
double m_min; |
1326 |
double m_min; |
|
|
| 1279 |
return new TriangularVariableImpl(*this); |
1360 |
return new TriangularVariableImpl(*this); |
| 1280 |
} |
1361 |
} |
| 1281 |
|
1362 |
|
|
|
1363 |
void TriangularVariableImpl::SerializeTo (std::ostream& os) const |
| 1364 |
{ |
| 1365 |
// XXX: support other distributions |
| 1366 |
os.setstate (std::ios_base::badbit); |
| 1367 |
} |
| 1368 |
|
| 1282 |
TriangularVariable::TriangularVariable() |
1369 |
TriangularVariable::TriangularVariable() |
| 1283 |
: RandomVariable (TriangularVariableImpl ()) |
1370 |
: RandomVariable (TriangularVariableImpl ()) |
| 1284 |
{} |
1371 |
{} |
|
|
| 1290 |
std::ostream &operator << (std::ostream &os, const RandomVariable &var) |
1377 |
std::ostream &operator << (std::ostream &os, const RandomVariable &var) |
| 1291 |
{ |
1378 |
{ |
| 1292 |
RandomVariableBase *base = var.Peek (); |
1379 |
RandomVariableBase *base = var.Peek (); |
| 1293 |
ConstantVariableImpl *constant = dynamic_cast<ConstantVariableImpl *> (base); |
1380 |
base->SerializeTo (os); |
| 1294 |
if (constant != 0) |
|
|
| 1295 |
{ |
| 1296 |
os << "Constant:" << constant->GetValue (); |
| 1297 |
return os; |
| 1298 |
} |
| 1299 |
UniformVariableImpl *uniform = dynamic_cast<UniformVariableImpl *> (base); |
| 1300 |
if (uniform != 0) |
| 1301 |
{ |
| 1302 |
os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax (); |
| 1303 |
return os; |
| 1304 |
} |
| 1305 |
NormalVariableImpl *normal = dynamic_cast<NormalVariableImpl *> (base); |
| 1306 |
if (normal != 0) |
| 1307 |
{ |
| 1308 |
os << "Normal:" << normal->GetMean () << ":" << normal->GetVariance (); |
| 1309 |
double bound = normal->GetBound (); |
| 1310 |
if (bound != NormalVariableImpl::INFINITE_VALUE) |
| 1311 |
{ |
| 1312 |
os << ":" << bound; |
| 1313 |
} |
| 1314 |
return os; |
| 1315 |
} |
| 1316 |
// XXX: support other distributions |
| 1317 |
os.setstate (std::ios_base::badbit); |
| 1318 |
return os; |
1381 |
return os; |
| 1319 |
} |
1382 |
} |
| 1320 |
std::istream &operator >> (std::istream &is, RandomVariable &var) |
1383 |
std::istream &operator >> (std::istream &is, RandomVariable &var) |