Skip to content

Commit

Permalink
Add TODOs and extend tolerance of sample mean
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesYang007 committed Apr 20, 2020
1 parent 20c486f commit 7af9834
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/autoppl/expr_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ inline constexpr auto normal(MeanType&& mean_expr,
* Builds a Bernoulli expression only when the parameter
* is a valid discrete distribution parameter type.
* See var_expr.hpp for more information.
* TODO: generalize as done with uniform and normal
*/
template <class ProbType>
inline constexpr auto bernoulli(const ProbType& p_expr)
Expand Down
18 changes: 3 additions & 15 deletions test/algorithm/mh_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@

namespace ppl {

TEST(mh_unittest, plot_hist_sanity)
{
static constexpr size_t sample_size = 20000;
std::array<double, sample_size> storage = {0.};
std::normal_distribution normal_sampler(0., 1.);
std::mt19937 gen;
for (size_t i = 0; i < sample_size; ++i) {
storage[i] = normal_sampler(gen);
}
plot_hist(storage);
}

/*
* Fixture for Metropolis-Hastings
*/
Expand Down Expand Up @@ -48,15 +36,15 @@ TEST_F(mh_fixture, sample_std_normal)
auto model = (theta |= normal(0., 1.));
mh_posterior(model, sample_size);
plot_hist(storage);
EXPECT_NEAR(sample_average(1000), 0., 0.01);
EXPECT_NEAR(sample_average(1000), 0., 0.1);
}

TEST_F(mh_fixture, sample_uniform)
{
auto model = (theta |= uniform(0., 1.));
mh_posterior(model, sample_size);
plot_hist(storage, 0.05, 0., 1.);
EXPECT_NEAR(sample_average(1000), 0.5, 0.01);
EXPECT_NEAR(sample_average(1000), 0.5, 0.1);
}

TEST_F(mh_fixture, sample_unif_normal_posterior)
Expand All @@ -68,7 +56,7 @@ TEST_F(mh_fixture, sample_unif_normal_posterior)
);
mh_posterior(model, sample_size);
plot_hist(storage);
EXPECT_NEAR(sample_average(1000), 3.0, 0.01);
EXPECT_NEAR(sample_average(1000), 3.0, 0.1);
}

} // namespace ppl

0 comments on commit 7af9834

Please sign in to comment.