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 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 - 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
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§
- 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. - 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 - This is the lowest-level driver. Pass
NoGuardto get the unguarded behavior; most callers should prefer the convenience wrappersrefine_with_candidates/refine_with_proposer/refine_with_proposer_guarded. - 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.