#include #include #include #include #include #include #include #include using std::max; using std::min; using std::string; using std::vector; using std::length_error; using std::logic_error; DistScalar::DistScalar(string const &name, unsigned int npar, Support support, bool canbound, bool discrete) : Distribution(name, npar + 2*canbound, canbound, discrete), _support(support) { } double DistScalar::lowerSupport(unsigned long i, vector const ¶meters) const { if (i != 0) { throw logic_error("Invalid index in Distreal::lowerSupport"); } SArray const *lb = lowerBound(parameters); if (lb) { return max(l(parameters), *lb->value()); } else { return l(parameters); } } double DistScalar::upperSupport(unsigned long i, vector const ¶meters) const { if (i != 0) { throw logic_error("Invalid index in Distreal::upperSupport"); } SArray const *ub = upperBound(parameters); if (ub) { return min(u(parameters), *ub->value()); } else { return u(parameters); } } unsigned long DistScalar::df(vector const ¶meters) const { return 1; } Index const & DistScalar::dim(vector const ¶meters) const { static const Index ScalarIndex(1); return ScalarIndex; } double DistScalar::l(vector const ¶meters) const { switch(_support) { case DIST_UNBOUNDED: return -DBL_MAX; break; case DIST_POSITIVE: case DIST_PROPORTION: return 0; break; case DIST_SPECIAL: //You must overload this function throw logic_error("Cannot call DistScalar::l for special distribution"); } return 0; //Wall } double DistScalar::u(vector const ¶meters) const { switch(_support) { case DIST_UNBOUNDED: case DIST_POSITIVE: return DBL_MAX; break; case DIST_PROPORTION: return 1; break; case DIST_SPECIAL: //You must overload this function throw logic_error("Cannot call DistScalar::u for special distribution"); } return 0; //Wall }