fioco 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fioco-1.0.1/API.md +151 -0
- fioco-1.0.1/DOCUMENTATION.md +100 -0
- fioco-1.0.1/LICENSE +674 -0
- fioco-1.0.1/LICENSES/nanoflann.txt +29 -0
- fioco-1.0.1/MANIFEST.in +7 -0
- fioco-1.0.1/PKG-INFO +91 -0
- fioco-1.0.1/README.md +65 -0
- fioco-1.0.1/examples/data/synthetic.npz +0 -0
- fioco-1.0.1/examples/quickstart.ipynb +610 -0
- fioco-1.0.1/examples/synthetic_experiment.ipynb +554 -0
- fioco-1.0.1/fioco/__init__.py +11 -0
- fioco-1.0.1/fioco/_io.py +96 -0
- fioco-1.0.1/fioco/_native/assignment.cpp +188 -0
- fioco-1.0.1/fioco/_native/assignment.hpp +24 -0
- fioco-1.0.1/fioco/_native/bindings.cpp +119 -0
- fioco-1.0.1/fioco/_native/common.hpp +156 -0
- fioco-1.0.1/fioco/_native/engine.cpp +286 -0
- fioco-1.0.1/fioco/_native/engine.hpp +151 -0
- fioco-1.0.1/fioco/_native/graph_state.cpp +274 -0
- fioco-1.0.1/fioco/_native/multigtm.cpp +456 -0
- fioco-1.0.1/fioco/_native/nanoflann.hpp +4099 -0
- fioco-1.0.1/fioco/_native/nearest_search.cpp +310 -0
- fioco-1.0.1/fioco/_utils.py +53 -0
- fioco-1.0.1/fioco/flow/__init__.py +2 -0
- fioco-1.0.1/fioco/flow/conditional.py +349 -0
- fioco-1.0.1/fioco/localgng/__init__.py +2 -0
- fioco-1.0.1/fioco/localgng/model.py +295 -0
- fioco-1.0.1/fioco/multigtm/__init__.py +2 -0
- fioco-1.0.1/fioco/multigtm/_backend.py +336 -0
- fioco-1.0.1/fioco/multigtm/_background.py +57 -0
- fioco-1.0.1/fioco/multigtm/_initialize.py +160 -0
- fioco-1.0.1/fioco/multigtm/_memory.py +268 -0
- fioco-1.0.1/fioco/multigtm/_memory_fit.py +256 -0
- fioco-1.0.1/fioco/multigtm/model.py +377 -0
- fioco-1.0.1/fioco/partitioning/__init__.py +5 -0
- fioco-1.0.1/fioco/partitioning/_graph.py +80 -0
- fioco-1.0.1/fioco/partitioning/_merge.py +82 -0
- fioco-1.0.1/fioco/partitioning/_models.py +75 -0
- fioco-1.0.1/fioco/partitioning/hierarchy.py +30 -0
- fioco-1.0.1/fioco/partitioning/moments.py +143 -0
- fioco-1.0.1/fioco/partitioning/surface.py +145 -0
- fioco-1.0.1/fioco/visualization/__init__.py +171 -0
- fioco-1.0.1/fioco/visualization/_surface.py +84 -0
- fioco-1.0.1/fioco.egg-info/PKG-INFO +91 -0
- fioco-1.0.1/fioco.egg-info/SOURCES.txt +50 -0
- fioco-1.0.1/fioco.egg-info/dependency_links.txt +1 -0
- fioco-1.0.1/fioco.egg-info/not-zip-safe +1 -0
- fioco-1.0.1/fioco.egg-info/requires.txt +20 -0
- fioco-1.0.1/fioco.egg-info/top_level.txt +1 -0
- fioco-1.0.1/pyproject.toml +40 -0
- fioco-1.0.1/setup.cfg +4 -0
- fioco-1.0.1/setup.py +14 -0
fioco-1.0.1/API.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
The classes below follow the order of a typical fioco run. `fit()` returns the fitted object, feature indices start at zero, and input matrices have observations in rows. See [Using fioco](DOCUMENTATION.md) for an explanation of the workflow.
|
|
4
|
+
|
|
5
|
+
## ConditionalFlow
|
|
6
|
+
|
|
7
|
+
Train paired conditional densities and keep one residual score per input row.
|
|
8
|
+
|
|
9
|
+
| Method | What it does |
|
|
10
|
+
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
11
|
+
| `fit(X, *, target=1, context=None)` | Fit the ensemble. `target` is a column index or a sequence. The default context is every other column. |
|
|
12
|
+
| `select(*, score="score_res", percentage=None, positive=False)` | Return a `FlowSelection` from the fitted scores. |
|
|
13
|
+
| `ConditionalFlow.from_scores(X, *, score_res, score_res_snr, strategy="adaptive", n_runs=None)` | Import two existing score arrays in the same row order as `X`. |
|
|
14
|
+
|
|
15
|
+
Use a finite numeric matrix. Target and context columns are standardised separately inside `fit()`. Pass them in their original units.
|
|
16
|
+
|
|
17
|
+
| Settings | Default and meaning |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| Ensemble | `strategy="adaptive"`, `min_runs=8`, `max_runs=20`, `check_every=2`, `patience=2`. `strategy="fixed"` runs exactly `n_seeds=20` pairs. |
|
|
20
|
+
| Training | `train_steps=300` optimizer updates per model, `train_batch=2048`, `learning_rate=1e-3`, `weight_decay=1e-5` |
|
|
21
|
+
| Network | `transforms=4`, `hidden_features=(128, 128)`, `bins=16` |
|
|
22
|
+
| Smoothing | `sigma_smooth=0.3`, measured in standardised target units |
|
|
23
|
+
| Repeatability | `random_state=0`. Use a nonnegative integer to choose the random sequence for model initialisation, batch order, smoothing noise and adaptive training pools. The default preserves the original sequence. |
|
|
24
|
+
| Execution | `score_batch=8192`, `device="auto"`, `progress=True`, `store_run_scores=False`. Automatic device selection uses CUDA when available. |
|
|
25
|
+
|
|
26
|
+
Adaptive fitting uses an 80% training pool per pair. It checks normalised RMS score drift `<0.05`, Spearman correlation `>0.995`, and Jaccard overlap `>0.97` for the upper 40% of mean residual scores. These three checks must pass for `patience` consecutive checkpoints after `min_runs`. The final selection percentage is independent of that monitoring fraction.
|
|
27
|
+
|
|
28
|
+
| Fitted attribute | Contents |
|
|
29
|
+
| ----------------------------------- | --------------------------------------------------------------------------------- |
|
|
30
|
+
| `score_res_` | Mean fine-minus-coarse log density across pairs |
|
|
31
|
+
| `score_res_std_` | Sample standard deviation across pairs |
|
|
32
|
+
| `score_res_snr_` | `score_res_ / (score_res_std_ + 1e-8)` |
|
|
33
|
+
| `n_runs_`, `converged_` | Completed pair count and whether adaptive stopping succeeded |
|
|
34
|
+
| `history_`, `run_timings_` | Checkpoint metrics and timings for each pair |
|
|
35
|
+
| `context_scaler_`, `target_scaler_` | Scikit-learn scalers fitted to the supplied columns |
|
|
36
|
+
| `run_scores_` | Pair-by-observation residual array when `store_run_scores=True`, otherwise `None` |
|
|
37
|
+
|
|
38
|
+
### FlowSelection
|
|
39
|
+
|
|
40
|
+
`select()` accepts `score="score_res"` or `"score_res_snr"`. Its default percentage is 20. The cutoff includes ties, so the selected count can exceed the requested fraction. `positive=True` selects finite scores above zero and cannot be combined with `percentage`.
|
|
41
|
+
|
|
42
|
+
| Attribute | Contents |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `indices` | Selected row indices in the original `X` |
|
|
45
|
+
| `points`, `selected_scores` | Selected observations and scores in matching order |
|
|
46
|
+
| `X`, `scores` | Full input matrix and full score vector |
|
|
47
|
+
| `score_name`, `cutoff`, `method`, `percentage` | How the selection was made |
|
|
48
|
+
|
|
49
|
+
## LocalGNG
|
|
50
|
+
|
|
51
|
+
Learn a graph from selected observations or a numeric matrix.
|
|
52
|
+
|
|
53
|
+
| Method | What it does |
|
|
54
|
+
| ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
55
|
+
| `fit(X, *, features=None, scores=None, scale=False)` | Train on an array or `FlowSelection`. `features` chooses columns in their fitted order. |
|
|
56
|
+
| `assign(X, *, as_rows=False, scaled=True, method="kdtree", batch_size=None, return_distance=False)` | Find the nearest active prototype for each row. |
|
|
57
|
+
| `graph_arrays()` | Return copies of scaled nodes and row-index edges. |
|
|
58
|
+
| `LocalGNG.from_arrays(*, nodes, edges, points, point_node, scores=None, scaler=None, indices=None, node_ids=None, edge_ages=None)` | Restore a graph from coordinates and existing assignments without training. |
|
|
59
|
+
|
|
60
|
+
A `FlowSelection` supplies its scores automatically and estimates scaling on the full source population. Array input uses its values unchanged unless `scale=True`. Pass one score per row to use the graph for partitioning. `from_arrays()` expects nodes and observations in the same input units and estimates a scaler on `points` if none is supplied.
|
|
61
|
+
|
|
62
|
+
| Settings | Defaults |
|
|
63
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
64
|
+
| Size and training | `max_nodes=500`, `n_epochs=20`, `insertion_interval=300`, `shuffle=True`, `sample_fraction=1.0`, `random_state=42` |
|
|
65
|
+
| Prototype updates | `winner_lr=0.2`, `neighbor_lr=0.006`, `insertion_error_decay=0.5`, `global_error_decay=0.995` |
|
|
66
|
+
| Edge rules | `local_length_factor=1.0` (`0` disables length rejection), `max_edge_age=50`, `remove_isolated_nodes=True`, `keep_at_least_active=2` |
|
|
67
|
+
| Training search | `nearest_backend="exact"`. The alternative `"kdtree"` uses `candidate_k=128` and `rebuild_interval=1_000_000`. |
|
|
68
|
+
| Reporting | `progress=True`, `history=False`. Set `history="metrics"` to record epoch summaries. |
|
|
69
|
+
|
|
70
|
+
`nodes_` and `data_` use input units, and `nodes_scaled_` uses graph-scaled coordinates. `edges_` and `point_node_` index rows of `nodes_`, while `indices_` maps fitted observations back to source rows. `active_ids_` preserves native node IDs, which can contain gaps.
|
|
71
|
+
|
|
72
|
+
For `assign()`, supply only the fitted graph columns. Its default assumes scaled coordinates and returns native node IDs. Set `scaled=False` for input-unit coordinates and `as_rows=True` for compact node row indices. `return_distance=True` returns `(labels, distances)`, with Euclidean distances in graph-scaled coordinates.
|
|
73
|
+
|
|
74
|
+
`graph_` is a `GraphResult` containing `nodes`, `edges`, `node_ids`, `support` and `edge_ages`. `graph_.components()` returns connected components as arrays of node rows. Use `summary()` for graph counts, `active_node_ids()` for native IDs, and `edge_array()` for native-ID edges.
|
|
75
|
+
|
|
76
|
+
## SurfaceHierarchy, SurfaceMoments and Partition
|
|
77
|
+
|
|
78
|
+
Build neighbouring-region merge hierarchies and select their lowest-cost cut.
|
|
79
|
+
|
|
80
|
+
| Method | What it does |
|
|
81
|
+
| ------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
|
|
82
|
+
| `SurfaceHierarchy(*, basins=None, progress=True, batch_size=50_000)` | Compare both basin constructions by default. Choose `"ascent"` or `"probabilistic"` to use one. |
|
|
83
|
+
| `fit(gng, *, features=None, scores=None, moments=None)` | Fit using a graph and optional cached moments. |
|
|
84
|
+
| `select()` or `partition(step=None)` | Return the selected `Partition`. Use `step=0` for the starting regions. |
|
|
85
|
+
| `partition_graph(gng, *, basins=None, features=None, scores=None, moments=None, progress=True, batch_size=50_000)` | Fit and return the selected partition in one call. |
|
|
86
|
+
| `SurfaceMoments.from_graph(gng, *, features=None, scores=None, batch_size=50_000, progress=True)` | Cache the regional fitting statistics for reuse. |
|
|
87
|
+
|
|
88
|
+
Choose exactly three graph columns. The default is the first three, or the cached columns when reusing moments. `scores=None` uses `gng.scores_`. Cached moments must match the graph, assignments, observations, scores and scaling.
|
|
89
|
+
|
|
90
|
+
A `SurfaceMoments` object can also be passed as the only input to `fit()`. This returns node partitions without attached observations. Include the matching graph to recover observation labels and pass the partition to MultiGTM.
|
|
91
|
+
|
|
92
|
+
| Fitted attribute | Contents |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `initial_labels_`, `merges_` | Starting node labels and complete merge sequence |
|
|
95
|
+
| `selected_step_`, `node_labels_` | Minimum-cost step and its node labels |
|
|
96
|
+
| `history_` | Step, group count, total cost and selected-step flag |
|
|
97
|
+
| `result_["basins"]` | Basin construction retained by the fit |
|
|
98
|
+
|
|
99
|
+
A `Partition` contains `gng`, `hierarchy`, `level` (merge step), `node_labels`, `point_labels` and `groups`. Group IDs are hierarchy branch IDs and may be nonconsecutive. Unsupported nodes have label `-1`. `summary()` reports node and observation counts per group.
|
|
100
|
+
|
|
101
|
+
## MultiGTM
|
|
102
|
+
|
|
103
|
+
Fit surfaces together, with an optional background component.
|
|
104
|
+
|
|
105
|
+
| Method | What it does |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `fit(partition, X=None, *, features=None, responsibility_out=None, background_data=None)` | Initialise meshes from the partition, then fit the supplied population. |
|
|
108
|
+
| `predict_proba(X=None, *, gated=True, out=None)` | Return one responsibility per observation and mixture component. |
|
|
109
|
+
| `score_samples(X=None, *, out=None)` | Return ungated mixture log density in input units. |
|
|
110
|
+
| `summary()` | Report fitted group sizes, responsibility mass and mixture weights. |
|
|
111
|
+
|
|
112
|
+
`features` selects graph columns and by default it uses the first three, or all columns if there are fewer. `X=None` fits the graph's attached observations. Explicit `X`, `background_data` and prediction arrays must contain only the model columns, in their fitted order and original units. The model reuses the graph's scaling.
|
|
113
|
+
|
|
114
|
+
| Settings | Default and meaning |
|
|
115
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
116
|
+
| Fitting | `n_iter=30` full-population EM updates, `batch_size=2048`, `n_threads=1`, `blas_threads=1`, `progress=True` |
|
|
117
|
+
| Mesh initialisation | `radius=0.4` (local covariance radius is twice this), `rbf_width=2.0`, `latent_dim=2` |
|
|
118
|
+
| Proximity gate | `gate_width=0.5`, `gate_floor=1e-8`. Use `gate_width=None` to disable it. Distances use retained original GNG nodes in scaled model coordinates. |
|
|
119
|
+
| Regularisation | `smooth_lambda=0.03`, `smooth_reference="previous"` (also `"initial"` or `"zero"`), `smooth_relative=True`, `normalize_reg=True` |
|
|
120
|
+
| Background | `background=False`, `background_df=5.0`, `background_scale=1.0`. Enable with the boolean `background=True`. |
|
|
121
|
+
| Early sample stages | `sample_schedule=None`, `random_state=0`. Supply increasing `(fraction_or_count, iterations)` pairs. |
|
|
122
|
+
| Working memory (experimental) | `memory_budget_gib=None` for additional RAM, or `total_memory_budget_gib=None` for a whole-process RAM target. Set at most one. `storage_dir=None` uses the system temporary directory. `memory_reserve=0.2` leaves 20% of the effective budget as headroom. |
|
|
123
|
+
| Per-vertex output | `store_node_responsibilities=False`. Per-component responsibilities are always available. |
|
|
124
|
+
|
|
125
|
+
The Student-t background has a fixed location and shape, with a jointly fitted mixture weight. By default its shape is estimated from `X`. `background_data` supplies an alternative population and requires `background=True`.
|
|
126
|
+
|
|
127
|
+
| Fitted attribute | Contents |
|
|
128
|
+
| ------------------------------- | -------------------------------------------------------------------------------- |
|
|
129
|
+
| `responsibilities_` | Observation-by-component memberships, ordered by `component_groups_` |
|
|
130
|
+
| `assignments_`, `point_groups_` | Winning component-column indices and their group IDs |
|
|
131
|
+
| `groups_`, `component_groups_` | Surface branch IDs. Component IDs also include background `-1` last when enabled |
|
|
132
|
+
| `vertices_`, `edges_` | Fitted meshes in `groups_` order |
|
|
133
|
+
| `priors_` | Learned surface and optional background mixture weights |
|
|
134
|
+
| `initialization_report_` | Which groups produced usable meshes and any covariance repairs |
|
|
135
|
+
| `batch_size_`, `memory_plan_` | Chosen batch size and memory report for a budgeted fit |
|
|
136
|
+
|
|
137
|
+
`X=None` in prediction methods uses the fitted observations. `responsibility_out` and `out` accept a `.npy` path for a float64 memory map or a writable float32/float64 NumPy array of the required shape.
|
|
138
|
+
|
|
139
|
+
### Memory budgets (experimental)
|
|
140
|
+
|
|
141
|
+
With `total_memory_budget_gib`, MultiGTM subtracts current process RAM (RSS) from the requested GiB at the start of `fit()`, `predict_proba()` or `score_samples()`. With `memory_budget_gib`, the requested GiB are additional to that baseline. In either mode the planner accounts for available RAM and leaves the `memory_reserve` fraction as headroom. These are planning estimates. MultiGTM raises `MemoryError` if a required allocation such as the dense solver workspace cannot fit.
|
|
142
|
+
|
|
143
|
+
With either budget, `batch_size=None` lets the planner choose a batch size. An explicit batch size caps its choice. With both budgets unset, `batch_size=None` processes the whole population in one batch.
|
|
144
|
+
|
|
145
|
+
`memory_plan_` reports baseline and observed peak RAM in bytes and the effective additional budget in GiB. In total-budget mode it also includes `requested_total_budget_gib`. The corresponding prediction and scoring reports are `prediction_memory_plan_` and `scoring_memory_plan_`.
|
|
146
|
+
|
|
147
|
+
## Save, inspect and plot
|
|
148
|
+
|
|
149
|
+
Use `result.save(path)` for a fioco NPZ, then `Class.load(path)` or `fioco.load(path)` to read it. `ConditionalFlow`, `LocalGNG` and `MultiGTM` provide `get_params()` for their constructor settings.
|
|
150
|
+
|
|
151
|
+
`plot()` returns a Plotly figure. `columns` chooses the three displayed coordinates, `axis_labels` names them in feature order, and `max_points` limits the display sample. Hierarchy plots accept `n_levels` or explicit `steps`. MultiGTM plots accept `view="surfaces"` or `"responsibilities"`. Use `.show(renderer="browser")` to open a browser or `.write_html("view.html")` to save one.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Using fioco
|
|
2
|
+
|
|
3
|
+
fioco finds curved structures in numeric data, represents them with a graph and fits a mixture of surfaces. This guide explains the choices that matter when using the stages together. See the [API reference](API.md) for signatures and defaults, and the [quickstart notebook](examples/quickstart.ipynb) for a runnable example.
|
|
4
|
+
|
|
5
|
+
## Start with the data and coordinates
|
|
6
|
+
|
|
7
|
+
Supply a finite observation-by-feature matrix `X` with at least three columns. Choose the flow target to describe the conditional density you want to examine, with the remaining columns that can provide context. The target can contain one or several columns.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from fioco import ConditionalFlow, LocalGNG, SurfaceHierarchy, MultiGTM
|
|
11
|
+
|
|
12
|
+
features = [0, 1, 2]
|
|
13
|
+
flow = ConditionalFlow().fit(X, target=1)
|
|
14
|
+
selected = flow.select(score="score_res", percentage=20)
|
|
15
|
+
graph = LocalGNG().fit(selected)
|
|
16
|
+
hierarchy = SurfaceHierarchy().fit(graph, features=features)
|
|
17
|
+
partition = hierarchy.select()
|
|
18
|
+
model = MultiGTM(background=True).fit(partition, features=features)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Feature indices are zero-based. Flow and graph coordinates need not be the same as the three coordinates used for partitioning and surface modelling.
|
|
22
|
+
|
|
23
|
+
## 1. Score observations with paired flows
|
|
24
|
+
|
|
25
|
+
`ConditionalFlow.fit()` standardises target and context columns separately, using all supplied observations. Each pair trains a fine conditional density and a coarse density whose targets receive Gaussian noise. Context stays unchanged, and both densities are evaluated on the original observations. The smoothing width `sigma_smooth` is in standardised target units; its width in input units is `sigma_smooth * flow.target_scaler_.scale_`.
|
|
26
|
+
|
|
27
|
+
A pair contributes the fine-minus-coarse log density. `score_res_` is its ensemble mean, while `score_res_std_` is the sample standard deviation across pairs. `score_res_snr_` divides the mean by that standard deviation plus `1e-8`. It measures consistency across the fits, rather than uncertainty in the ensemble mean.
|
|
28
|
+
|
|
29
|
+
Adaptive fitting draws an 80% training pool without replacement for each pair. The fine and coarse models share its shuffled minibatch order, and `train_steps` counts optimizer updates per model. At each checkpoint, stopping checks mean-score drift, rank correlation and overlap of the upper 40% of mean residual scores. All three checks must pass for `patience` consecutive checkpoints. Fixed fitting instead uses the full training pool and runs exactly `n_seeds` pairs.
|
|
30
|
+
|
|
31
|
+
Use `ConditionalFlow(random_state=7)` to choose a different random sequence for an ensemble. The seed controls model initialisation, shuffled batches, smoothing noise and the adaptive training pools. Keeping `random_state=0` preserves the original sequence. Each pair still has its own seeds within the ensemble.
|
|
32
|
+
|
|
33
|
+
Select by `score_res` or `score_res_snr`. A percentage cut includes ties. `positive=True` keeps positive scores. These are score-based selections, without a calibrated false-positive rate. `ConditionalFlow.from_scores()` imports scores calculated elsewhere.
|
|
34
|
+
|
|
35
|
+
## 2. Represent the selection with LocalGNG
|
|
36
|
+
|
|
37
|
+
LocalGNG learns prototype positions and their edges. Fitting a `FlowSelection` estimates feature scaling on its full source population and trains on selected rows. With direct array input, use `scale=True` to standardise that array. The default `scale=False` uses the supplied units unchanged.
|
|
38
|
+
|
|
39
|
+
`features` chooses graph columns. Training starts from two observations, inserts nodes during learning and updates the graph over `n_epochs`. A smaller positive `local_length_factor` makes the acceptance rule for new edges stricter and zero disables that length check. `max_nodes` is a cap, so the final active count can be smaller.
|
|
40
|
+
|
|
41
|
+
After training, every fitted observation is assigned to its nearest active prototype in graph-scaled coordinates. `graph.point_node_` contains prototype row indices, and `graph.indices_` maps observations back to source rows. `graph.nodes_` and `graph.data_` retain input units. Use `graph.summary()` to check node counts and connectivity before partitioning.
|
|
42
|
+
|
|
43
|
+
## 3. Group the graph nodes
|
|
44
|
+
|
|
45
|
+
The hierarchy ranks supported nodes by their mean assigned score. Ascent follows the highest-ranked uphill neighbour, while probabilistic ascent chooses the most likely peak under uniform uphill moves. Disconnected pieces of a basin become separate starting regions.
|
|
46
|
+
|
|
47
|
+
Regional models use the attached observations in three graph columns and their standardised scores. Polynomial moments are cached per prototype and summed when regions merge, so candidate fits do not repeatedly scan the data. Each candidate union gets its own PCA frame and quadratic fits for normal position and score.
|
|
48
|
+
|
|
49
|
+
The regional cost combines a weighted Gaussian fit, fitted region proportions and a fixed complexity charge. With `W` supported prototypes and `N` selected observations, each observation has weight `W/N`. The implemented cost is `L(R) - m_R * log(m_R / W) + 12 * log(W)`, where `m_R = W * n_R / N`, and uses graph resolution as the fit-versus-complexity scale.
|
|
50
|
+
|
|
51
|
+
Only adjacent regions merge. The complete merge sequence includes cost-increasing steps, and selection returns the earliest occurrence of its lowest total cost, including the starting partition. By default both basin constructions are tried and the lower-cost result is kept. A cut can join starting basins but cannot split one.
|
|
52
|
+
|
|
53
|
+
Use `hierarchy.partition(step=0)` for the starting regions, `history_` for costs and group counts, and `hierarchy.plot()` to browse cuts. Cache `SurfaceMoments` when comparing basin constructions on the same graph.
|
|
54
|
+
|
|
55
|
+
## 4. Fit surfaces jointly
|
|
56
|
+
|
|
57
|
+
MultiGTM builds a mesh from each usable region's largest connected graph component. Its initial covariances use the region's attached observations. The meshes then compete for observations in a joint expectation-maximisation fit. `initialization_report_` explains which regions produced meshes.
|
|
58
|
+
|
|
59
|
+
The proximity gate favours a mesh when an observation is near its retained original GNG nodes, measured in scaled model coordinates. The gate stays fixed as the fitted mesh moves. `gate_width=None` disables it. Regularisation controls changes in neighbouring mesh vertices and `smooth_reference` chooses the previous, initial or zero coefficient reference.
|
|
60
|
+
|
|
61
|
+
With `background=True`, a Student-t density competes with the surfaces. Its shape is fixed from the fitting population, or from `background_data` if supplied and its mixture weight is learned jointly. To fit the full input population, provide only the model columns, in their fitted order and original units:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
X_model = X[:, graph.features_[features]]
|
|
65
|
+
model = MultiGTM(background=True).fit(
|
|
66
|
+
partition, X_model, features=features,
|
|
67
|
+
responsibility_out="responsibilities.npy",
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`partition.point_labels` contains hard graph-region labels. `model.responsibilities_` contains memberships whose columns follow `component_groups_`, the background is last and has group ID `-1`. `assignments_` gives winning column indices and `point_groups_` their group IDs. Use `predict_proba()` for new observations and `score_samples()` for ungated mixture log density in input units. A large membership means preference among fitted components, rather than high absolute density.
|
|
72
|
+
|
|
73
|
+
## Larger runs, plots and saved results
|
|
74
|
+
|
|
75
|
+
`batch_size` limits observation buffers. Each EM update accumulates statistics over the whole current population before updating parameters. Use `responsibility_out` for a disk-backed `.npy` probability array.
|
|
76
|
+
|
|
77
|
+
For a total process RAM target, set `total_memory_budget_gib` (experimental). MultiGTM measures the RAM already in use, including any input slice created before the call. It then plans batches and disk-backed arrays with the remaining headroom. For example, with 2.5 GiB already in use and a 4 GiB target, the planner starts with up to 1.5 GiB of additional RAM before its default safety margin. Use `memory_budget_gib` instead if you want to specify that additional amount directly. Each setting is a planning estimate.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
model = MultiGTM(
|
|
81
|
+
background=True,
|
|
82
|
+
total_memory_budget_gib=4.0,
|
|
83
|
+
batch_size=None,
|
|
84
|
+
storage_dir="multigtm_work",
|
|
85
|
+
).fit(
|
|
86
|
+
partition, X_model, features=features,
|
|
87
|
+
responsibility_out="responsibilities_budgeted.npy",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
print(model.batch_size_)
|
|
91
|
+
print(model.memory_plan_["observed_peak_rss_bytes"] / 2**30)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Here `batch_size=None` lets MultiGTM choose the batch size. The peak reported above is the observed process RAM in GiB. MultiGTM also recalculates the available budget for prediction and scoring calls.
|
|
95
|
+
|
|
96
|
+
An optional `sample_schedule`, such as `[(0.1, 5), (0.3, 5)]`, fits nested 10% and 30% samples before the full population receives `n_iter` updates. Parameters carry forward between stages.
|
|
97
|
+
|
|
98
|
+
Save any stage with `.save(path)` and reopen it with `fioco.load(path)`. Saved flow scores let you change selection percentages without retraining. Saved MultiGTM models can predict new rows. Plots return Plotly figures: use `.show(renderer="browser")` or `.write_html("view.html")`. Display sampling changes the plot, not the fitted result.
|
|
99
|
+
|
|
100
|
+
The flow implementation uses [Zuko](https://github.com/probabilists/zuko); graph learning follows Growing Neural Gas and [MiniGNG](https://github.com/eliovr/minigng); surface modelling builds on AGTM in [1-DREAM](https://doi.org/10.1016/j.ascom.2022.100658).
|