API Reference¶
Auto-generated from the docstrings in the source. See Concepts & coming from MATLAB for the MATLAB function-name mapping.
Core pipeline¶
tmapper.tknndigraph
¶
Port of tmapper_tools/tknndigraph.m from the MATLAB toolbox.
tknndigraph(X_or_D, k, tidx, *, reciprocal=True, time_exclude_space=True, time_exclude_range=1, max_neighbor_dist=np.inf, max_neighbor_dist_prct=100.0)
¶
Construct a directed graph based on k-nearest neighbors that also includes temporal neighbors (t -> t+1 links).
Port of MATLAB's tknndigraph.m. Node i of the returned graph
corresponds to row i of X_or_D / element i of tidx (0-indexed,
unlike the 1-indexed MATLAB original).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_or_D
|
(array_like, shape(N, d) or (N, N))
|
Either raw coordinates (N points in d-dim space) or a precomputed (N, N) distance matrix. Auto-detected: treated as a distance matrix only if square and symmetric; otherwise treated as raw coordinates and converted to a Euclidean distance matrix. |
required |
k
|
int
|
Max number of spatial neighbors per point. Must be a positive integer strictly less than N. |
required |
tidx
|
array_like of int, shape (N,)
|
Time index per point. Two points x, y are temporal neighbors iff
|
required |
reciprocal
|
bool
|
Whether to require spatial k-NN links to be mutual (both directions) to be kept. |
True
|
time_exclude_space
|
bool
|
Whether temporal neighbors are barred from also counting as spatial neighbors. |
True
|
time_exclude_range
|
int
|
How many following time points are excluded from spatial-kNN consideration. |
1
|
max_neighbor_dist
|
float
|
Absolute distance cutoff for spatial neighbors. |
inf
|
max_neighbor_dist_prct
|
float
|
Percentile distance cutoff for spatial neighbors. The stricter
(smaller) of this and |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
g |
DiGraph
|
Unweighted directed graph, one node per input point. |
par |
dict
|
Parameters actually used, including the resolved
|
Source code in src/tmapper/tknndigraph.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
tmapper.filtergraph
¶
Port of tmapper_tools/filtergraph.m from the MATLAB toolbox.
filtergraph(g, d, *, reciprocal=True)
¶
Contract a graph g into a simplified graph (a Mapper-style shape
graph) by merging nodes that are within geodesic distance d of one
another.
Port of MATLAB's filtergraph.m. This is the Mapper-style contraction
step: nodes of g within geodesic distance d of each other are
connected in an intermediate graph, and its connected components become
the nodes of the simplified graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph or DiGraph
|
Graph to simplify. |
required |
d
|
float
|
Threshold under which original nodes are collapsed together. Must be a positive real number. |
required |
reciprocal
|
bool
|
Whether to require both the path length from x to y and from y
to x to be under |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
g_simp |
DiGraph
|
The simplified graph -- the attractor transition network. |
members |
list of list
|
|
nodesize |
(ndarray, shape(n_new))
|
Number of original-graph members in each new node. |
D_simp |
(ndarray, shape(n_new, n_new))
|
Shortest "distance" (from the original graph) between each pair of new nodes' member sets. |
Source code in src/tmapper/filtergraph.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
tmapper.find_node_label(members, x_label, *, labelmethod='mode')
¶
Aggregate a per-time-point label to a per-node label.
Port of MATLAB's findnodelabel.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members
|
sequence of sequence of int
|
|
required |
x_label
|
array_like
|
Label/value for each time point (indexed the same way as the
indices inside |
required |
labelmethod
|
(mode, mean, median, none)
|
How to aggregate each node's members' x_label values. A callable
is applied as |
'mode'
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(len(members)))
|
The aggregated label for each node. |
Source code in src/tmapper/labeling.py
tmapper.tcm_distance
¶
Port of tmapper_tools/TCMdistance.m from the MATLAB toolbox.
tcm_distance(g, nodet, weighted=False)
¶
Compute a temporal connectivity matrix: for every pair of original
time points, the shortest path length between the nodes (of a
simplified graph g) that contain them.
Port of MATLAB's TCMdistance.m. Sizes its output by the full range
covered by nodet (max - min + 1), not just the count of
distinct points referenced -- so time points genuinely not covered by
any node in nodet correctly stay NaN rather than being silently
zero-filled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph or DiGraph
|
The simplified graph. |
required |
nodet
|
sequence of sequence of int
|
|
required |
weighted
|
bool
|
Whether to use |
False
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(Nt, Nt))
|
The temporal connectivity matrix, where Nt = max(nodet) - min(nodet) + 1. Entries for time points never covered by any node stay NaN. |
Source code in src/tmapper/tcm_distance.py
tmapper.plot_tmgraph(g, x_label=None, nodemembers=None, *, ax=None, nodesizerange=(1, 10), nodesizemode='log', colorlabel='x_label', cmap='jet', labelmethod='mode', nodeclim=None, nodescatter=False, center_expand=4.0)
¶
Plot a temporal mapper graph (without a recurrence plot).
Port of MATLAB's plottmgraph.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph or DiGraph
|
The graph to plot. |
required |
x_label
|
array_like
|
A label for each member of each node, indexed the same way as the
indices inside |
None
|
nodemembers
|
sequence of sequence of int
|
|
None
|
ax
|
Axes
|
Axes to draw into. A new figure/axes is created if not given. |
None
|
nodesizerange
|
(float, float)
|
(min, max) marker size. |
(1, 10)
|
nodesizemode
|
(log, rank, original)
|
How to transform node sizes before rescaling to |
'log'
|
colorlabel
|
str
|
Colorbar label. |
'x_label'
|
cmap
|
str or Colormap
|
Colormap for node coloring. |
'jet'
|
labelmethod
|
(mode, mean, median, none)
|
See :func: |
'mode'
|
nodeclim
|
(float, float)
|
Color axis limits. Defaults to (min(x_label), max(x_label)). |
None
|
nodescatter
|
bool
|
Whether to overlay a scatter plot on top of the graph nodes. |
False
|
center_expand
|
float
|
Log-radial de-clumping strength applied to the layout after
normalizing it to the unit circle (0 disables it). Force-directed
layouts tend to pack most nodes into a dense central clump with a
few outliers stretching the frame; this spreads the dense core
outward without disturbing the outer structure. See
:func: |
4.0
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
cbar |
Colorbar
|
|
node_collection |
PathCollection
|
The drawn graph nodes. |
scatter_collection |
PathCollection or None
|
The scatter overlay, if |
Source code in src/tmapper/plotting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
tmapper.plot_tmgraph_tcm(g, x_label, t, nodemembers, **kwargs)
¶
Plot a temporal mapper graph alongside its geodesic recurrence plot.
Port of MATLAB's plotgraphtcm.m. Calls :func:plot_tmgraph
internally for the left subplot (all **kwargs are passed through),
so it accepts the same styling parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph or DiGraph
|
The (simplified) graph to plot. |
required |
x_label
|
array_like
|
A label for each time point in the time series. |
required |
t
|
array_like
|
Actual time (or a time index) associated with each time point, used as the recurrence plot's axis labels. |
required |
nodemembers
|
sequence of sequence of int
|
|
required |
**kwargs
|
Passed through to :func: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax1, ax2 : matplotlib.axes.Axes
|
The network plot and recurrence plot axes. |
|
cbar, cbar2 : matplotlib.colorbar.Colorbar
|
|
|
(node_collection, scatter_collection)
|
As returned by :func: |
|
D_geo |
ndarray
|
The recurrence plot matrix. |
Source code in src/tmapper/plotting.py
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 | |
tmapper.plot_tmgraph_interactive(g, x_label=None, nodemembers=None, *, nodesizerange=(6, 40), nodesizemode='log', colorlabel='x_label', cmap='jet', labelmethod='mode', nodeclim=None, center_expand=4.0, title='', output_path=None)
¶
Plot a temporal mapper graph as a draggable/zoomable/hoverable standalone HTML page (via pyvis/vis.js), instead of a static image.
Uses the same layout, node-size, and coloring logic as
:func:plot_tmgraph (so the two should look like the same network),
with physics disabled -- nodes stay exactly where the layout put
them, but can still be dragged, and hovering shows each node's size
and color-label value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph or DiGraph
|
The graph to plot. |
required |
x_label
|
array_like
|
See :func: |
None
|
nodemembers
|
sequence of sequence of int
|
See :func: |
None
|
nodesizerange
|
(float, float)
|
(min, max) node radius in pixels (pyvis/vis.js sizes nodes by
radius, unlike matplotlib's area-based marker size -- so this
default is not directly comparable to :func: |
(6, 40)
|
nodesizemode
|
(log, rank, original)
|
See :func: |
'log'
|
colorlabel
|
str
|
Legend label (rendered as a small embedded colorbar image). |
'x_label'
|
cmap
|
str or Colormap
|
Colormap for node coloring -- anything matplotlib accepts,
including a discrete :class: |
'jet'
|
labelmethod
|
(mode, mean, median, none)
|
See :func: |
'mode'
|
nodeclim
|
(float, float)
|
Color axis limits. Defaults to (min(x_label), max(x_label)). |
None
|
center_expand
|
float
|
See :func: |
4.0
|
title
|
str
|
Page heading (e.g. summarize the construction parameters here). |
''
|
output_path
|
str
|
If given, also write the standalone HTML page to this path.
Default None -- no file is written; use the returned |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
net |
Network
|
The populated network. |
html |
str
|
The standalone HTML page as a string (already includes the
embedded colorbar legend) -- identical to what gets written to
|
Source code in src/tmapper/plotting.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
Standalone graph builders¶
tmapper.knngraph
¶
Port of tmapper_tools/knngraph.m from the MATLAB toolbox.
knngraph(X_or_D, k, *, reciprocal=True)
¶
Construct an undirected graph based on k-nearest neighbors: each point is a node, linked to its k nearest neighbors.
Port of MATLAB's knngraph.m. A standalone graph builder with no
temporal component (unlike :func:tknndigraph).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_or_D
|
(array_like, shape(N, d) or (N, N))
|
Either raw coordinates (N points in d-dim space) or a precomputed (N, N) distance matrix. Auto-detected: treated as a distance matrix only if square and symmetric. |
required |
k
|
int
|
Number of nearest neighbors. Must be a positive integer strictly less than N. |
required |
reciprocal
|
bool
|
Whether to require a k-NN link to be mutual (both directions) to be kept. |
True
|
Returns:
| Type | Description |
|---|---|
Graph
|
Unweighted undirected graph, one node per input point. |
Source code in src/tmapper/knngraph.py
tmapper.cknngraph
¶
Port of tmapper_tools/cknngraph.m from the MATLAB toolbox.
cknngraph(X_or_D, k, delta, *, average=False)
¶
Construct a graph based on continuous k-nearest neighbors (Berry & Sauer, 2019).
Port of MATLAB's cknngraph.m. Connects points x, y iff::
D(x, y) < delta * sqrt(D(x, x_k) * D(y, y_k))
where D(~, ~) is the distance and ~_k is the k-th nearest
neighbor of ~.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_or_D
|
(array_like, shape(N, d) or (N, N))
|
Either raw coordinates (N points in d-dim space) or a precomputed (N, N) distance matrix. Auto-detected: treated as a distance matrix only if square and symmetric. |
required |
k
|
int
|
Used to normalize distance by local point density. Must be a positive integer strictly less than N. |
required |
delta
|
float
|
Threshold for linking two nodes (must be a positive real number). |
required |
average
|
bool
|
Whether |
False
|
Returns:
| Type | Description |
|---|---|
Graph
|
Unweighted undirected graph, one node per input point. |
Source code in src/tmapper/cknngraph.py
Graph & data utilities¶
tmapper.node_size(nodemembers)
¶
tmapper.node_measure(nodemembers)
¶
Number of members in each node, normalized to sum to 1. Port of
nodemeasure.m.
tmapper.normalize_geodesic(geod, nsize=None, *, exclude_diag=False)
¶
Normalize a geodesic distance matrix by node measure.
Port of normgeo.m. Note: unlike the MATLAB original, an omitted
nsize defaults to a uniform vector of ones (equal-size nodes),
which is clearly the intended behavior from the docstring -- the
MATLAB version's ones(N_nodes) (a matrix, not ones(N_nodes,1))
appears to be an unexercised bug in that rarely-hit default-value path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geod
|
(array_like, shape(N, N))
|
Geodesic distance matrix. |
required |
nsize
|
(array_like, shape(N))
|
Size of each node. Defaults to a uniform vector of ones. |
None
|
exclude_diag
|
bool
|
Whether to exclude the diagonal when computing the normalizing factor. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
geod_n |
(ndarray, shape(N, N))
|
Normalized geodesic distance matrix. |
nm |
(ndarray, shape(N))
|
Node measure (probability), sums to 1. |
Source code in src/tmapper/graph_utils.py
tmapper.normalize_tcm(tcm, *, normtype='max', infreplace='max')
¶
Normalize a temporal connectivity matrix by its maximal finite
value (or its norm). Port of normtcm.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tcm
|
array_like
|
Temporal connectivity matrix. |
required |
normtype
|
(max, norm)
|
How to compute the normalizing factor: the matrix's maximum finite value, or its (Frobenius/vector) norm. |
'max'
|
infreplace
|
(max, nan)
|
How to handle inf entries before normalizing: replace with the matrix's maximum finite value, or with NaN. |
'max'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in src/tmapper/graph_utils.py
tmapper.members_to_tidx(members, tidx)
¶
Translate positional-index members to real tidx values.
Port of members2tidx.m. Use this when tidx is non-contiguous
or offset (e.g. real timestamps with gaps): :func:filtergraph's
members output gives positional indices into your original data,
not tidx values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members
|
sequence of sequence of int
|
Positional indices into the original data, e.g. from
:func: |
required |
tidx
|
array_like
|
The same |
required |
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray
|
|
Source code in src/tmapper/graph_utils.py
tmapper.subgraph_from_members(g_simp, members, include_members)
¶
Extract the subgraph of a transition network restricted to a
subset of original time points. Port of subgraphFromMembers.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g_simp
|
Graph or DiGraph
|
The simplified transition network. |
required |
members
|
sequence of sequence of int
|
|
required |
include_members
|
iterable of int
|
The subset of original time points to keep. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
g_sub |
Graph or DiGraph
|
The induced subgraph containing only nodes with at least one
member in |
members_sub |
list of list
|
Members of each node of |
sub_orig_nodeidx |
list of int
|
Positional indices (into the original |
Source code in src/tmapper/graph_utils.py
tmapper.sym_dyn_to_digraph(sym_dyn)
¶
Construct a directed graph from a single time series of symbolic
dynamics. Port of symDyn2digraph.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym_dyn
|
array_like of int
|
A vector of N labels (purely nominal -- numeric differences between labels are irrelevant), one per time point. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dg |
DiGraph
|
One node per unique state in |
dwelltime |
ndarray
|
Number of time points belonging to each state (in the same
order as |
nodemembers |
list of numpy.ndarray
|
|
Source code in src/tmapper/graph_utils.py
tmapper.digraph_to_graph(dg)
¶
Convert a directed graph to an undirected graph, averaging the
weights of the two edges between each pair of nodes. Port of
digraph2graph.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dg
|
DiGraph
|
The directed graph to symmetrize. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
|
Source code in src/tmapper/graph_utils.py
tmapper.find_blocks(indicator)
¶
Find the start, end, and size of contiguous True/1 runs
("blocks") in a 0/1 indicator array. Port of findtaskn.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicator
|
array_like
|
A 1D array of 0s/1s (or booleans). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
block_start |
ndarray
|
0-indexed position of the first sample of each block. |
block_end |
ndarray
|
0-indexed position of the last sample of each block. |
block_size |
ndarray
|
Number of samples in each block. |
Source code in src/tmapper/graph_utils.py
Cycle / path analysis toolkit¶
tmapper.cycle_count
¶
Port of tmapper_tools/CycleCount.m from the MATLAB toolbox.
CycleCount.m is itself a third-party algorithm (not original to the tmapper toolbox), reproduced here under its original license:
Authors: P.-L. Giscard, N. Kriege, R. Wilson, Septembre 2016
Copyright (c) 2017, Pierre-Louis Giscard
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of York nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
cycle_count(A, L0)
¶
Count all simple cycles of length up to L0 (inclusive) on a
graph whose adjacency matrix is A, via the combinatorial-sieve
algorithm of Giscard, Kriege & Wilson (2016).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
(array_like, shape(N, N))
|
Adjacency matrix of the graph (directed or undirected, weighted or unweighted). |
required |
L0
|
int
|
Maximum length of the simple cycles to count. |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(L0))
|
|
Source code in src/tmapper/cycle_count.py
tmapper.cycle_count2p
¶
Port of tmapper_tools/CycleCount2p.m and reorgCycles.m from the MATLAB toolbox.
cycle_count2p(A, *, simple=True)
¶
Estimate the number of cycles of different lengths by finding the smallest cycle passing through every pair of vertices.
Port of MATLAB's CycleCount2p.m. Only counts unique cycles, and
by default only unique simple cycles (no repeated nodes other than
the start/end).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
(array_like, shape(N, N))
|
Adjacency matrix for a simple directed graph. |
required |
simple
|
bool
|
Whether to only count simple cycles. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
cyc_count |
ndarray
|
Number of cycles per unique length (shortest to longest). |
cyc_len |
ndarray
|
The unique cycle lengths themselves (shortest to longest). |
cyc_path |
list of numpy.ndarray
|
|
all_cycles |
list of list
|
Every cycle's path, flattened into a single list. |
Source code in src/tmapper/cycle_count2p.py
reorg_cycles(cyc_path)
¶
Unpack the cyc_path output of :func:cycle_count2p into a flat
list where each element is a single cycle's path.
Port of MATLAB's reorgCycles.m.
Source code in src/tmapper/cycle_count2p.py
tmapper.reorg_cycles(cyc_path)
¶
Unpack the cyc_path output of :func:cycle_count2p into a flat
list where each element is a single cycle's path.
Port of MATLAB's reorgCycles.m.
Source code in src/tmapper/cycle_count2p.py
tmapper.cycle_path_overlap(c, *, cycle=True, overlap_type='edge', grpvar=None)
¶
Calculate the overlap between cycles or paths.
Port of MATLAB's CyclePathOverlap.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
sequence of sequence of int
|
|
required |
cycle
|
bool
|
Whether the paths in |
True
|
overlap_type
|
(edge, node)
|
Whether to calculate overlap between edges or between nodes. |
'edge'
|
grpvar
|
array_like of int
|
A grouping variable for the paths. By default, each path is its own group. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
CO |
(ndarray, shape(P, P))
|
Percent overlap between every pair of groups (1 on the diagonal). |
grpnames |
ndarray
|
The unique group labels, in the same order as |
Source code in src/tmapper/cycle_overlap.py
tmapper.cycle_cluster
¶
Port of tmapper_tools/CycleCluster.m from the MATLAB toolbox.
cycle_cluster(allcycles, thres, *, plotmat=True, plotmds=False, plothist=True, reordermat=True, ax=None, return_ax=False)
¶
Cluster cycles based on the fraction of overlap between them (shared nodes / union of nodes).
Port of MATLAB's CycleCluster.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allcycles
|
sequence of sequence of int
|
|
required |
thres
|
float
|
Cut-off threshold (0-1) for single-linkage clustering: if overlap > thres, two cycles belong to the same cluster. |
required |
plotmat
|
bool
|
Whether to plot the overlap matrix. |
True
|
plotmds
|
bool
|
Whether to plot a 2D classical-MDS projection of the cycles. |
False
|
plothist
|
bool
|
Whether to plot the histogram of linkage distances. |
True
|
reordermat
|
bool
|
Whether to reorder the overlap matrix by cluster assignment. |
True
|
ax
|
Axes
|
Axes for the overlap-matrix plot (only used if |
None
|
return_ax
|
bool
|
If True, also return the axes used for the overlap-matrix plot
(None if |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
ndarray
|
1-indexed cluster label for each cycle (matching MATLAB's
|
|
ax |
Axes or None
|
Only returned if |
Source code in src/tmapper/cycle_cluster.py
tmapper.cycle_cluster_conn
¶
Port of tmapper_tools/CycleClusterConn.m from the MATLAB toolbox.
cycle_cluster_conn(dg, allcycles, cluster_idx)
¶
Connectivity between M clusters of N cycles.
Port of MATLAB's CycleClusterConn.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dg
|
DiGraph
|
The directed graph the cycles/paths live on. |
required |
allcycles
|
sequence of sequence of int
|
|
required |
cluster_idx
|
array_like of int
|
Cluster label of each cycle (e.g. from :func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
cluster_conn |
list of list of set
|
|
cluster_conn_dir |
list of list of set
|
|
clusters_nodes |
list of list
|
All nodes in each cluster (first-seen order). |
clusters_boundary |
list of set
|
Boundary nodes of each cluster. |
clusters_interior |
list of list
|
Nodes of each cluster that are not on its boundary. |
clusters_crtpts |
list of list
|
Critical points (nodes with more than one source or target) in each cluster. |
clusters_intcrtpts |
list of list
|
Critical points in each cluster that are not on its boundary. |
Source code in src/tmapper/cycle_cluster_conn.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
tmapper.cycle_cutter
¶
Port of tmapper_tools/CycleCutter.m from the MATLAB toolbox.
cycle_cutter(cyc, node_name)
¶
Cut a cycle into multiple paths at given nodes.
Port of MATLAB's CycleCutter.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cyc
|
sequence
|
A single cycle's path (node names, usually integers). |
required |
node_name
|
sequence or scalar
|
Names of nodes that are the cutting points of the cycle. Names not contained in the cycle are ignored. |
required |
Returns:
| Type | Description |
|---|---|
list of list
|
Each element is a path from one cutting point to the next.
Wraps around: if there are |
Source code in src/tmapper/cycle_cutter.py
tmapper.cycles_to_paths
¶
Port of tmapper_tools/Cycles2Paths.m from the MATLAB toolbox.
cycles_to_paths(allcycles, cutpts)
¶
Cut a set of cycles to obtain a set of unique paths connecting a set of cutting points (nodes).
Port of MATLAB's Cycles2Paths.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allcycles
|
sequence of sequence of int
|
A list of cycle paths. |
required |
cutpts
|
sequence of int
|
Node indices at which each cycle should be cut (cutting points). |
required |
Returns:
| Type | Description |
|---|---|
list of list
|
Unique paths linking the cutting points, sorted by (length, then lexicographically within each length). |
Source code in src/tmapper/cycles_to_paths.py
tmapper.cycle_path_decomp
¶
Port of tmapper_tools/CyclePathDecomp.m from the MATLAB toolbox.
The MATLAB original's diagonal cluster-block overlay (addDiagBlock.m)
is not ported literally -- it's tightly coupled to MATLAB axes internals
(ax.Children(end).CData) with no Python equivalent. The same visual
annotation is reproduced directly here with matplotlib patches, reusing
:func:tmapper.graph_utils.find_blocks.
cycle_path_decomp(dg, *, clusterthres=0.5, plotmat=True, plotmds=False, plothist=False, reordermat=True)
¶
Cycle-path decomposition of a directed graph.
Port of MATLAB's CyclePathDecomp.m. Cycles on the graph are
first computed, then clustered such that cycles with clusterthres
amount of overlap belong to the same cluster. Boundaries between
clusters of cycles (nodes where one cycle enters into another) are
used to cut cycles into paths, which are then clustered themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dg
|
DiGraph
|
The graph to decompose. |
required |
clusterthres
|
float
|
Overlap threshold for cycle/path clustering. |
0.5
|
plotmat
|
bool
|
Whether to plot the overlap matrices (with cluster-block outlines) for diagnostics. |
True
|
plotmds
|
bool
|
Whether to plot a 2D classical-MDS projection of cycles/paths. |
False
|
plothist
|
bool
|
Whether to plot linkage-distance histograms. |
False
|
reordermat
|
bool
|
Whether to reorder the overlap matrices by cluster assignment. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
allbd |
list
|
All boundary points between cycle clusters (used to cut cycles into paths). |
pclusters_nodes |
list of list
|
Nodes in each path cluster. |
pclusters_interior |
list of list
|
Interior (non-boundary) nodes of each path cluster. |
pclusters_boundary |
list of set
|
Boundary nodes of each path cluster. |
pcluster_conn_dir |
list of list of set
|
Directed boundary connectivity between path clusters. |
pclusters_intcrtpts |
list of list
|
Interior critical points of each path cluster. |
allupath |
list of list
|
All unique decomposed paths. |
Tp |
ndarray
|
Cluster assignment of each path in |
Source code in src/tmapper/cycle_path_decomp.py
tmapper.path_traffic
¶
Port of tmapper_tools/pathtraffic.m from the MATLAB toolbox.
path_traffic(allpath, nodesize)
¶
Compute traffic statistics (based on node size) along each path.
Port of MATLAB's pathtraffic.m. Note: matches MATLAB's std()
convention of dividing by N-1 (sample standard deviation), not
numpy's default N.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allpath
|
sequence of sequence of int
|
Each element is a path of node indices. |
required |
nodesize
|
array_like
|
Size of each node, indexed the same way as the indices in
|
required |
Returns:
| Type | Description |
|---|---|
traf_mean, traf_med, traf_min, traf_max, traf_std : numpy.ndarray
|
One value per path in |
Source code in src/tmapper/path_traffic.py
tmapper.qasym(A, C)
¶
Modularity measure of an asymmetric, weighted network.
Port of MATLAB's Qasym.m. Adapted from the canonical modularity
definition (Fortunato 2010, Physics Reports) for asymmetric networks
with weighted edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
(array_like, shape(N, N))
|
Adjacency matrix, which may or may not be symmetric. |
required |
C
|
(array_like, shape(N))
|
Community assignment of each node. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Modularity Q. Returns 0 for a zero-edge network (neither modular nor non-modular). |
Source code in src/tmapper/modularity.py
tmapper.cal_mod(W, m0)
¶
Modularity score of a (typically symmetric) network given a community assignment.
Port of MATLAB's calMod.m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
W
|
(array_like, shape(N, N))
|
Graph adjacency matrix. |
required |
m0
|
(array_like, shape(N))
|
Categorical node labels / community assignment. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Modularity score. Returns 0 for a zero-edge network (neither modular nor non-modular). |