/usr/include/JAGS/distribution/VectorDist.h is in jags 4.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #ifndef VECTOR_DIST_H_
#define VECTOR_DIST_H_
#include <distribution/Distribution.h>
#include <vector>
#include <string>
namespace jags {
struct RNG;
/**
* @short Vector-valued Distribution
*
* The VectorDist class represents distributions for which either the
* value or the parameters are vectors.
*/
class VectorDist : public Distribution
{
public:
/**
* Constructor.
* @param name name of the distribution as used in the BUGS language
* @param npar number of parameters, excluding upper and lower bounds
*/
VectorDist(std::string const &name, unsigned int npar);
/**
* @param x Value at which to evaluate the density.
*
* @param length Size of the array x.
*
* @param type Indicates whether the full probability density
* function is required (PDF_FULL) or whether partial calculations
* are permitted (PDF_PRIOR, PDF_LIKELIHOOD). See PDFType for
* details.
*
* @param parameters Vector of parameter values of the
* distribution.
*
* @param lengths Vector of parameter lengths corresponding to the
* parameter vector.
*
* @returns the log probability density. If the density should be
* zero because x is inconsistent with the parameters then -Inf is
* returned. If the parameters are invalid
* (i.e. checkParameterValue returns false), then the return value
* is undefined.
*
*/
virtual double
logDensity(double const *x, unsigned int length, PDFType type,
std::vector<double const *> const ¶meters,
std::vector<unsigned int> const &lengths,
double const *lbound, double const *ubound) const = 0;
/**
* Draws a random sample from the distribution.
*
* @param x Array to which the sample values are written
*
* @param length Size of the array x.
*
* @param parameters Vector of parameter values at which
* to evaluate the likelihood. This vector should be of length
* npar().
*
* @param lengths Vector of lengths of the arrays in the argument
* "parameters".
*
* @param rng pseudo-random number generator to use.
*
* @exception length_error
*/
virtual void randomSample(double *x, unsigned int length,
std::vector<double const *> const ¶meters,
std::vector<unsigned int> const &lengths,
double const *lbound, double const *ubound,
RNG *rng) const = 0;
/**
* Returns a typical value from the distribution. The meaning of
* this will depend on the distribution, but it will normally be a
* mean, median or mode.
*
* @param x Array to which the sample values are written
*
* @param length Size of the array x.
*
* @param parameters Vector of parameter values at which
* to evaluate the likelihood. This vector should be of length
* npar().
*
* @param lengths Vector of parameters lengths.
*
* @param lbound Lower bound for truncated distributions, or a NULL
* pointer if the distribution is not truncated.
*
* @param ubound Upper bound for truncated distributions, or a NULL
* pointer if the distribution is not truncated.
*
* @exception length_error
*/
virtual void typicalValue(double *x, unsigned int length,
std::vector<double const *> const ¶meters,
std::vector<unsigned int> const &lengths,
double const *lbound, double const *ubound)
const = 0;
/**
* Returns the support of an unbounded distribution
*/
virtual void support(double *lower, double *upper, unsigned int length,
std::vector<double const *> const ¶ms,
std::vector<unsigned int> const &lengths) const = 0;
/**
* Indicates whether the support of the distribution is fixed.
*
* @param fixmask Boolean vector of length npar() indicating which
* parameters have fixed values.
*/
virtual bool isSupportFixed(std::vector<bool> const &fixmask) const = 0;
/**
* Checks that lengths of the parameters are correct.
*/
virtual bool
checkParameterLength (std::vector<unsigned int> const ¶meters)
const = 0;
/**
* Checks that the values of the parameters are consistent with
* the distribution. For example, some distributions require
* than certain parameters are positive, or lie in a given
* range.
*
* This function assumes that checkParameterLength returns true.
*/
virtual bool
checkParameterValue(std::vector<double const *> const ¶meters,
std::vector<unsigned int> const &lengths) const = 0;
/**
* Calculates what the length of a sampled value should be, based
* on the lengths of the parameters.
*
* @param par vector of lengths of the parameters.
*/
virtual unsigned int
length (std::vector<unsigned int> const &par) const = 0;
/**
* Returns the number of degrees of freedom of the distribution
* given the parameter lengths. By default this is the same as
* VectorDist#length. However, some distributions are constrained:
* and the support occupies a lower dimensional subspace. In this
* case, the df member function must be overrideen.
*/
virtual unsigned int df(std::vector<unsigned int> const &lengths) const;
/**
* Returns a Monte Carlo estimate of the Kullback-Leibler
* divergence between distributions with two different parameter
* values. This is done by drawing random samples from the
* distribution with the first set of parameters and then
* calculating the log-likelihood ratio with respect to the second
* set of parameters.
*
* Only one lower and one upper bound is required, which is
* assumed common to both sets of parameters. This is because the
* Kullback-Leibler divergence is infinite between two bounded
* distributions if they do not share the same bounds.
*
* @param par1 First set of parameters
* @param par2 Second set of parameter values
* @param lengths Vector of parameter lengths, common to both par1 and par2
* @param lower Pointer to lower bound (NULL if unbounded)
* @param upper Pointer to upper bound (NULL if unbounded)
* @param rng Random number generator
* @param nrep Number of replicates on which to base the estimate
*/
double KL(std::vector<double const *> const &par1,
std::vector<double const *> const &par2,
std::vector<unsigned int> const &lengths,
double const *lower, double const *upper,
RNG *rng, unsigned int nrep) const;
/**
* Returns the Kullback-Leibler divergence between distributions
* with two different parameter values.
*
* This is a virtual function that must be overloaded for any
* distribution that allows exact Kullback-Leibler divergence
* calculations. The default method returns JAGS_NA, indicating that
* the method is not implemented.
*/
virtual double KL(std::vector<double const *> const &par1,
std::vector<double const *> const &par2,
std::vector<unsigned int> const &lengths) const;
};
} /* namespace jags */
#endif /* VECTOR_DISTRIBUTION_H_ */
|