[1e595d]: src / modules / bugs / distributions / DSum.cc  Maximize  Restore  History

Download this file

124 lines (107 with data), 2.7 kB

  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
#include <config.h>
#include <util/logical.h>
#include <util/nainf.h>
#include <module/ModuleError.h>
#include "DSum.h"
#include <cfloat>
#include <cmath>
using std::vector;
using std::fabs;
using std::sqrt;
namespace bugs {
DSum::DSum()
: ArrayDist("dsum", 0)
{
}
bool DSum::isDiscreteValued(vector<bool> const &mask) const
{
return allTrue(mask);
}
double DSum::logDensity(double const *x, unsigned int length, PDFType type,
vector<double const *> const &par,
vector<vector<unsigned int> > const &dims,
double const *lower, double const *upper) const
{
const double tol = sqrt(DBL_EPSILON);
for (unsigned int i = 0; i < length; ++i) {
double s = x[i];
for (unsigned int j = 0; j < par.size(); ++j) {
s -= par[j][i];
}
if (fabs(s) > tol) {
return JAGS_NEGINF;
}
}
return 0;
}
void DSum::randomSample(double *x, unsigned int length,
vector<double const *> const &par,
vector<vector<unsigned int> > const &dims,
double const *lower, double const *upper,
RNG *rng) const
{
for (unsigned int i = 0; i < length; ++i) {
x[i] = 0;
for (unsigned int j = 0; j < par.size(); ++j) {
x[i] += par[j][i];
}
}
}
void DSum::typicalValue(double *x, unsigned int length,
vector<double const *> const &par,
vector<vector<unsigned int> > const &dims,
double const *lower, double const *upper) const
{
for (unsigned int i = 0; i < length; ++i) {
x[i] = 0;
for (unsigned int j = 0; j < par.size(); ++j) {
x[i] += par[j][i];
}
}
}
bool DSum::isSupportFixed(vector<bool> const &fixmask) const
{
return allTrue(fixmask);
}
unsigned int DSum::df(vector<vector<unsigned int> > const &dims) const
{
return 0;
}
bool DSum::checkParameterValue(vector<double const *> const &params,
vector<vector<unsigned int> > const &dims) const
{
return true;
}
bool DSum::checkParameterDim (vector<vector<unsigned int> > const &dims) const
{
for (unsigned int i = 1; i < dims.size(); ++i) {
if (dims[i] != dims[0])
return false;
}
return true;
}
bool DSum::checkParameterDiscrete(vector<bool> const &mask) const
{
for (unsigned int i = 1; i < mask.size(); ++i) {
if (mask[i] != mask[0])
return false;
}
return true;
}
void DSum::support(double *lower, double *upper, unsigned int length,
vector<double const *> const &par,
vector<vector<unsigned int> > const &dims) const
{
for (unsigned int i = 0; i < length; ++i) {
lower[i] = 0;
for (unsigned int j = 0; j < par.size(); ++j) {
lower[i] += par[j][i];
}
upper[i] = lower[i];
}
}
vector<unsigned int> DSum::dim(vector<vector<unsigned int> > const &dims) const
{
return dims[0];
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks