Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BetaPrime tests #14

Draft
wants to merge 4 commits into
base: release/v0.19.0
Choose a base branch
from
Draft

Conversation

cscherrer
Copy link
Contributor

No description provided.

@cscherrer
Copy link
Contributor Author

Current status:

test dist::betaprime::tests::cdf_values ... ok
test dist::betaprime::tests::ln_pp_vs_ln_m_single ... ok
test dist::betaprime::tests::mean_when_beta_leq_one ... ok
test dist::betaprime::tests::mode_when_alpha_geq_one ... ok
test dist::betaprime::tests::draw_should_return_positive_values ... ok
test dist::betaprime::tests::mode_when_alpha_lt_one ... ok
test dist::betaprime::tests::new ... ok
test dist::betaprime::tests::mean_when_beta_gt_one ... ok
test dist::betaprime::tests::rv_impl::should_impl_debug_clone_and_partialeq ... ok
test dist::betaprime::tests::test_ln_m_cache_consistency ... ok
test dist::betaprime::tests::test_posterior ... ok
test dist::betaprime::tests::test_posterior_parameter_updates ... ok
test dist::betaprime::tests::variance_when_beta_leq_two ... ok
test dist::betaprime::tests::rv_impl::should_impl_parameterized ... ok
test dist::betaprime::tests::variance_when_beta_gt_two ... ok
test dist::betaprime::tests::test_bayes_law ... ok
test dist::betaprime::tests::ln_m_vs_monte_carlo ... FAILED   <------------------bad
test dist::betaprime::tests::test_sbc ... ok
test dist::betaprime::tests::ln_m_single_datum_vs_monte_carlo ... ok
test dist::betaprime::tests::ln_pp_vs_monte_carlo ... ok
test dist::betaprime::tests::ln_pp_single_vs_monte_carlo ... ok

With 1K samples it fails with

-1.5404450409471488 !~ -1.299563872668477

If I increase it to 1M I get

-1.5404450409471488 !~ -1.2802343101033689

and for 100M

-1.5404450409471488 !~ -1.2785370199497486

With more samples it's getting worse, so something is very wrong. But the implementation is simple, and I don't see any errors with the math. Here's the derivation

image

and implementation

    fn ln_m_cache(&self) -> Self::MCache {
        self.ln_beta_ab()
    }

    fn ln_m_with_cache(
        &self,
        cache: &Self::MCache,
        data: &DataOrSuffStat<usize, StickBreakingDiscrete>,
    ) -> f64 {
        let post = self.posterior(data);
        post.ln_beta_ab() - cache
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant