Skip to content

Commit

Permalink
Fix categorical logp to be conditional probability
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasColthurst committed Jul 8, 2024
1 parent ac14bd5 commit d4d6012
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions cxx/emissions/categorical.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ class CategoricalEmission : public Emission<int> {
}

double logp(const std::pair<int, int>& x) const {
double lp;
for (size_t i = 0; i < emission_dists.size(); ++i) {
if (std::cmp_equal(i, x.first)) {
lp += emission_dists[i].logp(x.second);
} else {
lp += emission_dists[i].logp_score();
}
}
return lp;
return emission_dists[x.first].logp(x.second);
}

double logp_score() const {
Expand Down
2 changes: 1 addition & 1 deletion cxx/emissions/categorical_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(test_simple) {
ce.incorporate(std::make_pair<int, int>(4, 4));
BOOST_TEST(ce.N == 2);

BOOST_TEST(ce.logp(std::make_pair<int, int>(2, 2)) == -4.8283137373023006,
BOOST_TEST(ce.logp(std::make_pair<int, int>(2, 2)) == -1.6094379124341003,
tt::tolerance(1e-6));

std::mt19937 prng;
Expand Down

0 comments on commit d4d6012

Please sign in to comment.