MUQ  0.4.3
InverseGamma.cpp
Go to the documentation of this file.
3 #include <Eigen/Core>
4 
5 using namespace muq::Modeling;
6 using namespace muq::Utilities;
7 
8 InverseGamma::InverseGamma(Eigen::VectorXd const& alphaIn,
9  Eigen::VectorXd const& betaIn) : Distribution(alphaIn.size()),
10  alpha(alphaIn),
11  beta(betaIn),
12  logConst(ComputeConstant(alphaIn, betaIn))
13  {};
14 
16  double betaIn) : InverseGamma(alphaIn*Eigen::VectorXd::Ones(1),
17  betaIn*Eigen::VectorXd::Ones(1)){};
18 
19 double InverseGamma::ComputeConstant(Eigen::VectorXd const& alphaIn,
20  Eigen::VectorXd const& betaIn)
21 {
22  double logConst = 0;
23  for(int i=0; i<alphaIn.size(); ++i)
24  logConst += alphaIn(i)*std::log(betaIn(i)) - std::lgamma(alphaIn(i));
25 
26  return logConst;
27 }
28 
30 {
31  Eigen::VectorXd const& x = inputs.at(0).get();
32 
33  if(x.minCoeff()<std::numeric_limits<double>::epsilon())
34  return -1.0*std::numeric_limits<double>::infinity();
35 
36  return logConst + ((-alpha.array()-1.0)*x.array().log() - beta.array() / x.array()).sum();
37 }
38 
39 
41 {
42  Eigen::VectorXd output(alpha.size());
43  for(int i=0; i<alpha.size(); ++i)
44  output(i) = 1.0/RandomGenerator::GetGamma(alpha(i),1.0/beta(i));
45 
46  return output;
47 }
const Eigen::VectorXd beta
Definition: InverseGamma.h:31
const Eigen::VectorXd alpha
Definition: InverseGamma.h:30
static double ComputeConstant(Eigen::VectorXd const &alphaIn, Eigen::VectorXd const &betaIn)
InverseGamma(double alphaIn, double betaIn)
virtual double LogDensityImpl(ref_vector< Eigen::VectorXd > const &inputs) override
Implement the log-density.
virtual Eigen::VectorXd SampleImpl(ref_vector< Eigen::VectorXd > const &inputs) override
Sample the distribution.
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37