Skip to content

Commit

Permalink
Revert "Change nonconjugate class to keep a running logp score"
Browse files Browse the repository at this point in the history
This reverts commit fc91153.
  • Loading branch information
ThomasColthurst committed Jun 21, 2024
1 parent 59dbbb1 commit 27f8ec5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cxx/distributions/nonconjugate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ template <typename T>
class NonconjugateDistribution : public Distribution<T> {
public:
// Abstract base class for Distributions that don't have conjugate priors.
std::map<T, int> seen;

// The log probability of x given the current latent values.
virtual double logp(const T& x) const = 0;
Expand All @@ -24,19 +25,21 @@ class NonconjugateDistribution : public Distribution<T> {
// Transition the current latent values.
virtual void transition_theta(std::mt19937* prng) = 0;

double cumulative_logp = 0.0;

void incorporate(const T& x) {
seen[x]++;
(this->N)++;
cumulative_logp += logp(x);
};

void unincorporate(const T& x) {
--seen[x];
--(this->N);
cumulative_logp -= logp(x);
};

double logp_score() const {
return cumulative_logp;
double score = 0.0;
for (const auto &it : seen) {
score += logp(it.first) * it.second;;
}
return score;
}
};

0 comments on commit 27f8ec5

Please sign in to comment.