#include #include #include #include #include #include using std::vector; using std::fabs; using std::runtime_error; using std::logic_error; static inline double SUM(vector const &par) { return *par[0]->value() + *par[1]->value(); } DSum::DSum() : Distribution("dsum", 2, false, true) { } DSum::~DSum() {} bool DSum::checkParameterValue(vector const &par) const { return true; } bool DSum::checkParameterDim(vector const &par) const { for (unsigned int i = 0; i < 2; ++i) { if (par[i]->length() != 1 || !par[i]->isDiscreteValued()) return false; } return true; } Index const &DSum::dim(vector const &par) const { static const Index ScalarIndex(1); return ScalarIndex; } double DSum::logLikelihood(SArray const &x, vector const &par) const { if (fabs(*x.value() - SUM(par)) > 16*DBL_EPSILON) { // If this happens by accident, you have no chance of getting it right throw runtime_error("Inconsistent arguments for dsum"); } return 0; } void DSum::randomSample(SArray &x, vector const &par) const { // The random sample from DSum is not random at all, but // deterministic. x.setValue(SUM(par), 0); } unsigned long DSum::df(std::vector const &par) const { return 0; } double DSum::lowerSupport(unsigned long i, std::vector const &par) const { if (i != 0) throw logic_error("Invalid index in DSum::lowerSupport"); return SUM(par); } double DSum::upperSupport(unsigned long i, std::vector const &par) const { if (i != 0) throw logic_error("Invalid index in DSum::upperSupport"); return SUM(par); }