Skip to content

Commit

Permalink
adding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mberaha committed Apr 19, 2024
1 parent 1755132 commit 1cf5f57
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/hierarchies/betagg_hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@
#include "updaters/random_walk_updater.h"

/**
* Beta Gamma-Gamma hierarchy for univaraite data in [0, 1]
*
* This class represents a hierarchical model where data are distributed
* according to a Beta likelihood (see the `BetaLikelihood` class for
* details). The shape and rate parameters of the likelihood have
* independent gamma priors. That is
*
* \f[
* f(x_i \mid \alpha, \beta) &= Beta(\alpha, \beta) \\
* \alpha &\sim Gamma(\alpha_a, \alpha_b) \\
* \beta &\sim Gamma(\beta_a, \beta_b)
* \f]
*
* The state is composed of shape and rate. Note that this hierarchy
* is NOT conjugate, meaning that the marginal distribution is not available
* in closed form.
*/

class BetaGGHierarchy
Expand Down
8 changes: 0 additions & 8 deletions src/hierarchies/likelihoods/beta_likelihood.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ double BetaLikelihood::compute_lpdf(const Eigen::RowVectorXd &datum) const {
return stan::math::beta_lpdf(datum(0), state.shape, state.rate);
}

// Eigen::VectorXd BetaLikelihood::sample() const {
// Eigen::VectorXd out(1);
// auto &rng = bayesmix::Rng::Instance().get();
// out(0) = stan::math::beta_rng(state.shape, state.rate, rng);
// out = out.cwiseMin(1.0 - 1e-8).cwiseMax(1e-8);
// return out;
// }

void BetaLikelihood::update_sum_stats(const Eigen::RowVectorXd &datum,
bool add) {
double x = datum(0);
Expand Down
2 changes: 0 additions & 2 deletions src/hierarchies/likelihoods/beta_likelihood.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class BetaLikelihood
bool is_dependent() const override { return false; };
void clear_summary_statistics() override;

// Eigen::VectorXd sample() const override;

template <typename T>
T cluster_lpdf_from_unconstrained(
const Eigen::Matrix<T, Eigen::Dynamic, 1> &unconstrained_params) const {
Expand Down
5 changes: 5 additions & 0 deletions src/hierarchies/priors/gamma_gamma_prior.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include "hyperparams.h"
#include "src/utils/rng.h"

/*
* Prior model for `ShapeRate` states.
* This class assumes that the shape and rate are independent and given
* Gamma-distributed priors
*/
class GGPriorModel
: public BasePriorModel<GGPriorModel, State::ShapeRate, Hyperparams::GG,
bayesmix::GGPrior> {
Expand Down
6 changes: 5 additions & 1 deletion src/proto/distribution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ message MultiNormalIGDistribution {
double scale = 4;
}

/*
* Parameters for the product of two independent Gamma distributions with different
* rates and shapes
*/
message GamGamDistribution {
double a_shape = 1;
double a_rate = 2;
double b_shape = 3;
double b_rate = 4;
}
}
2 changes: 1 addition & 1 deletion src/proto/hierarchy_prior.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ message GGPrior {
oneof prior {
GamGamDistribution fixed_values = 1;
}
}
}
5 changes: 4 additions & 1 deletion src/proto/ls_state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ message FAState {
Matrix lambda = 4;
}

/*
* Parameters of a shape-rate state, used, e.g., by the BetaLikelihood
*/
message SRState {
double shape = 1;
double rate = 2;
}
}

0 comments on commit 1cf5f57

Please sign in to comment.