## [ff1121]: src / include / distribution / Distribution.h  Maximize  Restore  History

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154``` ```#ifndef DISTRIBUTION_H_ #define DISTRIBUTION_H_ #include #include namespace jags { struct RNG; /** * Specifies different ways of calculating the log probability density * function. Typically we are only interested in calculating ratios of * probability density functions. When some terms in the log density * are constant (and therefore cancel out when taking ratios) they may * optionally be omitted from the calculations for improved * efficiency. * * PDF_FULL is used when neither the sampled values nor the * pararameters are constant. This implies full evaluation of the log * density. * * PDF_PRIOR is used when the parameters are constant. Terms that * depend only on the parameters may be omitted from the log density. * * PDF_LIKELIHOOD is used when the sampled value is constant. Terms * that depend only on the sampled value may be omitted from the log * density. * * Note that any function taking a PDFType argument is free to ignore * it and can always calculate the full density function. */ enum PDFType {PDF_FULL, PDF_PRIOR, PDF_LIKELIHOOD}; /** * @short Distribution of a random variable * * Distribution objects contain only constant data members and all * member functions are constant. Hence only one object needs to be * instantiated for each subclass. * * The DistTab class provides a convenient way of storing Distribution * objects and referencing them by name. * * @see DistTab */ class Distribution { const std::string _name; const unsigned int _npar; public: /** * Constructor. * @param name name of the distribution as used in the BUGS language * @param npar number of parameters, excluding upper and lower bounds */ Distribution(std::string const &name, unsigned int npar); virtual ~Distribution(); /** * @returns the BUGS language name of the distribution */ std::string const &name() const; /** * Returns an alternate name for the distribution. The default * implementation returns an empty string. However, this function * may be overridden to return a non-empty string giving an * alternate name for the distribution. */ virtual std::string alias() const; /** * Indicates whether the support of the distribution is fixed. * * @param fixmask Boolean vector indicating which parameters have * fixed values. */ virtual bool isSupportFixed(std::vector const &fixmask) const = 0; /** * Returns the number of parameters of the distribution */ unsigned int npar() const; /** * Some distributions require some of the parameters to be discrete * valued. As most distributions do not require discrete valued paremeters, * a default implementation is provided which always returns true. * * @param mask Boolean vector indicating which parameters are * discrete valued. */ virtual bool checkParameterDiscrete(std::vector const &mask) const; /** * Returns true if the distribution has support on the integers.The * default implementation returns false, so this must be overridden * for discrete-valued distributions. * * @param mask Vector indicating whether parameters are discrete * or not. Most implementations will ignore this argument, as a * distribution normally has support either on the real line or on * the integers. However, this argument is required in order to * support observable functions, for which the support may depend * on the arguments. * * @see Function#isDiscreteValued */ virtual bool isDiscreteValued(std::vector const &mask) const; /** * Tests for a location parameter. A parameter of a distribution * is considered to be a location parameter if, when it's value is * incremented by X, the whole distribution is shifted by X, * indpendently of the other parameter values. * * This is a virtual function, for which the default implementation * always returns false. Distributions with location parameters must * overload this function. * * @param index Index number (starting from 0) of the parameter to be * tested. */ virtual bool isLocationParameter(unsigned int index) const; /** * Tests for a scale parameter. A parameter of a distribution is * considered to be a scale parameter if, when it's value is * multiplied by X, the whole distribution multiplied by X, * indpendently of the other parameter values. * * Note that this definition excludes "location-scale" models: * i.e. if the density of y takes the form (1/b)*f((y-a)/b) then b * is not considered a scale parameter. * * This is a virtual function, for which the default * implementation always returns false. Distributions with scale * parameters must overload this function. * * @param index Index number (starting from 0) of the parameter to * be tested. */ virtual bool isScaleParameter(unsigned int index) const; /** * Indicates whether the distribution can be bounded. The default * implementation returns false. */ virtual bool canBound() const; }; /** * Checks that the distribution accepts npar parameters */ inline bool checkNPar(Distribution const *dist, unsigned int npar) { return (dist->npar() == 0 && npar > 0) || dist->npar() == npar; } } /* namespace jags */ #endif /* DISTRIBUTION_H_ */ ```