Repository navigation
Sbm bug fix - #219
Open
sekulovskin wants to merge 2 commits into
Open
Sbm bug fix#219sekulovskin wants to merge 2 commits into
sekulovskin wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes how the SBM edge prior sets the inclusion probabilities of a newly opened
cluster. They were drawn from the prior instead of from their posterior given the
variable's edges. As a result, the sampler did not target the correct posterior
over partitions.
Problem / Motivation
In the allocation step (
block_allocations_mfm_sbm), a variable that leaves ashared cluster to start a new one is scored with the correct integrated
likelihood. But the new cluster's between-cluster inclusion probabilities were
then drawn from the prior Beta(alpha_between, beta_between), ignoring the
variable's edges. Variables updated later in the same sweep used these random
values to decide whether to join the new cluster.
Under the default
sbm_prior()this biases the posterior over partitions(cluster-count probabilities, co-clustering, clustering Bayes factors). With
strongly informative priors such as
sbm_prior(8, 1, 1, 8)the bias isnegligible.
Proposed Changes / New Functionality
In the non-singleton branch of
block_allocations_mfm_sbm(
src/priors/sbm_edge_prior.cpp), each between-cluster probability of the newcluster is now drawn from Beta(alpha_between + s_ib, beta_between + n_b - s_ib).
Here s_ib is the number of edges from the variable to cluster b, and n_b is the
size of cluster b. The within-cluster entry keeps its prior draw, because the new
cluster has no within-cluster pairs yet.
This affects the sampling algorithm in
src/only. There are no changes to priorspecifications, summary outputs, or R functions.
Fixes #
Type of Change
Documentation and Release Notes
man/*.Rdfiles if roxygen comments changedNEWS.mdentry if the change affects usersTesting and Validation
Compared the sampler with exact enumeration of all partitions (6 variables,
averaged over the sampled graphs). Before the fix: total variation distance
0.107, largest deviation 11.8 Monte Carlo SEs. After: 0.018 and 1.8 SEs, i.e.
within Monte Carlo error.
sbm_prior(8, 1, 1, 8)is unaffected (TV 0.0009).Added
tests/testthat/test-sbm-allocation.R(nightly tier,BGMS_RUN_SLOW_TESTS=true, ~8 s). It checks P(number of clusters) againstexact enumeration within 0.02: the gap is 0.004 after the fix and 0.036 before,
so the test fails on the old code.
Full test suite: 8,514 passed, 0 failed. The slow tiers of
test-sbm-correction.Randtest-mixed-correction.Ralso pass.Added or updated tests in
tests/testthat/when neededRan the project styler
lintr::lint_package()roxygen2::roxygenise()if roxygen comments changedrcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"))for non-trivial changesAdditional Notes
sbm_prior()will change numerically (partitionprobabilities, cluster counts, clustering Bayes factors). Results under strongly
informative Beta priors are essentially unchanged.
"joint"branch (block_allocations_mfm_sbm_corrected) has thesame prior draw. Its correct conditional includes the normalizer tilt, so it
needs a separate fix.