API Reference
SOUMAP
soumap.SOUMAP
SOUMAP(
M, som_params=None, umap_params=None, ctrl_params=None
)
Self-Organizing UMAP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
int
|
Number of prototypes. |
required |
som_params
|
SOMParams
|
SOM learning parameters. Defaults to SOMParams(). |
None
|
umap_params
|
UMAPParams
|
UMAP embedding parameters. Defaults to UMAPParams(). |
None
|
ctrl_params
|
CtrlParams
|
Training control parameters. Defaults to CtrlParams(). |
None
|
Examples:
Default parameters:
>>> model = SOUMAP(M=100)
>>> model.fit(X)
Custom parameters:
>>> model = SOUMAP(
... M=100,
... som_params=SOMParams(rho_0=3.0, rho_f=0.3),
... ctrl_params=CtrlParams(total_epochs=200, verbose=False),
... )
Source code in src/soumap/soumap.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
W
property
W
Prototype matrix, shape (M, d). Authoritative copy lives in gtsom.
coords
property
coords
Embedding coordinates, shape (M, 2). Authoritative copy lives in gtsom.embed.
save
save(path)
Save this SOUMAP instance to an HDF5 file.
Serializes all parameter containers (SOMParams, UMAPParams,
CtrlParams), training state, similarity matrices (FSIM, PCADJ),
SOUMAP learning history, and the full GTSOM instance. The file
can be reloaded with :meth:load to resume training or inspect
results without retraining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. Created or overwritten. |
required |
Examples:
>>> model.fit(X, labels=y)
>>> model.save("soumap.h5")
>>> model2 = SOUMAP.load("soumap.h5")
>>> model2.fit(X, labels=y) # resume training
Source code in src/soumap/soumap.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
load
classmethod
load(path)
Load a SOUMAP from an HDF5 file created by :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to an HDF5 file previously created by :meth: |
required |
Returns:
| Type | Description |
|---|---|
SOUMAP
|
Fully reconstructed instance, ready for :meth: |
Examples:
>>> model = SOUMAP.load("soumap.h5")
>>> model.age
200
>>> model.gtsom.plot(color_by='labels')
Source code in src/soumap/soumap.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
fit
fit(X, labels=None)
Run the SOUMAP learning loop.
Alternates between SOM chunks (gtsom.fit) and UMAP embedding updates (build_FSIM + gtsom.update_embedding) for ctrl_params.total_epochs total SOM epochs.
build() must be called before fit(). tune_embed_scale() must be called before build() if parameter calibration is desired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(ndarray, shape(N, d))
|
|
required |
labels
|
(array - like, shape(N))
|
Observation labels passed through to GTSOM for prototype-level label summaries. Not used by the SOUMAP learning algorithm. |
None
|
Returns:
| Type | Description |
|---|---|
self
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If build() has not been called yet. |
Source code in src/soumap/soumap.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
transform
transform(X)
Map observations to output space via BMU lookup.
Each observation is assigned to its nearest prototype (BMU) and the embedding coordinates of that prototype are returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(ndarray, shape(N, d))
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
coords |
(ndarray, shape(N, 2))
|
|
Source code in src/soumap/soumap.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
fit_transform
fit_transform(X, labels=None)
Run the SOUMAP learning loop and return embedding coordinates for X.
Equivalent to fit(X, labels).transform(X). build() must be called before fit_transform().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(ndarray, shape(N, d))
|
|
required |
labels
|
(array - like, shape(N))
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
coords |
(ndarray, shape(N, 2))
|
|
Source code in src/soumap/soumap.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
tune_embed_scale
tune_embed_scale(
rho0_scale=0.5, min_dist0_scale=0.5, min_distf_scale=0.5
)
Calibrate rho_0, min_dist, and spread from a uniform random null embedding.
Motivation
In a classical SOM with a fixed lattice, the output topology has a known, regular geometry — prototype spacing is uniform and predictable, so rho and min_dist can be set intuitively relative to the lattice step size (e.g. rho_0 = 2 lattice steps). In SOUMAP, the output topology is data-driven and changes during learning, so there is no fixed lattice to anchor parameter choices.
This method recovers an equivalent reference scale by simulating what the embedding geometry would look like for M completely unstructured (uniform random) prototypes within the embedding space. This null embedding serves as a maximum-entropy reference — the geometry you would expect in the complete absence of cluster structure. Parameters are then set as fractions of the key geometric quantities in this null embedding, giving them a scale-free, interpretable meaning analogous to the fixed-lattice SOM case.
Parameter calibration
rho_0 = null_max_geo_dist * rho0_scale min_dist_0 = null_mean_edge_len * min_dist0_scale min_dist_f = null_mean_edge_len * min_distf_scale
spread is set directly from embedding_range (not from the null geometry) because it parameterizes the x-axis scale of the curve fitted by find_ab_params, which must cover the full range of inter-prototype distances in the embedding:
spread = (embedding_range[1] - embedding_range[0]) / 3
The denominator 3 comes from find_ab_params internals: the curve is fitted over [0, spread * 3], so setting spread = diameter / 3 ensures the fitting domain spans [0, diameter] — the full range of possible distances between prototypes. This is independent of the null geometry and is therefore not a scale parameter.
rho_f is not calibrated here — it should remain close to 1.0 (the default). Reducing rho_f toward 0 causes SOM learning to degenerate toward k-means, as prototype updates become independent of their neighbours.
With default scale factors, min_dist_0 == min_dist_f so min_dist does not anneal. Annealing activates only if asymmetric scale factors are provided.
Theoretical alternatives (not yet implemented)
For a uniform distribution of M points in a 2D square of side length L = embedding_range[1] - embedding_range[0], the following closed-form approximations from stochastic geometry could replace the Monte Carlo sampling:
Mean Delaunay edge length (replaces null_mean_edge_len): E[edge_len] ≈ 0.9 * L / sqrt(M) Source: Miles (1970), random Delaunay tessellations.
Mean nearest-neighbour distance: E[d_nn] ≈ L / (2 * sqrt(M)) Source: Clark & Evans (1954).
These would make calibration fully deterministic and free of sampling variability, at the cost of a slight approximation error (typically < 5% for M >= 20). null_mean_geo_dist does not have an equally clean closed form and would still require Monte Carlo or a cruder approximation (null_mean_edge_len * O(sqrt(M))).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho0_scale
|
float
|
rho_0 = null_max_geo_dist * rho0_scale. Controls how large the initial SOM neighbourhood is relative to the null lattice diameter. rho0_scale=0.5 covers half the null lattice, matching the standard SOM "half the map" initialization convention. |
0.5
|
min_dist0_scale
|
float
|
min_dist_0 = null_mean_edge_len * min_dist0_scale. |
0.5
|
min_distf_scale
|
float
|
min_dist_f = null_mean_edge_len * min_distf_scale. Equal to min_dist0_scale by default, so min_dist does not anneal. |
0.5
|
Returns:
| Type | Description |
|---|---|
self
|
Returns self to allow chaining: model.tune_embed_scale().build(X).fit(X) |
Notes
Annealing schedules for rho, min_dist, and spread are rebuilt after calibration to reflect the new parameter values. Call this method before fit(), not after, to ensure the schedules are correct before training begins.
The Monte Carlo sample is seeded by ctrl_params.random_state for reproducibility. Two runs with the same random_state and M will produce identical calibrated values.
Source code in src/soumap/soumap.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
build
build(X, labels=None)
Construct the SOUMAP architecture from data.
This is the equivalent of GTSOM.from_data() — it constructs the GTSOM instance with the current parameter settings, initializes prototypes via k-means, reduces them to 2D, builds the initial output-space topology, runs the first recall, and takes the initial snapshot (including DR metrics if compute_dr_metrics=True).
Call order:
model = SOUMAP(M=..., som_params=..., umap_params=..., ctrl_params=...)
model.tune_embed_scale() # optional — override rho_0, min_dist
model.build(X, labels=y) # construct architecture
model.gtsom.plot(...) # optional — inspect initial state
model.fit(X, labels=y) # learning loop
FSIM and PCADJ are not computed here — they are computed at the start of the first UMAP step in fit(), ensuring they reflect the prototypes and recall state at that point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(ndarray, shape(N, d))
|
Data matrix. Used to fit k-means prototypes and run initial recall. |
required |
labels
|
(array - like, shape(N))
|
Observation labels passed through to GTSOM for prototype-level label summaries and DR metric computation. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If build() has already been called on this instance. |
Source code in src/soumap/soumap.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
Parameter dataclasses
soumap.SOMParams
dataclass
SOMParams(
rho_0: float = 2.0,
rho_f: float = 1.0,
nbr_topo_alpha_0: float = 0.5,
nbr_topo_alpha_f: float = 0.5,
coord_topo: str = "delaunay",
proto_topo: str = "CONN",
compute_dr_metrics: bool = False,
)
Parameters governing SOM prototype learning.
Attributes:
| Name | Type | Description |
|---|---|---|
rho_0 |
float
|
Initial neighbourhood bandwidth. |
rho_f |
float
|
Final neighbourhood bandwidth. |
nbr_topo_alpha_0 |
float
|
Initial topology-blending weight passed to GTSOM. Controls the mix between Delaunay-lattice-based and CONN-based neighbourhood activations in the SOM update rule: 0.0 = pure CONN (Neural Gas style, data-space neighbours). 1.0 = pure lattice (classical SOM). 0.5 = equal blend (default). |
nbr_topo_alpha_f |
float
|
Final topology-blending weight. Annealing from a low value (CONN-dominant) toward a high value (lattice-dominant) reflects the intuition that early learning should be guided by data-space topology (which is reliable from k-means initialization), while later refinement should respect the evolved embedding topology. |
coord_topo |
str
|
Adjacency graph used to define the SOM output-space topology. Passed to GTSOM.from_data() as coord_topo.
|
proto_topo |
str
|
Form of the high-dimensional (data-space) neighbourhood used when blending CONN topology into the SOM update rule (i.e. when nbr_topo_alpha < 1). Passed to GTSOM.init().
|
compute_dr_metrics |
bool
|
If True, compute DR quality metrics (trustworthiness, continuity, and related topology-preservation criteria) at each GTSOM snapshot. Metrics are stored in learn_history_ and displayed as a caption on plots. Passed directly to GTSOM.compile(). Adds computational overhead — disable for speed when not needed. Default False. |
soumap.UMAPParams
dataclass
UMAPParams(
update_freq: int = 5,
n_epochs: int = 100,
min_dist_0: float = 0.01,
min_dist_f: float = 0.01,
spread_0: float = 2.0,
spread_f: float = 2.0,
lrate_0: float = 1.0,
lrate_f: float = 0.1,
negative_sample_rate: int = 5,
gamma: float = 1.0,
use_standard_umap: bool = False,
)
Parameters governing UMAP embedding updates.
Attributes:
| Name | Type | Description |
|---|---|---|
update_freq |
int
|
Number of SOM epochs between consecutive UMAP embedding updates. |
n_epochs |
int
|
Number of UMAP layout optimizer epochs per embedding update. |
min_dist_0 |
float
|
Initial UMAP min_dist parameter. |
min_dist_f |
float
|
Final UMAP min_dist parameter. |
spread_0 |
float
|
Initial UMAP spread parameter. Default is 2.0, derived from the default embedding_range (-3, 3) as (hi - lo) / 3 = 6 / 3 = 2.0. This ensures find_ab_params fits its curve over [0, diameter], covering the full range of inter-prototype distances. If you change embedding_range in CtrlParams, call tune_embed_scale() which sets this automatically. |
spread_f |
float
|
Final UMAP spread parameter. Defaults to spread_0 so spread does not anneal. Set asymmetrically only if you want spread to change over training. |
lrate_0 |
float
|
Initial UMAP layout optimizer learning rate. |
lrate_f |
float
|
Final UMAP layout optimizer learning rate. |
negative_sample_rate |
int
|
Number of negative samples per positive sample in the UMAP layout optimizer. |
gamma |
float
|
Repulsion strength in the UMAP layout loss. Higher values push non-neighbor prototypes further apart. Default 1.0 is the standard UMAP setting. |
use_standard_umap |
bool
|
Diagnostic flag. If True, bypasses FSIM entirely and runs a standard UMAP call on the current prototype matrix W at each embedding update step, using UMAP's own kNN similarity graph (default n_neighbors=15) warm-started from current coords. Useful for isolating whether cluster quality issues stem from FSIM construction or from the SOM step itself. Default False. |
soumap.CtrlParams
dataclass
CtrlParams(
total_epochs: int = 100,
min_nhbs: int = 3,
fill_val: float = 0.5,
coord_init: str = "pca",
embedding_range: tuple = (-3.0, 3.0),
n_jobs: int = None,
random_state: int = None,
verbose: bool = True,
plot_every: int = 0,
)
Parameters governing training control and initialization.
Attributes:
| Name | Type | Description |
|---|---|---|
total_epochs |
int
|
Total number of SOM epochs to run. Controls parameter annealing: all schedules decay from initial to final value over this many epochs (halflife at total_epochs / 2). |
min_nhbs |
int
|
Minimum number of neighbors required per row in PCADJ before similarity construction. Rows below this are padded with synthetic edges. |
fill_val |
float
|
Edge weight for synthetic PCADJ padding edges. |
coord_init |
str
|
Method for initializing embedding coordinates from prototypes W. Options: 'pca', 'le', 'random'. Passed to GTSOM.from_data(). |
embedding_range |
tuple of float
|
Target coordinate range for each axis of the embedding. After each UMAP update, coordinates are rescaled to fit within this range via scale_coords(). Also used by tune_embed_scale() to derive spread = (hi - lo) / 3. |
n_jobs |
int or None
|
Number of parallel jobs. Passed to GTSOM (numba parallelism for prototype updates) and converted to a boolean for the UMAP layout optimizer (parallel=True if n_jobs != 1). Set to 1 for fully sequential execution (enables reproducibility). None uses all available cores. |
random_state |
int or None
|
Random seed for reproducibility. Note: parallel execution (n_jobs != 1) in the UMAP optimizer uses fresh random samples each call regardless of random_state. Set n_jobs=1 for fully deterministic UMAP steps. |
verbose |
bool
|
If True, print progress during fit(). |
plot_every |
int
|
Plot the SOM embedding every this many UMAP update steps. Set to 0 to disable in-training plotting. The initialization state is always plotted if plot_every > 0. |
MPEC
soumap.MPEClustering
MPEClustering(
walktrap_n_steps: int | str = "auto",
kernel_w_cadj: float = 1.0,
kernel_w_high_d: float = 1.0,
kernel_w_low_d: float = 1.0,
kernel_power: float = 2.0,
kernel_min_value: float = 0.01,
remove_empty_protos: bool = True,
kernel_min_nhbs: int = 3,
kernel_support: str = "dense",
walktrap_max_steps: int = 15,
verbose: bool = False,
)
Multiview Prototype Embedding & Clustering.
Fuses a CADJ-topology view, a high-D Euclidean view, and a low-D Euclidean view of prototype space into a single weighted graph, then partitions it with the Walktrap community-detection algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
walktrap_n_steps
|
int or 'auto'
|
Number of random-walk steps for the Walktrap algorithm. If
|
"auto"
|
kernel_w_cadj
|
float
|
Fusion weight applied to the CADJ view. |
1.0
|
kernel_w_high_d
|
float
|
Fusion weight applied to the high-D Euclidean kernel view. |
1.0
|
kernel_w_low_d
|
float
|
Fusion weight applied to the low-D Euclidean kernel view. |
1.0
|
kernel_power
|
float
|
Exponent applied to each kernel view before fusion. Values > 1 sharpen inter-view agreement: pairs that are similar in all views receive disproportionately stronger edges, while disagreements are suppressed. Motivated by the kernel combination results of Cortes, Mohri & Rostamizadeh (NeurIPS 2009). |
2.0
|
kernel_min_value
|
float
|
Hard lower bound on kernel values retained after sparsification in
:func: |
0.01
|
remove_empty_protos
|
bool
|
If True, prototypes with empty receptive fields (no data mapped to
them during VQ recall, i.e. zero CADJ row sums) are excluded from
clustering. Their entries in |
True
|
kernel_min_nhbs
|
int
|
Minimum number of neighbours guaranteed per prototype. Does double
duty: passed to :func: |
3
|
kernel_support
|
('dense', 'CADJ')
|
Sparsity pattern used when building the high-D and low-D Euclidean
kernel views (
|
"dense"
|
walktrap_max_steps
|
int
|
Number of steps evaluated when |
15
|
verbose
|
bool
|
If True, print progress messages and warnings during :meth: |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
labels_ |
np.ndarray, shape (M,), dtype int
|
Cluster membership for each prototype (0-indexed). Empty prototypes
(excluded when |
active_labels_ |
np.ndarray, shape (M_active,), dtype int
|
Cluster labels for active (non-empty) prototypes only — equivalent to
|
active_indices_ |
np.ndarray, shape (M_active,), dtype int
|
Indices into the full prototype array of the prototypes that were actually clustered (i.e. the non-empty ones). |
rf_sizes_ |
np.ndarray, shape (M_active,), dtype float
|
Receptive field sizes for active prototypes — CADJ row sums of the active sub-matrix. Reflects how many data points each prototype attracted as first BMU. Useful as point-size weights in visualisation. |
fused_graph_ |
(csr_matrix, shape(M_active, M_active))
|
Symmetric weighted adjacency matrix of the fused graph, defined over the active (non-empty) prototypes only. |
n_steps_ |
int
|
Walktrap step count actually used. |
walktrap_result_ |
VertexClustering
|
Walktrap clustering result. Gives access to modularity, membership, and cluster sizes. |
walktrap_dendrogram_ |
VertexDendrogram
|
Raw Walktrap dendrogram before the optimal cut. Use
|
step_analysis_ |
list of dict or None
|
Per-communicating-class tradeoff analysis from
:func: |
kernel_cadj_ |
(csr_matrix, shape(M_active, M_active))
|
Row-max-normalised CADJ view kernel (before fusion and power). Values in [0, 1]. |
kernel_high_d_ |
(csr_matrix, shape(M_active, M_active))
|
Self-tuning Euclidean kernel on W (high-D view, before fusion and power). Values in (0, 1]. |
kernel_low_d_ |
(csr_matrix, shape(M_active, M_active))
|
Self-tuning Euclidean kernel on Y (low-D view, before fusion and power). Values in (0, 1]. |
Source code in src/soumap/mpec.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
active_labels_
property
active_labels_: ndarray
Cluster labels for active (non-empty) prototypes only.
Equivalent to labels_[active_indices_]. Contains no -1 sentinels
— every entry is a valid cluster index (0-indexed). Raises
RuntimeError if called before :meth:fit.
fit
fit(
W: ndarray,
Y: ndarray,
CADJ: spmatrix,
CADJ_nhbs: list[list[int]] | None = None,
) -> "MPEClustering"
Fit the multiview prototype clustering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
W
|
(ndarray, shape(M, d))
|
Prototype matrix in the original (high-D) feature space. |
required |
Y
|
(ndarray, shape(M, d2))
|
Low-D embedding of the prototypes (e.g. UMAP or PCA coordinates). |
required |
CADJ
|
scipy.sparse matrix, shape (M, M)
|
Asymmetric co-adjacency matrix from VQRecaller. |
required |
CADJ_nhbs
|
list of list of int, length M
|
Precomputed CADJ neighbour index lists. Derived from CADJ's CSR structure if not supplied. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
MPEClustering
|
The fitted instance. Results are available as instance attributes. |
Source code in src/soumap/mpec.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
save
save(path: str) -> None
Save this fitted MPEClustering instance to an HDF5 file.
All parameters, clustering results, kernel matrices, and step
analysis are serialized. igraph objects (walktrap_result_,
walktrap_dendrogram_) are not stored but are recomputed identically
from fused_graph_ and n_steps_ on :meth:load — Walktrap is
deterministic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. Created or overwritten. |
required |
Examples:
>>> mpec.fit(W, Y, CADJ)
>>> mpec.save("mpec.h5")
>>> mpec2 = MPEClustering.load("mpec.h5")
>>> mpec2.plot_diagnostics(embed_coords=Y)
Source code in src/soumap/mpec.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
load
classmethod
load(path: str) -> 'MPEClustering'
Load a MPEClustering from an HDF5 file created by :meth:save.
All parameters and results are restored. walktrap_result_ and walktrap_dendrogram_ are recomputed from the saved fused_graph_ and n_steps_ (Walktrap is deterministic — results are identical).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to an HDF5 file previously created by :meth: |
required |
Returns:
| Type | Description |
|---|---|
MPEClustering
|
Fully reconstructed instance with all plot and diagnostic functionality available immediately. |
Examples:
>>> mpec = MPEClustering.load("mpec.h5")
>>> mpec.n_steps_
4
>>> mpec.plot_diagnostics(embed_coords=Y)
Source code in src/soumap/mpec.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | |
plot_diagnostics
plot_diagnostics(
embed_coords: ndarray | None = None,
show_graph: bool = False,
which: list | str = "all",
max_components: int = 3,
point_size: float = 2.0,
figsize: tuple = (6, 5),
save_dir: str | None = None,
save_format: str = "pdf",
) -> dict
Produce diagnostic plots for the fitted clustering.
Each plot is rendered independently as a separate figure, displayed on screen, and optionally saved to disk. This avoids any dependency on panel-assembly libraries (e.g. patchworklib) and works with any plotnine version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embed_coords
|
(ndarray, shape(M, d))
|
Coordinates for the embedding scatter. First 2 columns are used if d > 2. If None, the embedding plot is skipped. |
None
|
show_graph
|
bool
|
If True, overlay |
False
|
which
|
list of str or "all"
|
Subset of plots to produce. Valid names:
|
"all"
|
max_components
|
int
|
Maximum number of communicating classes shown in the step tradeoff plot. |
3
|
point_size
|
float
|
Base point size for the embedding scatter. |
2.0
|
figsize
|
tuple
|
(width, height) in inches for each individual figure. |
(6, 5)
|
save_dir
|
str or None
|
Directory in which to save figures. If None, figures are shown
on screen only. Files are named
|
None
|
save_format
|
str
|
File format passed to plotnine's |
"pdf"
|
Returns:
| Name | Type | Description |
|---|---|---|
plots |
dict
|
|
Source code in src/soumap/mpec.py
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 | |