Expand description
Degree-corrected Poisson refinement core.
Shared Poisson-scoring machinery for top-down multi-level refinement.
Given per-entity sparse profiles (gene sums or a dense projection) and
current group labels, refinement reassigns entities between groups by
scoring moves under a Poisson likelihood with size-factor offsets.
Candidate-set construction is delegated to CandidateProposer so
different front-ends (cross-batch BBKNN, spatial KNN graph, …) can
plug in their own neighborhood definition.
The partition handed in is kept as a partition: refinement makes its
blocks purer without choosing how many there are or how large. Scores
are built so that a block is not preferred for being large (see
DcPoissonStats), an entity moves only on evidence beyond the noise
of the block estimates, and member-count limits (RefineParams) keep
every block near its starting size, small blocks trading members
rather than losing them.
The name “DC-Poisson” is deliberate: we are not inferring a stochastic block model — the blocks are given externally (by a prior coarsening step) and we only score membership moves. Compare to the full DC-SBM where blocks themselves are latent variables.
Entry points:
refine_with_candidates— lowest-level sweep driver given pre-built candidates.refine_with_proposer— generic driver that first asks aCandidateProposer.
See the BbknnProposer in refine_multilevel for the data_beans::alg
front-end, and pinto’s GraphProposer for the spatial-graph front-end.
Structs§
- DcPoisson
Stats - Sufficient statistics with cached log quantities for O(K · nnz(row)) scoring.
- NoGuard
- Trivial guard that accepts every move. Zero-cost default used by the
unguarded
refine_with_candidatesandrefine_with_proposer. - Profiles
- Sparse row-per-entity profile, owned by the refinement pass.
- Refine
Context - Shared sweep-driver context bundling the readonly inputs that every
refine_with_*variant needs. Kept as a struct so the driver fns don’t exceed clippy’s argument-count threshold. - Refine
Params - Parameters controlling the refinement pass.
Enums§
- Feature
Weighting - Per-feature weighting applied to the sparse profile before DC-Poisson
scoring. All variants multiply each nonzero entry
y_{e,f}by a scalarw_fand recompute per-row size factors; only the formula forw_fdiffers. - Profile
Source - Feature representation used to score entity → block moves.
Constants§
- BATCH_
FACTOR_ BOUND - Largest batch factor, and the reciprocal of the smallest.
- BATCH_
FACTOR_ PSEUDO_ COUNT - Pseudo-count
κin the observed and the expected count behind a batch factor (seeProfiles::rescale_batches). - LOG_EPS
- Additive floor to keep
ln(.)finite when a block or feature has zero mass.
Traits§
- Candidate
Proposer - Propose candidate group labels each entity may move into on one sweep.
- Move
Guard - Veto individual moves after they’ve been picked by the sweep.
Functions§
- argmax_
log_ restricted - Argmax over
allowedindices. - argmax_
log_ restricted_ from - Argmax over
allowedindices that leavescurrentonly for a strictly better block: a tie with the current label (an entity with no evidence scores every block alike) is not a move. Withcurrentoutsideallowed, ties go to the first allowed index. - compact_
labels - Compact a label vector to dense
0..Kids, preserving relative order of first appearance. Returns the new labels and the newK. Generic over the key type so it serves both plain group ids (usize) and composite keys (e.g.(child, parent)pairs inproject_to_refinement). - compute_
log_ probs_ restricted - Log-probability of placing entity
einto each of theallowedblocks. - compute_
sibling_ sets - For each entity, siblings at
level= groups atlevelsharing the same parent group atlevel + 1. - intersect_
with_ siblings_ fallback - Intersect a per-entity sibling set with a per-entity neighbor-group set, with sibling fallback when the intersection is empty and guaranteed inclusion of the entity’s current label so staying put is always a legal move.
- refine_
with_ candidates - Unguarded variant of
refine_with_candidates_guarded. - refine_
with_ candidates_ guarded - Refine
labelsin place for one level by running Gibbs + greedy sweeps overprofileswith the given pre-builtcandidatesand a customMoveGuard. Returns total accepted moves across all sweeps. - refine_
with_ proposer - Unguarded generic driver: ask
proposerfor candidates, then run the sweep withNoGuard. - refine_
with_ proposer_ guarded - Generic driver: ask
proposerfor candidates, then run the guarded sweep. - sample_
categorical_ log_ restricted - Gumbel-max categorical sampling over the
allowedslots oflog_probs, skipping non-finite entries. Falls back tocurrent(the entity’s present label — always a legal “move”) when no allowed slot is finite, so a degenerate score vector can never produce an out-of-range label.