Expand description
Per-gene weighting helpers used by reporting / annotation pipelines.
compute_nb_fisher_weights derives bounded (0, 1] weights from the
NB dispersion trend (see nb_dispersion) — high-mean / high-dispersion
genes get attenuated, low-mean genes recover w_g = 1 in the Poisson
limit. The same formula is applied inside DC-Poisson refinement so
clustering and reporting stay consistent.
apply_gene_weights row-scales a (num_genes × K) matrix in place.
Originally lived in pinto/src/util/common.rs; moved here so senna /
chickpea / other consumers don’t have to duplicate the implementation.
Functions§
- apply_
gene_ weights - Scale each row of
sum_gkby its corresponding entry ofweights.weights.len()must equalsum_gk.nrows(). - compute_
nb_ fisher_ weights - Fit the NB mean-variance trend on
data_vecand return per-gene Fisher-info weights in row order (same asdata_vec.row_names()). - compute_
nb_ fisher_ weights_ coarsened - Same as
compute_nb_fisher_weights, but at the coarse feature level afterFeatureCoarseningaggregation. Streams cells, coarsens each block viaaggregate_sparse_csc(sum within group), then fits a fresh NB dispersion trend atD_coarseand computes per-meta-gene Fisher weights. - fisher_
weights_ from_ pseudobulk - Fisher weights fitted on pseudobulks rather than on cells.
- fisher_
weights_ from_ stats - Fit a fresh NB dispersion trend on
statsand return per-feature Fisher-info weightsw_d ∈ (0, 1].n_entitiesis the count divisor used to compute the mean entity size factors̄(typically the number of cells or pseudobulks the stats were accumulated over). - load_
fisher_ weights - Convenience wrapper: load
{prefix}.fisher_weights.parquet. ReturnsOk(None)when the file doesn’t exist so callers can fall back to recomputing viacompute_nb_fisher_weights. - load_
fisher_ weights_ coarse - Convenience wrapper: load
{prefix}.fisher_weights_coarse.parquet. ReturnsOk(None)when the file doesn’t exist (older models trained before coarse weights were saved). - load_
per_ gene_ weights - Load a per-gene weight vector previously written by
save_per_gene_weights. Returns(gene_names, weights). - save_
fisher_ weights - Convenience wrapper: write per-gene weights to the conventional
{out_prefix}.fisher_weights.parquetpath used by sennatopicand chickpeafit-topic. Downstream consumers (e.g.senna annotate) look for this filename to reload weights instead of re-scanning all cells. - save_
fisher_ weights_ coarse - Save coarse-resolution NB-Fisher weights computed at the encoder/
decoder’s
D_coarse(post-feature-coarsening). Stored at{prefix}.fisher_weights_coarse.parquetkeyed on syntheticcoarse_<i>axis ids since coarse meta-genes have no biological names. Loaded bysenna predict/senna eval-topicto re-attach the same per-feature multinomial-loss weights at inference. - save_
per_ gene_ weights - Save a per-gene weight vector as a single-column parquet keyed on
gene name. The output path is fully specified — callers control the
filename. For the standard
{out}.fisher_weights.parquetconvention used by senna and chickpea, seesave_fisher_weights.
Type Aliases§
- Gene
Weights (gene_names, per-gene weights)returned by the per-gene weight loaders.