topo
Submodules
Attributes
Classes
Geometry-aware estimator that learns spectral scaffolds, refined operators, and 2-D layouts. |
Functions
|
Load a TopOGraph object from a pickle file. |
|
Save a TopOGraph object to a pickle file. |
Package Contents
- topo._HAVE_SCANPY = True
- class topo.TopOGraph(base_knn=30, graph_knn=30, min_eigs=128, n_jobs=-1, projection_methods=['MAP', 'PaCMAP'], base_kernel=None, base_kernel_version='bw_adaptive', graph_kernel_version='bw_adaptive', base_metric='cosine', graph_metric='euclidean', diff_t=0, delta=1.0, sigma=0.1, low_memory=False, eigen_tol=1e-08, eigensolver='arpack', backend='hnswlib', cache=True, verbosity=0, random_state=42, id_method='fsa', id_ks=50, id_metric='euclidean', id_quantile=0.99, id_min_components=128, id_max_components=1024, id_headroom=0.5, uom=False, eigenmap_method=None, laplacian_type='normalized')
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixinGeometry-aware estimator that learns spectral scaffolds, refined operators, and 2-D layouts.
TopOGraph builds the multiscale and single-time spectral scaffolds, reconstructs refined similarity graphs in scaffold space, and exposes ready-to-plot TopoMAP/TopoPaCMAP embeddings together with intrinsic dimensionality estimates. Legacy dictionaries remain available for benchmarking and combinatorial model searches.
- Parameters:
base_knn (int, default 30) – k-nearest neighbors for the base graph on input space.
graph_knn (int, default 30) – k-nearest neighbors for the refined graph built in spectral scaffold space.
min_eigs (int, default 128) – Minimum number of eigenpairs to compute for the scaffold.
base_kernel (topo.tpgraph.Kernel or None, default None) – Pre-fitted kernel to reuse; if provided, fit skips base graph construction.
laplacian_type ({'unnormalized', 'normalized', 'random_walk', 'geometric'}, default 'normalized') – Laplacian normalization used for spectral computations.
base_kernel_version (str, default 'bw_adaptive') – Kernel choice for the base graph (e.g., ‘bw_adaptive’, ‘fuzzy’, ‘cknn’).
graph_kernel_version (str, default 'bw_adaptive') – Kernel choice for scaffold graphs (applies to DM and msDM).
backend ({'hnswlib', 'nmslib', 'annoy', 'faiss', 'sklearn'}, default 'hnswlib') – Approximate nearest-neighbor backend.
base_metric (str, default 'cosine') – Distance for the base kNN graph (usually cosine/correlation on standardized inputs).
graph_metric (str, default 'euclidean') – Distance for kNN in scaffold space.
diff_t (int, default 0) – Diffusion time used for the single-time scaffold; ignored for multiscale.
sigma (float, default 0.1) – Bandwidth for Gaussian kernels (when selected).
delta (float, default 1.0) – Radius parameter for cKNN kernels.
n_jobs (int, default 1) – Threads for kNN searches; -1 uses all cores.
low_memory (bool, default False) – Avoid caching large kernel objects when True.
eigen_tol (float, default 1e-8) – Tolerance passed to the eigen solver.
eigensolver ({'arpack', 'lobpcg', 'amg', 'dense'}, default 'arpack') – Solver used for eigendecomposition.
projection_methods (list[str], default ['MAP', 'PaCMAP']) – Layouts to compute when calling project.
cache (bool, default True) – Cache kernel and eigen objects in dictionaries for reuse.
verbosity (int, default 0) – 0: silent; 1: major steps; 2+: include layout messages; 3: debug neighborhoods.
random_state (int or numpy.random.RandomState, default 0) – Random seed/control for reproducibility.
id_method ({'mle', 'fsa'}, default 'fsa') – Intrinsic dimensionality estimator that selects scaffold size (both are stored).
id_ks (int or iterable, default 50) – Neighborhood sizes for I.D. estimation.
id_metric (str, default 'euclidean') – Metric used for I.D. estimation.
id_quantile (float, default 0.99) – Quantile for FSA-based I.D. estimation.
id_min_components (int, default 128) – Lower bound on scaffold components.
id_max_components (int, default 1024) – Upper bound on scaffold components.
id_headroom (float, default 0.5) – Extra fraction of components beyond the estimated I.D. to keep.
uom (bool, default False) – Enable unions-of-manifolds (block-diagonal scaffolds) if supported.
- Variables:
knn_X (scipy.sparse.csr_matrix) – Base kNN graph on the input space.
P_of_X (scipy.sparse.csr_matrix) – Diffusion operator on the input space.
knn_Z (knn_msZ,) – kNN graphs on the multiscale and single-time spectral scaffolds.
P_of_Z (P_of_msZ,) – Refined diffusion operators on the multiscale and single-time scaffolds.
eigenvalues (numpy.ndarray) – Eigenvalues of the active eigenbasis (multiscale by default).
msPaCMAP (MAP, msMAP, PaCMAP,) – Ready-to-plot 2-D layouts computed on refined graphs.
ProjectionDict (BaseKernelDict, EigenbasisDict, GraphKernelDict,) – Legacy storage used for benchmarking and model selection.
- projection_methods = ['MAP', 'PaCMAP']
- diff_t = 0
- min_eigs = 128
- n_eigs = 128
- base_knn = 30
- graph_knn = 30
- n_jobs = -1
- low_memory = False
- backend = 'hnswlib'
- base_metric = 'cosine'
- graph_metric = 'euclidean'
- eigen_tol = 1e-08
- eigensolver = 'arpack'
- base_kernel = None
- base_kernel_version = 'bw_adaptive'
- eigenmap_method
- graph_kernel_version = 'bw_adaptive'
- laplacian_type = 'normalized'
- eigenbasis = None
- verbosity = 0
- sigma = 0.1
- bases_graph_verbose = False
- layout_verbose = False
- delta = 1.0
- random_state = 42
- cache = True
- eigenbasis_knn_graph = None
- base_nbrs_class = None
- base_knn_graph = None
- BaseKernelDict
- EigenbasisDict
- GraphKernelDict
- ProjectionDict
- ClustersDict
- n = None
- m = None
- SpecLayout = None
- runtimes
- current_eigenbasis = None
- current_graphkernel = None
- global_dimensionality = None
- local_dimensionality = None
- RiemannMetricDict
- LocalScoresDict
- temp_file = None
- _have_hnswlib = None
- _have_nmslib = None
- _have_annoy = None
- _have_faiss = None
- id_method = 'fsa'
- id_ks = 50
- id_metric = 'euclidean'
- id_quantile = 0.99
- id_min_components = 128
- id_max_components = 1024
- id_headroom = 0.5
- _id_details
- _scaffold_components_dm = None
- _scaffold_components_ms = None
- _knn_msZ = None
- _knn_Z = None
- _kernel_msZ = None
- _kernel_Z = None
- msTopoMAP_snapshots = []
- TopoMAP_snapshots = []
- uom = False
- uom_enabled = False
- uom_comp_labels_ = None
- uom_components_ = None
- uom_knn_X_list = None
- knn_X_uom = None
- P_of_X_uom = None
- uom_BaseKernel_list = None
- uom_DMEig_list = None
- uom_msDMEig_list = None
- uom_eigenvalues_dm_list = None
- uom_eigenvalues_ms_list = None
- _uom_active_mode = 'msDM'
- uom_Z_list = None
- uom_msZ_list = None
- uom_knn_Z_list = None
- uom_knn_msZ_list = None
- uom_Kernel_Z_list = None
- uom_Kernel_msZ_list = None
- Z_uom = None
- msZ_uom = None
- knn_Z_uom = None
- knn_msZ_uom = None
- P_of_Z_uom = None
- P_of_msZ_uom = None
- _uom_axis_slices = None
- __repr__()
- _noANN_lib()
- _parse_backend()
- _parse_random_state()
- _automated_sizing(X)
Run automated scaffold sizing directly on X (no eigenbasis required), record details for both methods, and set:
self._scaffold_components_ms
self._scaffold_components_dm
self.n_eigs (so eigendecomposition uses this size cap)
Notes
Uses self.id_method (‘fsa’ or ‘mle’) to pick the working size.
Applies caps: [id_min_components, id_max_components, n-2].
- _csr(A)
- _to_float32_csr(A: scipy.sparse.csr_matrix) scipy.sparse.csr_matrix
- _symmetrize_geometric(P: scipy.sparse.csr_matrix) scipy.sparse.csr_matrix
S_ij = sqrt(P_ij * P_ji) on overlapping support (CSR float32).
- _normalized_laplacian(A: scipy.sparse.csr_matrix) scipy.sparse.csr_matrix
- _eigengap_k(vals: numpy.ndarray, k_max: int, k_min: int = 2) int
- _mbkm(X: numpy.ndarray, n_clusters: int, random_state: int = 0) numpy.ndarray
- _consolidate_macros_via_conductance(W: scipy.sparse.csr_matrix, labels: numpy.ndarray, max_iters: int = 100)
- _louvain_micro(S: scipy.sparse.csr_matrix, random_state: int = 0, max_passes: int = 100, gamma: float = 0.85)
Greedy Louvain (modularity) on weighted undirected graph S (CSR). Returns micro labels (ints). No external deps.
- uom_find_components(P: scipy.sparse.csr_matrix, random_state: int = 0, consolidate: bool = True, max_passes: int = 100, gamma: float = 0.85)
Discover disconnected “macro” components under the Union-of-Manifolds (UoM) hypothesis using the refined TopoMetry operator (self.graph_kernel.P).
Workflow
Symmetrize P via geometric mean → conservative similarity S.
If S already disconnected, return its connected components.
Micro partition: greedy Louvain clustering on S, with resolution γ < 1.
Build a supergraph W (micro × micro), edge weights = sum of S across partitions.
Macro partition: eigengap spectral clustering on W with MiniBatchKMeans.
Optional consolidation: merge fragile macros using a conductance outlier rule.
Propagate macro labels back to all cells.
- param random_state:
Random seed for stochastic parts (MiniBatchKMeans initialization, node visiting order in Louvain). If None, falls back to self.random_state.
- type random_state:
int or None, default=None
- param consolidate:
Whether to run a final consolidation pass on the macro components. Uses conductance-based outlier detection to merge flimsy macros into stronger neighbors. Helps avoid over-splitting into many weak components. Set False to return the raw spectral partition.
- type consolidate:
bool, default=True
- param gamma:
Resolution parameter for Louvain modularity at the micro partition step. - γ < 1 → favors fewer, larger micro-communities (coarser). - γ > 1 → favors more, smaller micro-communities (finer). Lowering below 1 is generally helpful for UoM, as it avoids too many spurious micro splits that later cascade into excess macro components.
- type gamma:
float, default=0.85
- param max_passes:
Maximum number of Louvain refinement passes over all nodes. Each pass shuffles nodes and attempts greedy modularity improvements. Larger values increase stability at the cost of runtime. Usually 20–50 passes are sufficient; 100 is a safe ceiling.
- type max_passes:
int, default=100
- returns:
n_comp (int) – Number of discovered UoM components (macro-level).
labels (ndarray of shape (n_samples,)) – Integer component label for each cell (0 .. n_comp-1). These labels reflect the final macro components after optional consolidation.
- fit(X=None, **kwargs)
Build base kNN, base kernel P(X). Compute both msDM and DM eigenbases (dual scaffold). Optionally (uom=True), detect disconnected components and build per-component scaffolds and refined graphs; aggregate them into block-diagonal operators and concatenated coordinates with no cross-component edges.
- spectral_scaffold(multiscale: bool = True)
Return spectral scaffold coordinates. If UoM is enabled, return the aggregated UoM coordinates (concatenated columns, rows in original sample order). Otherwise return the global scaffold.
- Parameters:
multiscale (bool (default True)) – If True, returns msDM coordinates; else returns DM (fixed time diff_t) coordinates.
- Returns:
np.ndarray, shape (n_samples, n_eigs)
- property eigenvalues
Eigenvalues of the active eigenbasis.
- Returns:
np.ndarray or dict –
Standard mode (uom=False): 1-D np.ndarray (msDM by default).
- UoM mode (uom=True): dict with per-component eigenvalue arrays:
{ ‘mode’: ‘msDM’ or ‘DM’, ‘per_component’: [np.ndarray, …], # eigenvalues for each component ‘component_sizes’: [int, …] # n_i for each component }
- property knn_msZ
kNN graph in the multiscale Diffusion Map (msDM) scaffold space. (UoM-aggregated if enabled).
- Returns:
scipy.sparse.csr_matrix – k-nearest neighbor adjacency matrix for the msDM scaffold.
- Raises:
AttributeError – If the msDM kNN graph is not available (e.g., .fit(X) has not been called).
- property knn_Z
kNN graph in the standard Diffusion Map (DM) scaffold space (UoM-aggregated if enabled)..
- Returns:
scipy.sparse.csr_matrix – k-nearest neighbor adjacency matrix for the DM scaffold.
- Raises:
AttributeError – If the DM kNN graph is not available (e.g., .fit(X) has not been called).
- property P_of_msZ
Diffusion operator on the msDM scaffold (UoM block-diagonal if enabled).
- Returns:
scipy.sparse.csr_matrix – Refined diffusion operator (row-stochastic) constructed on the msDM scaffold.
- Raises:
AttributeError – If the msDM diffusion operator is not available (e.g., .fit(X) has not been called).
- property P_of_Z
Diffusion operator on the DM scaffold (UoM block-diagonal if enabled).
- Returns:
scipy.sparse.csr_matrix – Refined diffusion operator (row-stochastic) constructed on the DM scaffold.
- Raises:
AttributeError – If the DM diffusion operator is not available (e.g., .fit(X) has not been called).
- property knn_X
Initial kNN graph in the input (X) space (UoM block-diagonal if enabled).
- Returns:
scipy.sparse.csr_matrix – k-nearest neighbor adjacency matrix built directly from the input data.
- Raises:
AttributeError – If the base kNN graph is not available (e.g., .fit(X) has not been called).
- property P_of_X
Diffusion operator on the input (X) space (UoM block-diagonal if enabled).
- Returns:
scipy.sparse.csr_matrix – Diffusion operator (row-stochastic) constructed on the base input kNN graph.
- Raises:
AttributeError – If the diffusion operator on X is not available (e.g., .fit(X) has not been called).
- property global_id
Global intrinsic dimensionality estimated by the Maximum Likelihood Estimator (MLE).
- Returns:
float – The global MLE dimension estimate, as computed during .fit(X).
- Raises:
AttributeError – If MLE details are not available (e.g., .fit(X) has not been called).
- property local_ids
Local intrinsic dimensionality estimates per sample.
- Returns:
dict –
- Dictionary with per-sample ID vectors:
’mle’ → per-sample estimates from Maximum Likelihood Estimator (MLE).
’fsa’ → per-sample estimates from Fisher Separability Analysis (FSA).
- Raises:
AttributeError – If local ID details are not available (e.g., .fit(X) has not been called).
- property TopoMAP
2D MAP layout computed on the DM refined graph (P_of_Z).
- property msTopoMAP
2D MAP layout computed on the msDM refined graph (P_of_msZ).
- property TopoPaCMAP
2D PaCMAP layout computed on the DM refined graph (P_of_Z).
- property msTopoPaCMAP
2D PaCMAP layout computed on the msDM refined graph (P_of_msZ).
- Y(key: str = 'msTopoMAP')
Return a 2D embedding by stable alias (backwards compatible).
Aliases
‘TopoPaCMAP’ -> PaCMAP on DM refined graph ‘msTopoPaCMAP’-> PaCMAP on msDM refined graph
np.ndarray shape (n_samples, 2)
- set_refined_from_precomputed(knn, *, multiscale: bool = True, coords=None)
Install a precomputed refined neighbor graph (CSR) and rebuild the corresponding kernel.
- Parameters:
knn (csr_matrix) – Precomputed neighbor graph for the scaffold coordinates.
multiscale (bool, default True) – If True, sets msZ kernel; else Z (DM) kernel.
coords (np.ndarray or None) – The scaffold coordinates used to build knn (for neighborhood expansion kernels).
- eigenspectrum(eigenbasis_key=None, **kwargs)
Scree plot helper (calls topo.plot.decay_plot).
Behavior
UoM enabled: plots one scree per disconnected component using the active mode
(self._uom_active_mode, default ‘msDM’). Titles include component index and size. - Non-UoM: behaves as before, plotting the selected/global eigenbasis.
- plot_eigenspectrum(eigenbasis_key=None, **kwargs)
Alias for eigenspectrum.
- list_eigenbases()
List keys in EigenbasisDict (legacy/benchmarking).
- transform(X=None, **kwargs)
DEPRECATED: all computations now happen during .fit(). Returns the msDM graph kernel matrix for backward compatibility.
- spectral_layout(graph=None, n_components=2)
Multicomponent spectral layout of a (precomputed) graph kernel. Stores result in SpecLayout and returns it (used for layout init). In UoM mode, defaults to the UoM msZ operator if no graph is provided.
- project(n_components=2, init=None, projection_method=None, landmarks=None, landmark_method='kmeans', n_neighbors=None, num_iters=300, multiscale=False, save_every=None, save_limit=None, save_callback=None, include_init_snapshot=True, **kwargs)
Compute a 2D projection and store it in ProjectionDict. In UoM mode, graph-based methods use UoM block-diagonal affinities; coordinate-based methods use UoM concatenated scaffolds. This guarantees zero cross-component edges.
- Parameters:
n_components (int (default 2)) – Number of output dimensions.
init (np.ndarray or str (optional)) – Initial coordinates for layout optimization. If a string, must be a key in ProjectionDict. If None, spectral layout is used.
projection_method (str (optional, default 'Isomap').) –
Which projection method to use. Only ‘Isomap’, ‘t-SNE’ and ‘MAP’ are implemented out of the box. ‘t-SNE’ uses and ‘MAP’ relies on code that is adapted from UMAP. Current options are:
’Isomap’ - one of the first manifold learning methods
[‘t-SNE’](https://github.com/DmitryUlyanov/Multicore-TSNE) - a classic manifold learning method
’MAP’- a lighter [UMAP](https://umap-learn.readthedocs.io/en/latest/index.html) with looser assumptions
[‘UMAP’](https://umap-learn.readthedocs.io/en/latest/index.html)
[‘PaCMAP’](http://jmlr.org/papers/v22/20-1061.html) (Pairwise-controlled Manifold Approximation and Projection) - for balanced visualizations
[‘TriMAP’](https://github.com/eamid/trimap) - dimensionality reduction using triplets
’IsomorphicMDE’ - [MDE](https://github.com/cvxgrp/pymde) with preservation of nearest neighbors
’IsometricMDE’ - [MDE](https://github.com/cvxgrp/pymde) with preservation of pairwise distances
’NCVis’ - [Noise Contrastive Visualization](https://github.com/stat-ml/ncvis) - a UMAP-like method with blazing fast performance
These are frankly quite direct to add, so feel free to make a feature request if your favorite method is not listed here.
landmarks (int or np.ndarray (optional)) – Number of landmarks or indices of landmark samples. If None, no landmarks are used.
landmark_method (str (default 'kmeans')) – Landmark selection method (if landmarks is an int). One of {‘random’, ‘kmeans’).
n_neighbors (int (optional)) – Number of neighbors for graph-based methods. If None, uses self.graph_knn.
num_iters (int (default 300)) – Number of optimization epochs for layout optimization.
multiscale (bool (internal, default False)) – If True, use msDM refined graph; else use DM refined graph.
save_every – Passed through to MAP checkpointing. Ignored by other methods.
save_limit – Passed through to MAP checkpointing. Ignored by other methods.
save_callback – Passed through to MAP checkpointing. Ignored by other methods.
include_init_snapshot – Passed through to MAP checkpointing. Ignored by other methods.
Notes
For graph-based DR methods we pass precomputed affinities from the chosen refined graph: {MAP, UMAP, Isomap, (Iso/Isomorphic)MDE, PaCMAP, NCVis, TriMAP, t-SNE}.
- find_ideal_projection(min_dist_grid=[0.2, 0.6, 1.0], spread_grid=[0.8, 1.2, 1.6], initial_alpha_grid=[0.4, 1.0, 1.6], *, multiscale: bool = True, num_iters: int = 600, save_every: int = 10, metric: str = 'euclidean', n_neighbors: int = 30, backend: str = 'hnswlib', n_jobs: int = -1, times=(1, 2, 4), r: int = 32, k_for_pf1: int = None, symmetric_hint: bool = True, verbosity: int = 1)
Grid-search MAP hyperparameters (min_dist, spread, initial_alpha), evaluate each run against the reference operator P, and select the best final 2-D projection.
- Returns:
dict with keys – ‘best_params’ : dict ‘best_score’ : float (TopoPreserve composite) ‘scores’ : list of dicts per combo ‘best_snapshots’ : list of snapshot dicts (each has ‘metrics’ + ‘hyperparams’)
- visualize_optimization(num_iters: int = 600, save_every: int = 10, dpi: int = 120, color=None, *, multiscale: bool = True, filename: str = None, point_size: float = 3.0, fps: int = 20, include_init_snapshot: bool = True, overlay_metrics: bool = False)
- run_models(X, kernels=['fuzzy', 'cknn', 'bw_adaptive'], eigenmap_methods=['DM', 'LE', 'top'], projections=['Isomap', 'MAP'])
Legacy power function that runs multiple models for benchmarking. Preserved for backward compatibility.
- write_pkl(filename='topograph.pkl', remove_base_class=True)
Save the TopOGraph object to a pickle file (legacy helper).
- _compute_kernel_from_version_knn(knn, n_neighbors, kernel_version, results_dict, prefix='', suffix='', low_memory=False, base=True, data_for_expansion=None)
- global_id_mle()
Return the global MLE intrinsic dimensionality if computed.
- Returns:
float or None
- global_id_fsa()
Return the quantile-based FSA intrinsic dimensionality if computed.
- Returns:
float or None
- spectral_selectivity(Z=None, evals=None, multiscale: bool = True, use_scaffold_components: bool = True, weight_mode: str = 'lambda_over_one_minus_lambda', standardize: bool = True, k_neighbors: int = 30, metric: str = 'euclidean', smooth_P: str | None = None, smooth_t: int = 0, out_prefix: str = 'spectral', return_dict: bool = True, random_state: int | None = None)
- Compute per-sample spectral selectivity diagnostics:
EAS (axis selectivity via spectral entropy)
RayScore (sigmoid of radial z-score * EAS)
LAC (local axial coherence = EVR1 of local PCA)
axis (argmax energy axis), axis_sign, radius (||Z||2)
- Parameters:
Z (np.ndarray, optional) – Scaffold coordinates (n, m). If None, uses spectral_scaffold(multiscale).
evals (np.ndarray, optional) – Eigenvalues for weighting. If None, uses the corresponding eigenvalues from the chosen scaffold.
multiscale (bool (default True)) – Choose msDM (True) or DM (False) scaffold if Z is None.
use_scaffold_components (bool (default True)) – If True, slice Z to the number chosen by automated scaffold sizing.
weight_mode ({'lambda_over_one_minus_lambda','lambda', 'none'}) – Weighting of axes in EAS.
standardize (bool (default True)) – Column-standardize Z before metrics.
k_neighbors (int (default 30)) – Neighborhood size for local metrics (radiality, LAC).
metric (str (default 'euclidean')) – Metric for neighborhood search.
smooth_P ({'X','Z','msZ', None} (default None)) – Optional diffusion smoothing of scalar fields with P^t.
smooth_t (int (default 0)) – Number of diffusion steps for smoothing (if smooth_P is not None).
out_prefix (str (default 'spectral')) – Keys used when storing to self.LocalScoresDict.
return_dict (bool (default True)) – If True, return a dictionary with results.
random_state (int or None) – RNG for any randomized steps.
- Returns:
dict or None – {‘EAS’,’RayScore’,’LAC’,’axis’,’axis_sign’,’radius’} arrays if return_dict=True.
- _select_P_operator(which: str = 'msZ')
Internal: choose a diffusion operator.
- Parameters:
which ({'X','Z','msZ'}) –
‘X’ : P_of_X (input space)
’Z’ : P_of_Z (DM-based refined operator)
’msZ’ : P_of_msZ (msDM-based refined operator)
- filter_signal(signal, t: int = 8, which: str = 'msZ')
Diffusion-filter a 1D signal over the chosen graph operator.
- Parameters:
signal (array-like, shape (n,)) – Scalar per-sample values to be smoothed.
t (int (default 8)) – Number of diffusion steps (applications of P).
which ({'X','Z','msZ'} (default 'msZ')) – Which operator to use (see _select_P_operator).
- Returns:
np.ndarray, shape (n,) – Filtered signal.
- pseudotime(root: int | None = None, labels: numpy.ndarray | None = None, label_value: object | None = None, multiscale: bool = True, k: int = 64, weight_mode: str = 'lambda_over_one_minus_lambda', null_n_seeds: int = 0, random_state: int | None = 42, return_null: bool = True)
Compute a diffusion-based pseudotime on the chosen spectral scaffold.
- Parameters:
root (int or None) – Index of the root cell. If None and labels/label_value is given, a random root from that subset is chosen; otherwise a global random root is used.
labels (array-like or None) – Per-sample labels for root selection (optional).
label_value (any or None) – Choose root from samples where labels == label_value.
multiscale (bool (default True)) – Use msDM scaffold if True, else DM.
k (int (default 64)) – Number of spectral coordinates to use (after dropping the trivial one).
weight_mode ({'lambda_over_one_minus_lambda','lambda','none'}) – Axis weighting for MSDD coordinates.
null_n_seeds (int (default 0)) – If >0, compute null mean/std over randomized roots.
random_state (int or None) – RNG seed.
return_null (bool (default True)) – If True, return (mean,std) of null as well.
- Returns:
dict – {‘pseudotime’,’root’, ‘null_mean’,’null_std’} (the latter two present if requested)
- impute(X, t: int = 8, which: str = 'msZ', output: str = 'auto', dtype=np.float64)
- riemann_diagnostics(Y: numpy.ndarray | None = None, L: numpy.ndarray | None = None, center: str = 'median', diffusion_t: int = 0, diffusion_op: str | None = None, normalize: str = 'symmetric', clip_percentile: float = 2.0, return_limits: bool = True, compute_metric: bool = True, compute_scalars: bool = True, random_state: int | None = 7)
- eval_models_layouts(X, landmarks=None, kernels=['cknn', 'bw_adaptive'], eigenmap_methods=['msDM', 'DM', 'LE'], projections=['MAP'], additional_eigenbases=None, additional_projections=None, landmark_method='random', n_neighbors=5, n_jobs=-1, cor_method='spearman', **kwargs)
Evaluate orthogonal bases, topological graphs and layouts against geodesic correlations and a PCA baseline. Kept for backward compatibility.
- topo.load_topograph(filename: str) TopOGraph
Load a TopOGraph object from a pickle file.
- Parameters:
filename (str) – Path to a previously pickled TopOGraph.
- Returns:
TopOGraph – The loaded object.
- topo.save_topograph(tg: TopOGraph, filename: str = 'topograph.pkl', remove_base_class: bool = True)
Save a TopOGraph object to a pickle file.
- Parameters:
tg (TopOGraph) – The object to save.
filename (str) – Destination path.
remove_base_class (bool) – If True, clears tg.base_nbrs_class before pickling to avoid non-serializable ANN handles.
- topo.__version__ = '1.1.0'