Analysis
Analyse systems, trajectories, and measured data by the kind of data.
The kinds of data are series, paths, fields, agents, and networks, such as the price of a stock over time, the grid of a forest fire, or the friendships of a school, and each analysis takes a system, a trajectory, or plain arrays.
AlignmentResult(angles, vectors, positions, order, tensors=None, axes=None, phase=None)
dataclass
A result of alignment, how well the members line up at every frame.
It holds one order value per frame, 1 when every member points the same way and near 0 when they point at random,
such as [1.0] for three birds flying north, with the angles, vectors, positions, axes, or mean phase the kind
reads. It measures the order of a flock, the line-up of the spins of a magnet, and the synchrony of fireflies.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angles
|
Array | None
|
The angles, frames by members, or |
required |
vectors
|
Array | None
|
The vectors or velocities, frames by members by components, or |
required |
positions
|
Array | None
|
The positions of agents, frames by agents by dimensions, or |
required |
order
|
Array
|
The alignment of every frame, between 0 and 1, or the scalar order of every site of every frame. |
required |
tensors
|
Array | None
|
The independent components of the tensors, with one frame per row of the first axis, for |
None
|
axes
|
Array | None
|
The principal axis of every site of every frame, with the components on the last axis, for
|
None
|
phase
|
Array | None
|
The mean phase of every frame, for |
None
|
See Also
alignment: Returns this result.
Examples:
>>> from skcomplex.core.analysis import alignment
>>> alignment([0.0, 0.0, 0.0]).order.tolist()
[1.0]
AnalysisTags(data, time=frozenset(), space=frozenset(), randomness=None)
dataclass
Bases: BaseSpec
A set of tags that an analysis needs of its data and of the system.
It names the kind of data an analysis reads and the tags the system behind the data must have, so an analysis
refuses data it cannot read before doing any work, such as AnalysisTags('system', randomness='deterministic') for
an analysis of systems with no randomness. An analysis module declares it as the constant TAGS, and an empty field
needs nothing. It keeps a stability analysis off a random epidemic and a network measure off a price series.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataKind | str
|
The kind of data the analysis reads. |
required |
time
|
frozenset[str]
|
The times of which the system needs one, among |
frozenset()
|
space
|
frozenset[str]
|
The spaces of which the system needs one, such as |
frozenset()
|
randomness
|
str | None
|
The randomness the system needs, |
None
|
See Also
applicable_analyses: Lists the analyses whose tags a source meets.
Examples:
>>> from skcomplex.core.analysis import AnalysisTags
>>> from skcomplex.core.components import Tags
>>> needed = AnalysisTags('system', randomness='deterministic')
>>> needed.get_missing(Tags(time=frozenset({'continuous'}), randomness='stochastic'))
{'randomness': ['stochastic']}
get_missing(tags)
Return the tags of a system that do not give what the analysis needs, by field.
The system needs one of the needed times and one of the needed spaces, and the needed randomness. A field of
the system that is empty or None is unknown and not checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
Tags
|
The tags of a system. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
missing |
dict[str, list[str]]
|
The tags of the system of every field that misses what is needed, sorted. |
Source code in src/skcomplex/core/analysis/_analysis_tags.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
ApplicableAnalysesResult(kinds, readings, analyses)
dataclass
A result of applicable_analyses, the analyses that fit a source, by kind.
It holds the kinds of data the source holds, such as ['field', 'series'] for a 2D array, what each kind reads from
it, and the analyses that apply under each kind, ready to call. It answers which measures fit a run of an epidemic,
a grid of a forest, or a table of prices.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kinds
|
list[str]
|
The data kinds of the source, in the order agents, field, network, path, series. |
required |
readings
|
dict[str, str]
|
How the analyses of every data kind read the source, by data kind. |
required |
analyses
|
dict[str, list[partial[object]]]
|
The analyses that apply to the source by data kind, each bound to its kind for a family, so calling one on the source gives its result. |
required |
See Also
applicable_analyses: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import applicable_analyses
>>> applicable_analyses(np.zeros((16, 16))).kinds
['field', 'series']
AutocatalyticSetsResult(snapshots, reactions, products, sizes, fractions, exists)
dataclass
A result of autocatalytic_sets, the largest such set at every frame.
It holds, for every frame, the reactions of the largest set that makes its own helpers from the food, the products of those reactions, their number and share, and whether such a set exists. It reports the self-making chemistry of the origin of life and the goods of an economy that are made from each other.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshots
|
list[NetworkSnapshotSpec]
|
The network snapshot of every analysed frame. |
required |
reactions
|
list[Indices]
|
The rows, in the hyperedges of the snapshot, of the reactions of the largest RAF of every frame. |
required |
products
|
list[Indices]
|
The node rows that the reactions of the largest RAF of every frame produce. |
required |
sizes
|
NDArray[int_]
|
The number of reactions of the largest RAF of every frame. |
required |
fractions
|
Array
|
The share of the reactions of every frame that the largest RAF holds, 0 for a frame without reactions. |
required |
exists
|
NDArray[bool_]
|
Whether every frame holds a RAF. |
required |
See Also
autocatalytic_sets: Returns this result.
Examples:
>>> from skcomplex.core.analysis import AutocatalyticSetsResult
>>> AutocatalyticSetsResult((), (), (), [], [], [False]).exists
[False]
AutomatonResult(automaton, injective=None, surjective=None, pre_injective=None, pattern=None, inverse=None, composition=None, differences=None, entropy=None, matrix=None, polynomial=None, admissible=None, violations=None, count=None, sample=None)
dataclass
A result of automaton, a decision or a measure of a cellular automaton.
It holds the answer the kind asks for, such as whether no two grids share their next grid, a grid that no grid leads
to, an automaton that undoes another, or the number of allowed grids, and leaves the other fields None. It answers
whether a model of traffic, of growth, or of a crystal loses information.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
automaton
|
System
|
The |
required |
injective
|
bool | None
|
Whether the automaton is injective. |
None
|
surjective
|
bool | None
|
Whether the automaton is surjective. |
None
|
pre_injective
|
bool | None
|
Whether no two configurations that differ only inside the window share their image. |
None
|
pattern
|
IntArray | None
|
A configuration whose values on the window have no preimage, or |
None
|
inverse
|
System | None
|
The |
None
|
composition
|
System | None
|
The |
None
|
differences
|
NDArray[bool_] | None
|
One row per step, the initial one first, true where the runs differ. |
None
|
entropy
|
NDArray[float64] | None
|
One entropy per window. |
None
|
matrix
|
Matrix | None
|
The Sage matrix of the linear automaton. |
None
|
polynomial
|
LaurentPolynomial | None
|
The Sage Laurent polynomial in the variables |
None
|
admissible
|
bool | None
|
Whether the configuration belongs to the subshift. |
None
|
violations
|
NDArray[bool_] | None
|
One flag per site, true where a forbidden pattern appears. |
None
|
count
|
int | None
|
The number of configurations without a forbidden pattern. |
None
|
sample
|
IntArray | None
|
The admissible configuration. |
None
|
See Also
automaton: Returns this result.
Examples:
>>> from skcomplex.core.analysis import automaton
>>> from skcomplex.systems.computer_science.automata import ElementaryAutomatonSystem
>>> automaton(ElementaryAutomatonSystem(rule=170, size=8)).injective
True
CellComplexResult(complex, values, period, betti=None, gradient=None, curl=None, harmonic=None, potential=None, share=None, energy=None)
dataclass
A result of cell_complex, a split of flows, counts of holes, or curved faces.
It holds, one row per frame, the three flows that a flow on links splits into, the counts of holes of each dimension
of a complex, or the faces around which an angle winds. A grid of 4 by 4 sites joined at its edges has one piece,
two loops, and one hollow, the Betti numbers (1, 2, 1). It reports the cycles of a road network, the holes of a
pattern, and the vortices of a gauge field.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
complex
|
CellComplexSpace
|
The cell complex the analysis reads. |
required |
values
|
Array
|
The values of the source, with one row per frame. |
required |
period
|
float
|
The period of the values. |
required |
betti
|
tuple[int, ...] | None
|
The Betti numbers of every degree, for the kind |
None
|
gradient
|
Array | None
|
The part of every frame that is the exterior derivative of a site potential, for the kind |
None
|
curl
|
Array | None
|
The part of every frame that the transposed incidence of a face potential gives, for the kind |
None
|
harmonic
|
Array | None
|
The remainder of every frame, for the kind |
None
|
potential
|
Array | None
|
The site potential of every frame, of zero mean, for the kind |
None
|
share
|
Array | None
|
The share of the faces of every frame that are curved, for the kind |
None
|
energy
|
Array | None
|
The sum over the faces of every frame of one minus the cosine of the oriented sum, for the kind
|
None
|
See Also
cell_complex: Returns this result.
Examples:
>>> from skcomplex.core.analysis import cell_complex
>>> from skcomplex.core.components.spaces import CellComplexSpace, LatticeSpace
>>> cell_complex(None, kind='betti', space=CellComplexSpace(LatticeSpace((4, 4))).prepare()).betti
(1, 2, 1)
ChainShapeResult(positions, values)
dataclass
A result of chain_shape, the geometry of a chain of points per frame.
It holds the positions and one value per frame, the radius of gyration, the distance between the ends, or the deviation from a reference shape, such as the radius 1 of two points 2 apart. It reports the size of a polymer, the stretch of a strand of DNA, and how far a folding protein lies from its native shape.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Array
|
The positions, frames by points by dimensions. |
required |
values
|
Array
|
The value per frame. |
required |
See Also
chain_shape: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import chain_shape
>>> chain_shape(np.array([[[0.0, 0.0], [2.0, 0.0]]])).values.tolist()
[1.0]
ClustersResult(points=None, faces=None, grids=None, graph=None, labels=None, sizes=None, strength=None, mean_size=None, spanning=None, probability=None)
dataclass
A result of clusters, the clusters of a grid, a graph, or points.
It holds the label of every cell, the size of every cluster, largest first, and for percolation the share of the
largest cluster, the mean size, and whether a cluster joins two opposite edges, such as [2, 1] for a pair and a
single. It reports the flow paths of a porous rock, the burnt patches of a forest, and the groups of like-minded
voters.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[float64] | None
|
The arrays of points, one per entry of the first axis, or |
None
|
faces
|
NDArray[float64] | None
|
The sides of the space that holds the points of a trajectory, or |
None
|
grids
|
NDArray[bool_] | None
|
The grids, one per entry of the first axis, or |
None
|
graph
|
Graph | None
|
The graph, or |
None
|
labels
|
IntArray | None
|
The label of every cell, 0 for empty cells and 1 onwards for clusters, for |
None
|
sizes
|
IntArray | None
|
The size of every cluster, in label order for |
None
|
strength
|
float | None
|
The share of all sites or nodes in the largest cluster, for |
None
|
mean_size
|
float | None
|
The mean size of the cluster of an occupied site outside the largest, |
None
|
spanning
|
bool | None
|
Whether a cluster of the grid joins the two opposite edges of |
None
|
probability
|
float | None
|
The spanning probability of the ensemble, for |
None
|
See Also
clusters: Returns this result.
Examples:
>>> from skcomplex.core.analysis import clusters
>>> clusters([[1, 1, 0], [0, 0, 1]], kind='sizes').sizes.tolist()
[2, 1]
CoarseGrainResult(positions, box, field)
dataclass
A result of coarse_grain, agents counted on a grid or spread over values.
It holds the counts of agents in every cell of a grid, one grid per frame, with the positions and the box, or the share of members at every value, which sums to 1. It reports the density of a herd, the spread of wealth, and the density of a fluid.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Array
|
The positions, one row per agent, with one leading axis of frames for a trajectory, or the values of the
state of every member with |
required |
box
|
Array | None
|
The sides of the box, or |
required |
field
|
Array
|
The grid of counts, or of sums with the value components last, with one grid per frame for a trajectory,
ready for field analyses, or the fractions of members at every value of |
required |
See Also
coarse_grain: Returns this result.
Examples:
>>> from skcomplex.core.analysis import coarse_grain
>>> coarse_grain([-1.0, 0.4, 0.6, 1.5, 9.0], over=[0.0, 1.0, 2.0]).field.tolist()
[0.4, 0.4, 0.2]
ComplexityResult(values, labels, entropy, complexity, minimum, maximum)
dataclass
A result of complexity, places on the complexity and entropy plane.
It holds the entropy and the complexity of every series or frame, with the lowest and highest complexity that each entropy allows. Noise sits near entropy 1 and complexity 0, and chaos higher up. It tells chaos from noise in heart beats, climate records, and prices.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column, or the frames of the field. |
required |
labels
|
list[str]
|
The label of every series, or of the field. |
required |
entropy
|
Array
|
The normalized permutation entropy of every series or frame. |
required |
complexity
|
Array
|
The statistical complexity of every series or frame. |
required |
minimum
|
Array
|
The curve of least complexity, one row of entropy and complexity per point. |
required |
maximum
|
Array
|
The curve of largest complexity, one row of entropy and complexity per point. |
required |
See Also
complexity: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import complexity
>>> complexity(np.random.default_rng(0).standard_normal(50_000), dimension=4).entropy.round(2).tolist()
[1.0]
CorrelationResult(values, labels, lags=None, correlation=None, time=None, distances=None, length=None, overlap=None)
dataclass
A result of correlation, the correlation of series or of a field.
It holds the correlation at every lag, time, or distance, the correlation time or length, or the overlap of two
configurations, such as [[1.0, -0.75]] for a series that flips sign at every step. It reports how long a price
remembers, how far order reaches in a magnet, and how alike two states of a glass are.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column, the ensemble, the field, or the two configurations. |
required |
labels
|
list[str]
|
The label of every series, of the ensemble or field, or of the two configurations. |
required |
lags
|
Array | None
|
The lags in time, for |
None
|
correlation
|
Array | None
|
One autocorrelation per series for |
None
|
time
|
Array | None
|
The integrated autocorrelation time of every series, for |
None
|
distances
|
Array | None
|
The distances, for |
None
|
length
|
float | Array | None
|
The correlation length, for |
None
|
overlap
|
float | Array | None
|
The overlap of the two configurations, one per frame for frames, for |
None
|
See Also
correlation: Returns this result.
Examples:
>>> from skcomplex.core.analysis import correlation
>>> correlation([1.0, -1.0, 1.0, -1.0], max_lag=1).correlation.round(2).tolist()
[[1.0, -0.75]]
DataCollapseResult(values, labels, critical=None, nu=None, exponent=None, quality=None, time_spread=None, ratio_spread=None, ratios=None, densities=None, spread=None, crossings=None)
dataclass
A result of data_collapse, curves of several sizes laid onto one.
It holds the rescaled curves, the fitted critical point and exponents with the quality of the collapse, the spreads
of aging curves, or the points where the curves of consecutive sizes cross, such as [2.0]. It reports the critical
point of a magnet, the growth exponents of a rough surface, and the aging of a glass.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
dict[float, Array] | Array
|
The curve of every size, the curves of every waiting time, or the samples of every age. |
required |
labels
|
list[float]
|
The size, waiting time, or age of every curve. |
required |
critical
|
float | None
|
The critical value used or fitted, for |
None
|
nu
|
float | None
|
The correlation length exponent used or fitted, for |
None
|
exponent
|
float | None
|
The exponent |
None
|
quality
|
float | None
|
The mean squared relative distance between the scaled curves, 0 for a perfect collapse, for |
None
|
time_spread
|
float | None
|
The largest difference between the curves against the lag, 0 without aging, for |
None
|
ratio_spread
|
float | None
|
The largest difference between the curves against |
None
|
ratios
|
Array | None
|
The centres of the bins of |
None
|
densities
|
Array | None
|
One row per age of |
None
|
spread
|
float | None
|
The largest relative difference between the rows where every row is positive, for |
None
|
crossings
|
Array | None
|
The first crossing of the curves of every pair of consecutive sizes, |
None
|
See Also
data_collapse: Returns this result.
Examples:
>>> from skcomplex.core.analysis import data_collapse
>>> curves = {8: [0.6, 0.5, 0.2], 16: [0.65, 0.5, 0.1]}
>>> data_collapse(curves, kind='crossings', parameters=[1.0, 2.0, 3.0]).crossings.tolist()
[2.0]
DefectsResult(angles, positions, charges)
dataclass
A result of defects, the points where a field of angles winds around.
It holds, for every frame, the angles, the positions of the defects, and their charges, the number of whole turns the angle makes around each, such as one defect of charge 1 at the centre of a vortex. It reports the vortices of a superfluid, the defects of a liquid crystal, and the swirls of a swarm of bacteria.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angles
|
Array
|
The angles, with one frame per row of the first axis. |
required |
positions
|
list[Array]
|
The centres of the plaquettes with a defect at every frame, each an array of defects by dimensions. |
required |
charges
|
list[Array]
|
The charges of the defects at every frame, each an array in the order of |
required |
See Also
defects: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import defects
>>> rows, columns = np.meshgrid(np.arange(8.0), np.arange(8.0), indexing='ij')
>>> result = defects(np.arctan2(rows - 3.5, columns - 3.5), period=2 * np.pi, periodic=False)
>>> result.positions[0].tolist(), result.charges[0].tolist()
([[3.5, 3.5]], [1.0])
DisplacementResult(positions, lags, msd, exponent, diffusion)
dataclass
A result of displacement, the mean squared distance travelled over every lag.
It holds the positions, the lags, the mean squared distance at every lag, the exponent of its growth with the lag, 1 for plain diffusion and 2 for straight flight, and the diffusion coefficient. It reports how molecules spread in a fluid, how cells crawl in a tissue, and how animals forage.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Array
|
The unwrapped positions, frames by particles by dimensions. |
required |
lags
|
Array
|
The lags in time. |
required |
msd
|
Array
|
The mean squared displacement at every lag. |
required |
exponent
|
float
|
The slope of |
required |
diffusion
|
float
|
The coefficient |
required |
See Also
displacement: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import displacement
>>> walks = np.cumsum(np.random.default_rng(0).standard_normal((2000, 500)), axis=0)
>>> round(displacement(walks).exponent, 1)
1.0
DistributionResult(values, labels, edges=None, density=None, support=None, survival=None, mean=None, variance=None, skewness=None, kurtosis=None, ratio=None, cumulant=None, index=None, gini=None, tail_index=None, records=None, distance=None)
dataclass
A result of distribution, the distribution of the values of a source.
It holds what the kind measures: a histogram, the share of values at or above each value, the moments, the Gini coefficient, the tail index, the count of records, or the distance between two distributions, such as a Gini coefficient of 0.75 when one of four holds everything. It reports the spread of incomes, the sizes of cities, and the avalanches of a sandpile.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The pooled sample, or the samples, one per column. |
required |
labels
|
list[str]
|
The label of every sample. |
required |
edges
|
Array | None
|
The bin edges of the histogram, for |
None
|
density
|
Array | None
|
The probability density in every bin of the histogram, for |
None
|
support
|
Array | None
|
The sorted distinct values of the complementary cumulative distribution, for |
None
|
survival
|
Array | None
|
The share of samples at or above every distinct value, |
None
|
mean
|
Array | None
|
The mean of every sample, for |
None
|
variance
|
Array | None
|
The variance of every sample, for |
None
|
skewness
|
Array | None
|
The skewness of every sample, for |
None
|
kurtosis
|
Array | None
|
The excess kurtosis of every sample, 0 for Gaussian samples, for |
None
|
ratio
|
Array | None
|
The moment ratio of every sample, for |
None
|
cumulant
|
Array | None
|
The normalized cumulant of every sample, for |
None
|
index
|
Array | None
|
The dispersion index of every sample, for |
None
|
gini
|
float | None
|
The Gini coefficient, for |
None
|
tail_index
|
float | None
|
The Hill estimate of the tail index, for |
None
|
records
|
NDArray[int64] | None
|
The number of records of every series, the first value included, for |
None
|
distance
|
float | None
|
The total variation distance between the two groups, for |
None
|
See Also
distribution: Returns this result.
Examples:
>>> from skcomplex.core.analysis import distribution
>>> distribution([0, 0, 0, 4], kind='gini').gini
0.75
DomainsResult(frames, times, size=None, exponent=None, wavelength=None, wavenumber=None, orientation=None, density=None)
dataclass
A result of domains, the size, growth, or pattern of the regions of a field.
It holds the size of the regions of equal value in every frame, the exponent of their growth, the dominant
wavelength and orientation of a pattern, or the share of neighbours that differ, such as [0.25] for stripes two
sites wide. It reports the growth of magnetic domains, of regions of opinion, and of the phases of an alloy.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
list[Graph] | Array
|
The frames of the field, or the graph. |
required |
times
|
Array
|
The time of every frame. |
required |
size
|
Array | None
|
The domain size of every frame, for |
None
|
exponent
|
float | None
|
The growth exponent of the domain size, for |
None
|
wavelength
|
Array | None
|
The wavelength of the peak of every frame, for |
None
|
wavenumber
|
Array | None
|
The wavenumber of the peak of every frame, for |
None
|
orientation
|
Array | None
|
The orientation order of the wave vectors near the peak of every frame, for |
None
|
density
|
Array | None
|
The interface density of every frame, for |
None
|
See Also
domains: Returns this result.
Examples:
>>> from skcomplex.core.analysis import domains
>>> domains([[1, 1, -1, -1]] * 4, kind='interface-density').density.tolist()
[0.25]
ElementaryModesResult(labels, modes, lines)
dataclass
A result of elementary_modes, the simplest steady routes through a network.
It holds the names of the variables, the routes, one row per route in exact fractions, and the routes that can run both ways, such as one route through a chain of three reactions. It reports the pathways of a metabolism, the routes of a chemical plant, and the flows of a supply chain.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
tuple[str, ...]
|
The name of every column of |
required |
modes
|
NDArray[object_]
|
One row per generator, scaled to |
required |
lines
|
NDArray[object_]
|
The generators that run in both directions, the lines of a cone that is not pointed, one row per line. |
required |
See Also
elementary_modes: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import elementary_modes
>>> elementary_modes(np.array([[1.0, -1.0, 0.0], [0.0, 1.0, -1.0]]), normalize='v0').modes.tolist()
[[Fraction(1, 1), Fraction(1, 1), Fraction(1, 1)]]
EmbeddingResult(values, labels, delay, dimension=None, points=None, mutual_information=None, false_neighbors=None)
dataclass
A result of embedding, the delayed copies of a series.
It holds the delay, the dimension, the points made of delayed copies of the series, and the measures that chose them, the auto mutual information and the share of false neighbours. It reports the rebuilt orbit of a heart beat, of a river flow, or of a price.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, as one column. |
required |
labels
|
list[str]
|
The label of the series. |
required |
delay
|
int
|
The delay in steps. |
required |
dimension
|
int | None
|
The dimension of |
None
|
points
|
Array | None
|
One row per delay vector of |
None
|
mutual_information
|
Array | None
|
The auto mutual information at every delay from 0, or |
None
|
false_neighbors
|
Array | None
|
The fraction of false nearest neighbours in every dimension from 1, or |
None
|
See Also
embedding: Returns this result.
Examples:
>>> from skcomplex.core.analysis import embedding
>>> embedding([0, 1, 2, 3, 4], delay=2, dimension=2).points.tolist()
[[0.0, 2.0], [1.0, 3.0], [2.0, 4.0]]
EmergenceResult(matrix=None, values=None, labels=None, information=None, determinism=None, degeneracy=None, states=None, partition=None, macro_matrix=None, micro_information=None, macro_information=None, gain=None, psi=None, delta=None, gamma=None, macro_uncertainty=None, micro_uncertainty=None, gap=None)
dataclass
A result of emergence, how much a coarse scale adds over a fine scale.
It holds what the kind measures: the effective information of a matrix of moves with its determinism and degeneracy, the best grouping of states with its gain, the criteria of Rosas et al., or the gap of a closed coarse view. Four states that each go to themselves carry 2 bits. It asks whether a flock, a brain region, or an economy acts as more than its parts.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Array | None
|
The micro transition matrix, for |
None
|
values
|
AnyArray | None
|
The micro series, one column per micro variable, for |
None
|
labels
|
list[str] | None
|
The label of every micro series. |
None
|
information
|
float | None
|
The effective information in bits, for |
None
|
determinism
|
float | None
|
|
None
|
degeneracy
|
float | None
|
|
None
|
states
|
NDArray[int64] | None
|
The states with observed transitions, the rows the effective information uses. |
None
|
partition
|
IntArray | None
|
The macro label of every micro state, for |
None
|
macro_matrix
|
Array | None
|
The macro transition matrix of the partition, every row summing to one. |
None
|
micro_information
|
float | None
|
The effective information of the micro matrix. |
None
|
macro_information
|
float | None
|
The effective information of the macro matrix. |
None
|
gain
|
float | None
|
The macro minus the micro effective information in bits. |
None
|
psi
|
float | None
|
|
None
|
delta
|
float | None
|
|
None
|
gamma
|
float | None
|
|
None
|
macro_uncertainty
|
float | None
|
|
None
|
micro_uncertainty
|
float | None
|
|
None
|
gap
|
float | None
|
The information the micro past adds about the macro future, zero for a closed coarse-graining. |
None
|
See Also
emergence: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import emergence
>>> emergence(np.eye(4), kind='effective-information').information
2.0
EntropyResult(values, labels, entropy, divergence=None, error=None)
dataclass
A result of entropy, the entropy of series or of the frames of a field.
It holds the values read and one entropy per series or frame, with the divergence from a reference law for an ensemble, such as 1 bit for a series that takes two values equally often. It reports the disorder of a heart rate, a written text, and the configurations of a lattice.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
NDArray[int64] | Array
|
The series, one per column, or the frames of the field, or the runs of the ensemble. |
required |
labels
|
list[str]
|
The label of every series, or of the field. |
required |
entropy
|
Array
|
One entropy per series or frame, with one column per block length for |
required |
divergence
|
Array | None
|
The divergence in bits of the outcomes of every frame of an ensemble from the reference law, or |
None
|
error
|
float | None
|
The expected divergence of a sample of the reference law of the ensemble's size, |
None
|
See Also
entropy: Returns this result.
Examples:
>>> from skcomplex.core.analysis import entropy
>>> entropy([0, 0, 1, 1] * 100, kind='excess', dimension=4).entropy.round(3).tolist()
[2.0]
EpsilonMachineResult(values, labels, alphabet, histories, transitions, probabilities, stationary, statistical_complexity, entropy_rate)
dataclass
A result of epsilon_machine, the hidden states that predict a series.
It holds the alphabet, the pasts that lead to each hidden state, the moves between states with their chances, how
often each state is visited, how much memory the states hold, the statistical complexity, and how much new
randomness each symbol brings, the entropy rate. A series 0, 0, 1 repeated has three states, a memory of log2 3
bits, and no randomness. It reports the hidden states of an automaton, of the spikes of a neuron, and of a text.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series of symbols. |
required |
labels
|
list[str]
|
The label of the series. |
required |
alphabet
|
Array
|
The distinct symbols, whose positions are the codes of the histories and of the columns. |
required |
histories
|
tuple[tuple[IntTuple, ...], ...]
|
The histories of every causal state, as codes of their symbols, oldest first. |
required |
transitions
|
IntArray
|
The state reached from every state on every symbol, -1 for symbols a state never emits. |
required |
probabilities
|
Array
|
The probability of every symbol from every state. |
required |
stationary
|
Array
|
The fraction of time spent in every state. |
required |
statistical_complexity
|
float
|
The entropy of the stationary distribution of the causal states in bits. |
required |
entropy_rate
|
float
|
The mean entropy of the next symbol given the causal state in bits. |
required |
See Also
epsilon_machine: Returns this result.
Examples:
>>> from skcomplex.core.analysis import epsilon_machine
>>> machine = epsilon_machine([0, 0, 1] * 300, max_length=3)
>>> len(machine.histories), round(machine.statistical_complexity, 3), round(machine.entropy_rate, 3)
(3, 1.585, 0.0)
ErgodicityResult(values=None, mapping=None, ergodicity_breaking=None, times=None, metric=None, exponent=None, ergodicity_distance=None, edges=None, density=None, transition_matrix=None)
dataclass
A result of ergodicity, whether a time average equals an ensemble average.
It holds the runs or the map it read and the measure of the kind, such as an ergodicity breaking of 0 for two runs that visit the same values and near 1 for runs frozen in their own states. It tells whether one long run of a gas, a wealth process, or a neuron stands for the whole ensemble.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array | None
|
The runs, one row per run, or the values of the run. |
None
|
mapping
|
Callable[[Array], Array] | None
|
The map of |
None
|
ergodicity_breaking
|
float | None
|
The ergodicity-breaking parameter, of |
None
|
times
|
Array | None
|
The times of the columns, of |
None
|
metric
|
Array | None
|
The fluctuation metric at every time, of |
None
|
exponent
|
float | None
|
The slope of |
None
|
ergodicity_distance
|
float | None
|
The median distance between the law of every run and that of the ensemble, of |
None
|
edges
|
Array | None
|
The edges of the bins or of the cells, of the density kinds. |
None
|
density
|
Array | None
|
The density in every bin or cell, of the density kinds. |
None
|
transition_matrix
|
Array | None
|
The probability that a point of every cell lands in every cell, of |
None
|
See Also
ergodicity: Returns this result.
Examples:
>>> from skcomplex.core.analysis import ergodicity
>>> ergodicity([[0.0, 0.0], [1.0, 1.0]], kind='distance').ergodicity_distance
0.5
EventsResult(times, values, labels, starts=None, sizes=None, durations=None, shapes=None, peaks=None, waiting_times=None, counts=None, branching_ratio=None)
dataclass
A result of events, the events of one series or of event times.
It holds the series it read and what the kind measures: the start, size, duration, and peak of every event, the
counts in windows, the laminar phases, the excursions, or the branching ratio, such as the sizes 4 and 2 of the
two bursts of [0, 3, 1, 0, 0, 2, 0]. It reports the crashes of a market, the spikes of a neuron, and the floods
of a river.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
Array | None
|
The time of every value, or of every event for |
required |
values
|
Array | None
|
The series, as one column, or one column per trial for |
required |
labels
|
list[str]
|
The label of the series or the state. |
required |
starts
|
Array | None
|
The time at which every event starts. |
None
|
sizes
|
Array | None
|
The sum of the values of every event. |
None
|
durations
|
Array | None
|
The time every event lasts for |
None
|
shapes
|
list[Array] | None
|
The profile of every excursion of a series, empty for records. |
None
|
peaks
|
Array | None
|
The largest value of every event. |
None
|
waiting_times
|
Array | None
|
The time between the end of every event and the start of the next. |
None
|
counts
|
Array | None
|
The number of events in every window. |
None
|
branching_ratio
|
float | None
|
The branching ratio |
None
|
See Also
events: Returns this result.
Examples:
>>> from skcomplex.core.analysis import events
>>> events([0, 3, 1, 0, 0, 2, 0]).sizes.tolist()
[4.0, 2.0]
FitLawResult(values, labels, exponent=None, minimum=None, maximum=None, statistic=None, p_value=None, tail=None, comparisons=None, index=None, skewness=None, shape=None, location=None, scale=None, maxima=None, parameters=None)
dataclass
A result of fit_law, a law fitted to a pooled sample.
It holds the sample and the fitted parameters of the law with how well it fits, such as an exponent near 2.5 for
samples drawn from p(x) ∝ x^-2.5. It reports whether the sizes of earthquakes, cities, or firms follow a power
law, and the scale of the energies of a gas.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The pooled sample. |
required |
labels
|
list[str]
|
The label of every series. |
required |
exponent
|
float | None
|
The exponent |
None
|
minimum
|
float | None
|
The lower cutoff of the power law, for |
None
|
maximum
|
float | None
|
The upper cutoff of the power law, or |
None
|
statistic
|
float | None
|
The Kolmogorov-Smirnov distance between the tail and the power law, or between the sample and a named law. |
None
|
p_value
|
float | None
|
For the power law, the share of bootstrap samples from the fit whose distance exceeds |
None
|
tail
|
int | None
|
The number of samples between the cutoffs of the power law, for |
None
|
comparisons
|
dict[str, tuple[float, float]] | None
|
For every alternative of |
None
|
index
|
float | None
|
The stability index of the stable law, 2 for the normal law, for |
None
|
skewness
|
float | None
|
The skewness of the stable law, for |
None
|
shape
|
float | None
|
The shape |
None
|
location
|
float | None
|
The location of the stable or the extreme-value law. |
None
|
scale
|
float | None
|
The scale of the stable or the extreme-value law. |
None
|
maxima
|
Array | None
|
The maximum of every block of the extreme-value law, for |
None
|
parameters
|
dict[str, float] | None
|
The fitted and fixed parameters of a named law. |
None
|
See Also
fit_law: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import fit_law
>>> fit = fit_law(np.random.default_rng(0).exponential(2.0, 1000), law='exponential', fixed={'loc': 0})
>>> round(fit.parameters['scale'], 0), fit.p_value > 0.05
(2.0, True)
InformationResult(values, labels, symbols, information)
dataclass
A result of information, the information among series.
It holds the series, the symbols it read them as, and the measure of the kind, a matrix for pairs, a value per series, or one value for all series, such as the 1 bit a copied coin flip passes to its copy. It reports the flow of information between regions of the brain, between markets, and between the members of a flock.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column. |
required |
labels
|
list[str]
|
The label of every series. |
required |
symbols
|
AnyArray
|
The symbols the kinds measure, one column per series, the series themselves without |
required |
information
|
float | Array
|
A matrix with the measure from the series of every row to the series of every column for |
required |
See Also
information: Returns this result.
Examples:
>>> from skcomplex.core.analysis import information
>>> xor = [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
>>> round(information(xor, kind='o-information').information, 6)
-1.0
InvariantsResult(problem, system, dynamics, namespace, rates, conserved, methods)
dataclass
A result of invariants, the rates of expressions and if they are conserved.
It holds the system, its equations, and for every expression its rate of change, whether it is conserved, and the
method that decided, such as the energy x² + x'² of a unit spring with a rate of 0. It reports the conserved
energy of a pendulum, the conserved total of an epidemic, and the conserved money of an exchange economy.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec
|
The compiled problem. |
required |
system
|
System
|
The |
required |
dynamics
|
_DynamicsSpec
|
The first-order equations of the system, with the values of its parameters. |
required |
namespace
|
SimpleNamespace
|
The namespace of the symbols of the states and parameters of the system, where |
required |
rates
|
dict[str, Expression]
|
A mapping from every label to the rate of change of its expression. |
required |
conserved
|
dict[str, bool]
|
A mapping from every label to whether its expression is conserved. |
required |
methods
|
dict[str, str]
|
A mapping from every label to the method that decided, |
required |
See Also
invariants: Returns this result.
Examples:
>>> from skcomplex.core.analysis import invariants
>>> from skcomplex.core.components import Observable
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> position = Observable('position', lambda s: s.mass.x)
>>> invariants(HarmonicOscillatorSystem(), expressions=[position]).rates['position']
x_d1_mass
IrreversibilityResult(values, duration=None, entropy_production=None, entropies=None, currents=None, statistic=None, p_value=None, balanced=None, centres=None, log_ratios=None, slope=None, mean=None, variance=None, product=None, error=None, holds=None, response=None, fluctuation_dissipation_ratio=None)
dataclass
A result of irreversibility, how far a process is from its reverse in time.
It holds the rates, paths, or samples it read and what the kind measures: the entropy production, the test of
detailed balance, the fluctuation relations, or the response, such as an entropy production of ln 2 for a ring of
five states that steps forward twice as often as back. It reports how far molecular motors, heart beats, and the
prices of a market are from equilibrium.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
NDArray[int64] | Array
|
The rate matrix, the paths one row per path, or the samples the kind reads. |
required |
duration
|
float | None
|
The duration of the jump paths, the setting or the duration of a trajectory. |
None
|
entropy_production
|
float | None
|
The entropy production per unit time in units of |
None
|
entropies
|
Array | None
|
The entropy produced along every path, of |
None
|
currents
|
Array | None
|
The net number of transitions from every state to every other per step, of |
None
|
statistic
|
float | None
|
The statistic |
None
|
p_value
|
float | None
|
The chi-squared p-value of the statistic under detailed balance, of |
None
|
balanced
|
bool | None
|
Whether the p-value exceeds the significance level, of |
None
|
centres
|
Array | None
|
The centres of the bins of entropy whose mirror bin is also populated, of |
None
|
log_ratios
|
Array | None
|
|
None
|
slope
|
float | None
|
The slope of the log ratio against the entropy, of |
None
|
mean
|
float | None
|
The mean of the current over the paths, of |
None
|
variance
|
float | None
|
The variance of the current over the paths, of |
None
|
product
|
float | None
|
The squared relative fluctuation of the current times the entropy, of |
None
|
error
|
float | None
|
The standard error of the product from bootstrap resamples of the paths, of |
None
|
holds
|
bool | None
|
Whether the product is at least 2 within two standard errors, of |
None
|
response
|
Array | None
|
The integrated response at every frame, of |
None
|
fluctuation_dissipation_ratio
|
float | None
|
The fluctuation-dissipation ratio, of |
None
|
See Also
irreversibility: Returns this result.
Examples:
>>> from skcomplex.core.analysis import irreversibility
>>> irreversibility([0, 1, 2] * 1000, kind='detailed-balance').balanced
False
KramersMoyalResult(values, positions, drift, diffusion)
dataclass
A result of kramers_moyal, the drift and diffusion of one series.
It holds the series, the centres of the bins of values, and the drift and the diffusion in every bin, such as a
diffusion of 1 everywhere for a random walk whose steps have the variance 2 dt. It reports the pull and the noise
of wind speeds, heart rates, and exchange rates.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series. |
required |
positions
|
Array
|
The centres of the bins of values. |
required |
drift
|
Array
|
The first coefficient |
required |
diffusion
|
Array
|
The second coefficient |
required |
See Also
kramers_moyal: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import kramers_moyal
>>> x = np.cumsum(np.random.default_rng(0).normal(0, np.sqrt(0.02), 100_000))
>>> kramers_moyal(x, dt=0.01, bins=21).positions.size
21
LargeDeviationsResult(rates=None, increments=None, system=None, samples=None, observations=None, tilts=None, scgf=None, effective_population=None, values=None, rate_function=None, weights=None, mean=None, effective_size=None)
dataclass
A result of large_deviations, the odds of rare values of an observable.
It holds the data it read, the scaled cumulant generating function at every tilt, and the rate function at the
values, such as 2 (e - 1) at the tilt 1 for the count of a Poisson process of rate 2. It reports the odds of a
run of losses of an insurer, a rare current through a channel, or a long drought.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
Array | None
|
The rate matrix of |
None
|
increments
|
Array | None
|
The increments of |
None
|
system
|
System | ProblemSpec | None
|
The |
None
|
samples
|
dict[int, Array] | None
|
The samples at every size of |
None
|
observations
|
Array | None
|
The samples of |
None
|
tilts
|
Array | None
|
The tilts of the generating function. |
None
|
scgf
|
Array | None
|
The scaled cumulant generating function at every tilt. |
None
|
effective_population
|
Array | None
|
The smallest effective number of clones over the selection steps at every tilt, |
None
|
values
|
Array | None
|
The values of the rate function, the centres of the bins of |
None
|
rate_function
|
Array | None
|
The rate function at every value, 0 at its minimum and |
None
|
weights
|
Array | None
|
The normalized weight of every sample of |
None
|
mean
|
float | None
|
The weighted mean of the samples of |
None
|
effective_size
|
float | None
|
The effective number of samples |
None
|
See Also
large_deviations: Returns this result.
Examples:
>>> from skcomplex.core.analysis import large_deviations
>>> large_deviations([-1.0, 1.0], kind='reweight', log_weights=[0.0, 0.0]).mean
0.0
LinearizationResult(problem, A, B, C, D, states, controls, outputs, controllability, observability, gain)
dataclass
A result of linearization, a linear state-space system.
It holds the matrices of x' = A x + B u and y = C x + D u, the ranks that tell whether the controls reach every
state and the outputs reveal every state, and the gain of the regulator, such as A = [[0, 1], [-1, 0]] for a unit
spring. It gives the linear model of an aircraft near trim, a power grid, or an economy near its steady state.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec
|
The compiled problem. |
required |
A
|
Array
|
The state matrix, the Jacobian of the rates by the states. |
required |
B
|
Array
|
The input matrix, the Jacobian of the rates by the controls. |
required |
C
|
Array
|
The output matrix, the Jacobian of the outputs by the states. |
required |
D
|
Array
|
The feedthrough matrix, the Jacobian of the outputs by the controls. |
required |
states
|
tuple[str, ...]
|
The names of the state components, in the order of the rows of |
required |
controls
|
tuple[str, ...]
|
The names of the controls, in the order of the columns of |
required |
outputs
|
tuple[str, ...]
|
The names of the outputs, in the order of the rows of |
required |
controllability
|
int
|
The rank of the controllability matrix. |
required |
observability
|
int
|
The rank of the observability matrix. |
required |
gain
|
Array | None
|
The gain of the regulator, one row per control and one column per state, or |
required |
See Also
linearization: Returns this result.
Examples:
>>> from skcomplex.core.analysis import linearization
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> linearization(HarmonicOscillatorSystem()).A.tolist()
[[0.0, 1.0], [-1.0, 0.0]]
LocalInformationResult(values, labels, information)
dataclass
A result of local_information, the information sample by sample.
It holds the series and the information of every sample, such as 2 bits for the rare 1 of [0, 0, 0, 1] and
less for each common 0. It reports the moments when information moves in a flock, in a cellular automaton, and in
the spikes of neurons.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column. |
required |
labels
|
list[str]
|
The label of every series. |
required |
information
|
Array
|
One row of local entropies per series for |
required |
See Also
local_information: Returns this result.
Examples:
>>> from skcomplex.core.analysis import local_information
>>> local_information([0, 0, 0, 1]).information.round(3).tolist()
[[0.415, 0.415, 0.415, 2.0]]
LoopsResult(problem, trajectory=None, graph=None, loops=None, polarities=None, gains=None, times=None, dominant=None, flows=None, holders=None, matrix=None)
dataclass
A result of loops, the feedback loops of a system.
It holds the signed graph of which state drives which, its loops with their polarity and gain, the dominant loop at every frame, or the matrix of the flows between holders, such as a reinforcing loop of word of mouth and a balancing loop of saturation in the spread of a product. It reports the loops of a model of system dynamics, a gene network, and an ecosystem.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec
|
The compiled problem. |
required |
trajectory
|
Trajectory | None
|
The trajectory of |
None
|
graph
|
DiGraph | None
|
The signed dependency graph from each state or flow to every node whose amount or rate depends on it, with
the edge attributes |
None
|
loops
|
list[tuple[str, ...]] | None
|
The nodes of every loop, in the order of their influence, starting at its first state by name, or at its first node by name when it holds no state. |
None
|
polarities
|
list[str] | None
|
The polarity of every loop, at the first frame for |
None
|
gains
|
Array | None
|
The gain of every loop, with one row per frame for |
None
|
times
|
Array | None
|
The time of every frame of |
None
|
dominant
|
NDArray[intp] | None
|
The index of the loop with the largest absolute gain at every frame of |
None
|
flows
|
tuple[str, ...] | None
|
The paths of the flows of the flow matrix. |
None
|
holders
|
tuple[str, ...] | None
|
The states and environments the flows connect. |
None
|
matrix
|
Array | None
|
The outflow, negative, and the inflow, positive, of every flow for every holder. |
None
|
See Also
loops: Returns this result.
Examples:
>>> from skcomplex.core.analysis import loops
>>> from skcomplex.systems.economics.innovation import BassDiffusionSystem
>>> loops(BassDiffusionSystem().prepare().system_).polarities
['reinforcing', 'balancing']
LyapunovResult(problem=None, exponents=None, kaplan_yorke_dimension=None, kolmogorov_sinai_entropy=None, values=None, labels=None, largest_exponent=None)
dataclass
A result of lyapunov, the Lyapunov exponents of a system or of series.
It holds the exponents, the rates at which nearby runs separate along each direction, with the dimension and the
entropy they give, or the largest exponent of every recorded series, such as ln 2 for the logistic map at
r = 4. It reports how fast small errors grow in the weather, a double pendulum, and the orbits of asteroids.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec | None
|
The compiled problem of the spectrum of a system, or |
None
|
exponents
|
Array | None
|
The exponents of the spectrum in decreasing order, per unit of time for flows and per iteration for maps,
or |
None
|
kaplan_yorke_dimension
|
float | None
|
The Kaplan-Yorke dimension of the spectrum, with |
None
|
kolmogorov_sinai_entropy
|
float | None
|
The entropy rate of the dynamics in nats per unit time, the sum of the positive exponents, or |
None
|
values
|
Array | None
|
The series of |
None
|
labels
|
list[str] | None
|
The label of every series of |
None
|
largest_exponent
|
Array | None
|
The largest exponent per unit time of every series of |
None
|
See Also
lyapunov: Returns this result.
Examples:
>>> from skcomplex.core.analysis import lyapunov
>>> round(lyapunov([0.906, 0.0, -14.572]).kaplan_yorke_dimension, 2)
2.06
MarkovResult(path=None, matrix=None, counts=None, transition_matrix=None, stationary=None, spectral_gap=None, relaxation_times=None, states=None, timescales=None, metastable_sets=None)
dataclass
A result of markov, a Markov chain of paths or of a matrix.
It holds the paths or the matrix it read and what the kind measures: the chances of moving from every state to every state, the share of time spent in each state, how fast the chain forgets its start, or the sets of states it lingers in, such as the shares 1/3 and 2/3 of a chain that leaves its second state less often. It reports the chain of weather states, credit ratings, and the shapes of a folding protein.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
NDArray[int64] | None
|
The integer states of the paths, one row per path, read without a matrix. |
None
|
matrix
|
Array | None
|
The matrix read with |
None
|
counts
|
NDArray[int64] | None
|
The transition counts, one row per origin, of |
None
|
transition_matrix
|
Array | None
|
The probability of every destination after one lag from every origin, of |
None
|
stationary
|
Array | None
|
The stationary law, of |
None
|
spectral_gap
|
float | None
|
The spectral gap, of |
None
|
relaxation_times
|
Array | None
|
|
None
|
states
|
NDArray[int64] | None
|
The states of the largest connected set, which index the rows of the matrix, of |
None
|
timescales
|
Array | None
|
The implied timescales |
None
|
metastable_sets
|
list[NDArray[int64]] | None
|
The states of every metastable set, empty without a number of sets, of |
None
|
See Also
markov: Returns this result.
Examples:
>>> from skcomplex.core.analysis import markov
>>> markov([[0.5, 0.5], [0.25, 0.75]], kind='stationary', matrix='transition').stationary.round(3).tolist()
[0.333, 0.667]
ModeDecompositionResult(samples, system, labels, states, last_state, dt, training_error, validation_error, eigenvalues, modes, amplitudes, generator, input_generator, operator, input_matrix, dictionary, inputs, forecast)
dataclass
A result of mode_decomposition, a linear system fitted to series.
It holds the fitted System, its matrices, its modes with their growth rates and frequencies, the errors of the
fit, and the forecast, such as the frequencies 1 and -1 of a point that turns on the unit circle. It reports the
patterns of a fluid flow, brain activity, and traffic in a city.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
_SamplesSpec
|
The series of every run, the names of the variables, and the step. |
required |
system
|
System
|
The |
required |
labels
|
list[str]
|
The variables, or the observables of the dictionary, in the order of the states. |
required |
states
|
list[str]
|
The names of the states of the surrogate element. |
required |
last_state
|
Array
|
The values of the states at the last sample of the last run, where the forecast starts. |
required |
dt
|
float
|
The time between the samples it was fitted to. |
required |
training_error
|
float
|
The relative error of the predicted increments over one sample on the training samples. |
required |
validation_error
|
float
|
The relative error on the held-out samples, NaN when none are held out. |
required |
eigenvalues
|
ComplexArray
|
The continuous eigenvalues |
required |
modes
|
ComplexArray
|
The modes, one column per mode and one row per state. |
required |
amplitudes
|
ComplexArray
|
The amplitudes of the modes at the last sample of the last run. |
required |
generator
|
Array
|
The matrix |
required |
input_generator
|
Array
|
The matrix |
required |
operator
|
Array
|
The matrix |
required |
input_matrix
|
Array
|
The matrix |
required |
dictionary
|
TransformerMixin | None
|
The fitted dictionary, which lifts new states to the observables, or |
required |
inputs
|
list[str]
|
The names of the parameters of the surrogate element that hold the inputs. |
required |
forecast
|
Array
|
The states at the |
required |
See Also
mode_decomposition: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import mode_decomposition
>>> times = np.arange(0.0, 10.0, 0.1)
>>> result = mode_decomposition(np.column_stack([np.cos(times), np.sin(times)]), horizon=5, dt=0.1)
>>> result.forecast.shape
(5, 2)
MotifsResult(graphs, counts, null_mean=None, null_std=None, z_scores=None)
dataclass
A result of motifs, the counts and scores of small subgraphs.
It holds the graph of every frame, the count of every motif, and for z-scores how far each count lies from those of random graphs with the same degrees, such as the four triangles of four nodes all joined. It reports the feedforward loops of a gene network, the triangles of a social network, and the circuits of a food web.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graphs
|
list[Graph]
|
The graph of every frame. |
required |
counts
|
list[dict[str, int]]
|
The count of every motif of every frame. |
required |
null_mean
|
list[dict[str, float]] | None
|
The mean count of every motif over the null ensemble of every frame, for |
None
|
null_std
|
list[dict[str, float]] | None
|
The standard deviation of every count over the null ensemble of every frame, for |
None
|
z_scores
|
list[dict[str, float]] | None
|
The z-score of every motif of every frame, for |
None
|
See Also
motifs: Returns this result.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import motifs
>>> motifs(nx.complete_graph(4), size=4).counts
[{'clique': 1}]
NeighborsResult(positions=None, box=None, frames=None, distances=None, ratio=None, radii=None, distribution=None, share=None)
dataclass
A result of neighbors, the neighbours of agents, cells, or nodes.
It holds the positions or the states it read and the statistic of the kind for every frame, such as a distance of 1 between two points at 0.5 and 9.5 in a periodic box of side 10. It reports how close birds sit in a flock, how cells pack in a tissue, and how far households live from others like them.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Array | None
|
The positions, frames by agents by dimensions, for the agent kinds. |
None
|
box
|
Array | None
|
The sides of the periodic box, or |
None
|
frames
|
list[Array] | list[Graph] | None
|
The grids of states, or the graphs, for |
None
|
distances
|
Array | None
|
The nearest-neighbour distances, frames by agents, for |
None
|
ratio
|
Array | None
|
One Clark-Evans ratio per frame, for |
None
|
radii
|
Array | None
|
The bin centres of |
None
|
distribution
|
Array | None
|
|
None
|
share
|
Array | None
|
One like share per frame, for |
None
|
See Also
neighbors: Returns this result.
Examples:
>>> from skcomplex.core.analysis import neighbors
>>> neighbors([[1, 1, 2, 2]] * 4, kind='like-share', diagonal=False).share.tolist()
[0.75]
NetworkMeasuresResult(graphs, degrees=None, moments=None, exponent=None, assortativity=None, centrality=None, labels=None, modularity=None, agreement=None, distinct_degrees=None, neighbor_degree=None, nodes=None, edges=None, mean_degree=None, clustering=None, path_length=None, diameter=None, components=None)
dataclass
A result of network_measures, measures of a network at every frame.
It holds the graph of every frame and what the kind measures: the degrees, how alike linked nodes are, how central each node is, the communities, or a summary of size, clustering, and paths, such as the mean degree 2 of a ring. It reports the hubs of the internet, the clustering of a social network, and the paths of a power grid.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graphs
|
list[Graph]
|
The graph of every frame. |
required |
degrees
|
list[NDArray[int64]] | None
|
The degree of every node of every frame, for |
None
|
moments
|
Array | None
|
The degree moments, frames by orders, for |
None
|
exponent
|
Array | None
|
The fitted degree exponent of every frame, for |
None
|
assortativity
|
Array | None
|
The assortativity of every frame, for |
None
|
centrality
|
list[dict[object, float]] | None
|
A mapping from node to its centrality for every frame, for |
None
|
labels
|
list[NDArray[int64]] | None
|
The community of every node of every frame, for |
None
|
modularity
|
Array | None
|
The modularity of every frame, for |
None
|
agreement
|
Array | None
|
The normalized mutual information with the reference of every frame, or |
None
|
distinct_degrees
|
list[NDArray[int64]] | None
|
The distinct degrees of every frame, for |
None
|
neighbor_degree
|
list[NDArray[float64]] | None
|
The mean neighbour degree of the nodes of every distinct degree of every frame, for |
None
|
nodes
|
NDArray[int64] | None
|
The number of nodes of every frame, for |
None
|
edges
|
NDArray[int64] | None
|
The number of edges of every frame, for |
None
|
mean_degree
|
Array | None
|
The mean degree of every frame, for |
None
|
clustering
|
Array | None
|
The average clustering of every frame, for |
None
|
path_length
|
Array | None
|
The average shortest path length of the largest component of every frame, for |
None
|
diameter
|
NDArray[int64] | None
|
The diameter of the largest component of every frame, for |
None
|
components
|
list[list[int]] | None
|
The sizes of the connected components of every frame, largest first, for |
None
|
See Also
network_measures: Returns this result.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import network_measures
>>> network_measures(nx.star_graph(3), kind='degrees').moments.tolist()
[[1.5, 3.0]]
PartialInformationResult(values, labels, redundancy, unique_first, unique_second, synergy, total)
dataclass
A result of partial_information, the parts of the information of two sources.
It holds the symbols and the four parts of what two sources tell about a target, the shared, the two unique, and the synergistic part, with their sum, such as 1 bit unique to the first source when the target copies it. It reports what two genes tell about a trait, two neurons about a stimulus, or two indicators about a market.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The symbols of the two sources and the target, one per column. |
required |
labels
|
list[str]
|
The label of every series. |
required |
redundancy
|
float
|
The information both sources give. |
required |
unique_first
|
float
|
The information only the first source gives. |
required |
unique_second
|
float
|
The information only the second source gives. |
required |
synergy
|
float
|
The information only the two sources together give. |
required |
total
|
float
|
The mutual information of the two sources together with the target, the sum of the four parts. |
required |
See Also
partial_information: Returns this result.
Examples:
>>> from skcomplex.core.analysis import partial_information
>>> copy = [[0, 0, 0], [0, 1, 0], [1, 0, 1], [1, 1, 1]]
>>> round(partial_information(copy).unique_first, 6)
1.0
PassageResult(values=None, times=None, matrix=None, passage_times=None, hitting_probabilities=None, return_times=None, committor=None, mean_first_passage_time=None)
dataclass
A result of passage, the first passages of paths to a level or a set.
It holds the paths, the series, or the matrix it read and what the kind measures: when every path first reaches a level or a set of states, where it ends, how long it takes to come back, or the chance of reaching one set before another, such as the time 2 of a path that climbs one step at a time to the level 2. It reports the time until a population dies out, a price hits a barrier, or a protein folds.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array | None
|
The paths, one row per path, or the series of |
None
|
times
|
Array | None
|
The common times of the steps. |
None
|
matrix
|
Array | None
|
The transition matrix of the matrix kinds. |
None
|
passage_times
|
Array | None
|
The time from the start to the first passage of every path, |
None
|
hitting_probabilities
|
Array | None
|
The share of paths that hit every target state first, of |
None
|
return_times
|
Array | None
|
The time between every return and the next, of |
None
|
committor
|
Array | None
|
The committor of every state, 0 on the origin and 1 on the target, of |
None
|
mean_first_passage_time
|
float | None
|
The mean first-passage time, of |
None
|
See Also
passage: Returns this result.
Examples:
>>> from skcomplex.core.analysis import passage
>>> walk = [[0.5, 0.5, 0.0], [0.25, 0.5, 0.25], [0.0, 0.5, 0.5]]
>>> passage(walk, kind='committor', origin=[0], target=[2]).committor.tolist()
[0.0, 0.5, 1.0]
RecurrenceResult(values, labels, radius, matrix, rate, determinism, laminarity, mean_diagonal, longest_diagonal, trapping_time, entropy)
dataclass
A result of recurrence, the recurrence matrix and its statistics.
It holds the points, the matrix that marks every pair of times whose points lie within the radius, and the statistics of its lines, such as a determinism near 1 for a sine wave. It tells regular rhythms of a heart, regime changes of the climate, and periodic orbits of an oscillator apart from noise.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The points, one per row. |
required |
labels
|
list[str]
|
The label of every coordinate. |
required |
radius
|
float
|
The recurrence radius. |
required |
matrix
|
csr_array
|
The symmetric sparse boolean recurrence matrix, with a true diagonal. |
required |
rate
|
float
|
The share of recurrent pairs off the Theiler window. |
required |
determinism
|
float
|
The share of recurrent points on diagonal lines of at least the minimum length. |
required |
laminarity
|
float
|
The share of recurrent points on vertical lines of at least the minimum length. |
required |
mean_diagonal
|
float
|
The mean length of those diagonal lines. |
required |
longest_diagonal
|
int
|
The length of the longest diagonal line. |
required |
trapping_time
|
float
|
The mean length of those vertical lines. |
required |
entropy
|
float
|
The Shannon entropy in nats of the distribution of those diagonal line lengths. |
required |
See Also
recurrence: Returns this result.
Examples:
>>> from skcomplex.core.analysis import recurrence
>>> recurrence([0.0, 0.1, 5.0, 5.1], radius=0.5).matrix.toarray().astype(int).tolist()
[[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]
RenormalizationResult(graph, graphs, degrees, exponents, clustering)
dataclass
A result of renormalization, the network at every scale.
It holds the network it read, the network after every merge of nodes into supernodes, and the degrees, the degree exponent, and the clustering at every scale, such as two dense groups joined by one link that merge into two linked supernodes. It reports the structure of the internet, the brain, and transport networks across scales.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
The network read from the source. |
required |
graphs
|
list[Graph]
|
The network at every scale, the original first. |
required |
degrees
|
list[NDArray[int64]]
|
The degree of every node at every scale. |
required |
exponents
|
Array
|
The fitted degree exponent at every scale, |
required |
clustering
|
Array
|
The average clustering at every scale. |
required |
See Also
renormalization: Returns this result.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import renormalization
>>> ring = nx.cycle_graph(8)
>>> nx.set_node_attributes(ring, {node: float(node) for node in ring}, 'angle')
>>> [graph.number_of_nodes() for graph in renormalization(ring, kind='geometric', steps=2).graphs]
[8, 4, 2]
ReservoirResult(samples, system, labels, states, last_state, dt, training_error, validation_error, step, forecast)
dataclass
A result of reservoir, a reservoir system fitted to series.
It holds the fitted System, which steps once per sample, its states, the errors of its predicted increments over
one sample, the map it steps with, and the forecast, such as the states x, memory_0, and memory_1 of a
reservoir that reads two consecutive samples of x. It gives a model of a chaotic flow, a power demand, or a
speech signal learned from series alone.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
_SamplesSpec
|
The series of every run, the names of the variables, and the step. |
required |
system
|
System
|
The |
required |
labels
|
list[str]
|
The variables the surrogate was fitted to. |
required |
states
|
list[str]
|
The names of the states of the surrogate element, the variables first. |
required |
last_state
|
Array
|
The variables at the last sample of the last series and the memory the series left, where forecasts start. |
required |
dt
|
float
|
The time between the samples it was fitted to, which one step of the system stands for. |
required |
training_error
|
float
|
The relative error of the predicted increments on the training samples, with the reservoir driven by the series. |
required |
validation_error
|
float
|
The relative error on the held-out samples, NaN when none are held out. |
required |
step
|
_ReservoirStep
|
The map from the states to the states one step later, which the update law calls, holding the fitted
reservoir node |
required |
forecast
|
Array
|
The variables at the |
required |
See Also
reservoir: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import reservoir
>>> reservoir(np.sin(0.1 * np.arange(400.0)), variables=['x']).states
['x', 'memory_0', 'memory_1']
RollingResult(values, labels, statistic, trend)
dataclass
A result of rolling, a statistic in rolling windows and its trend.
It holds the series, the statistic of every window set at its last sample, and the trend of the statistic, such as a trend of 1 for a variance that grows in every window. It reports the early warnings of a lake that turns turbid, a market that crashes, or a climate that shifts.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column. |
required |
labels
|
list[str]
|
The label of every series. |
required |
statistic
|
Array
|
The statistic of every series in every window, one row per series, |
required |
trend
|
Array
|
Kendall's tau of the statistic of every series against time, positive when it rises. |
required |
See Also
rolling: Returns this result.
Examples:
>>> from skcomplex.core.analysis import rolling
>>> rolling([0, 1, 0, 2, 0, 3], window=3).statistic.round(2).tolist()
[[nan, nan, 0.22, 0.67, 0.89, 1.56]]
ScalingResult(values, samples, labels, exponent, scales=None, fluctuations=None, counts=None, sums=None, means=None, deviations=None, fit_range=None, interval=None)
dataclass
A result of scaling, a scaling exponent, a fractal dimension, or a law.
It holds what the source was read as, the exponent of every series or the dimension of a set of cells or points, and the curves it is fitted on, such as the dimension 2 of a filled square. It reports the long memory of river flows, the fractal dimension of a coastline, and the critical exponents of a magnet.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column, the field or its frames, or the points, an empty array for samples by size,
and the pairs of sizes and samples of |
required |
samples
|
dict[float, Array] | None
|
The samples by size, or |
required |
labels
|
list[str]
|
The label of every series, of the field, or of every size. |
required |
exponent
|
float | Array
|
The exponent of every series for the fluctuation kinds and |
required |
scales
|
Array | None
|
The window sizes, the box sides, the radii, or the sizes, or |
None
|
fluctuations
|
Array | None
|
The fluctuation, or the rescaled range, of every series at every window size, for the fluctuation kinds. |
None
|
counts
|
Array | None
|
The number of occupied boxes of every side, for |
None
|
sums
|
Array | None
|
The share of pairs of points closer than every radius, for |
None
|
means
|
Array | None
|
The mean of the quantity at every scale, for |
None
|
deviations
|
Array | None
|
The standard deviation of the quantity at every scale, for |
None
|
fit_range
|
tuple[float, float] | None
|
The smallest and largest radii of the fit of the correlation dimension, for |
None
|
interval
|
tuple[float, float] | None
|
The lower and upper ends of the confidence interval of the allometric exponent, for |
None
|
See Also
scaling: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import scaling
>>> round(scaling(np.ones((256, 256)), kind='box-counting').exponent, 2)
2.0
SectionResult(problem, times, states, values)
dataclass
A result of section, the states of a flow at a crossing or at each period.
It holds the time and the state of every point of the section and the values of the read states there, such as a
unit spring that crosses x = 0 upward every 2 pi with the speed 1. It reports the crossings of the orbit of a
planet, a forced pendulum, and a heart rhythm.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec
|
The compiled problem of a Poincaré or stroboscopic section. |
required |
times
|
Array
|
The time of every point of a section. |
required |
states
|
Array
|
One state vector per point of a section. |
required |
values
|
dict[str, Array]
|
A mapping from the name of every read state to its values at the points of a section, one row per point
for a vector state. A derivative is named with a prime, such as |
required |
See Also
section: Returns this result.
Examples:
>>> from skcomplex.core.analysis import section
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> section(HarmonicOscillatorSystem(), state='mass.x', until=20.0).values["mass.x'"].round(3).tolist()
[1.0, 1.0, 1.0]
SignatureSpec(kind, title, xlabel, ylabel, curves, values=dict(), xscale='linear', yscale='linear', points=False)
dataclass
Bases: BaseSpec
A spec of the default analysis of one kind of data, ready to plot.
It holds the title, the labels and scales of the axes, the curves, and the values worth stating of one figure, such as the power spectrum of the prey and the predators of a Lotka-Volterra run on log axes. It gives the first look at the series of an ecosystem, the jumps of a market, or the field of a chemical pattern.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
DataKind
|
The kind of data analysed. |
required |
title
|
str
|
The title of the figure. |
required |
xlabel
|
str
|
The label of the horizontal axis. |
required |
ylabel
|
str
|
The label of the vertical axis. |
required |
curves
|
dict[str, tuple[Array, Array]]
|
A mapping from label to the abscissas and ordinates of every curve. |
required |
values
|
dict[str, float]
|
The measured values worth stating, by name. |
dict()
|
xscale
|
str
|
|
'linear'
|
yscale
|
str
|
|
'linear'
|
points
|
bool
|
Whether the curves are drawn as points rather than lines. |
False
|
See Also
signatures: Returns one spec per kind of data of a trajectory.
Examples:
>>> from skcomplex.core.analysis import signatures
>>> from skcomplex.systems.biology.ecology import LotkaVolterraSystem
>>> trajectory = LotkaVolterraSystem().prepare().simulate(until=20.0, random_state=0)
>>> signatures(trajectory).signatures[0].xlabel
'frequency'
SignaturesResult(kinds, discrete, signatures, snapshots=None, frames=None, graphs=None, path=None, jumps=None, series=None)
dataclass
A result of signatures, one default analysis per kind of data.
It holds the kinds of data of the trajectory, the data read for each, and one figure per kind with its curves, axis labels, title, and values, such as the power spectrum of the series of a Lotka-Volterra run. It gives the first look at the series of an ecosystem, the jumps of a market, or the field of a chemical pattern.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kinds
|
list[DataKind]
|
The data kinds of the trajectory, in the order agents, field, network, path, series. |
required |
discrete
|
bool
|
Whether the trajectory is that of a map, whose series give a return map. |
required |
signatures
|
list[SignatureSpec]
|
One signature per data kind, in the order of |
required |
snapshots
|
_SnapshotsSpec | None
|
The agents of the first group at every frame, for the agents kind. |
None
|
frames
|
Array | None
|
The frames of the first lattice state, for the field kind. |
None
|
graphs
|
list[Graph] | None
|
The network of every frame, for the network kind. |
None
|
path
|
_JumpPathSpec | None
|
The jump path of the first discrete state, for the path kind. |
None
|
jumps
|
Array | None
|
The size of the jumps of that state between frames, for the path kind. |
None
|
series
|
_SeriesSpec | None
|
The scalar series, for the series kind. |
None
|
See Also
signatures: Returns this result.
Examples:
>>> from skcomplex.core.analysis import signatures
>>> from skcomplex.systems.biology.ecology import LotkaVolterraSystem
>>> trajectory = LotkaVolterraSystem().prepare().simulate(until=20.0, random_state=0)
>>> [kind.value for kind in signatures(trajectory).kinds]
['series']
SparseIdentificationResult(samples, system, labels, states, last_state, dt, training_error, validation_error, features, coefficients, forecast)
dataclass
A result of sparse_identification, a sparse symbolic system.
It holds the fitted System, the candidate terms and the coefficient of each in the rate of every state, the
errors of the fit, and the forecast, such as the rate x' = -2 x found from a decaying exponential. It reports
the equations of a fluid flow, a chemical reaction, and a predator and prey cycle.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
_SamplesSpec
|
The series of every run, the names of the variables, and the step. |
required |
system
|
System
|
The |
required |
labels
|
list[str]
|
The variables the system was fitted to, in the order of its states. |
required |
states
|
list[str]
|
The names of the states of the surrogate element. |
required |
last_state
|
Array
|
The values of the states at the last sample of the last run, where the forecast starts. |
required |
dt
|
float
|
The time between the samples it was fitted to. |
required |
training_error
|
float
|
The relative error of the predicted derivatives on the training samples. |
required |
validation_error
|
float
|
The relative error on the held-out samples, NaN when none are held out. |
required |
features
|
list[str]
|
The candidate monomials of the states, such as |
required |
coefficients
|
Array
|
The coefficient of every monomial in the rate of every state, one row per state and one column per monomial, zero where the term is absent. |
required |
forecast
|
Array
|
The variables at the |
required |
See Also
sparse_identification: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import sparse_identification
>>> times = np.arange(0.0, 2.0, 0.001)
>>> sparse_identification(np.exp(-2 * times), variables=['x'], degree=1, dt=0.001).features
['1', 'x']
SpectrumResult(values, labels, power, frequencies=None, wavenumbers=None)
dataclass
A result of spectrum, the spectrum of series or of a field.
It holds the data read and how its power spreads over frequencies, or over wavenumbers for a field, such as a peak at the wavelength 8 for stripes that repeat every 8 sites. It reports the rhythms of brain waves, the cycles of a business, and the energy cascade of turbulence.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The series, one per column, or the field. |
required |
labels
|
list[str]
|
The label of every series, or of the field. |
required |
power
|
Array
|
One density per series and frequency for |
required |
frequencies
|
Array | None
|
The frequencies, for |
None
|
wavenumbers
|
Array | None
|
The wavenumbers of the shells, without 0, for |
None
|
See Also
spectrum: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import spectrum
>>> factor = spectrum(np.cos(2 * np.pi * np.arange(64) / 8)[:, None] * np.ones(64), kind='structure-factor')
>>> round(float(2 * np.pi / factor.wavenumbers[factor.power.argmax()]), 1)
8.0
StabilityResult(problem=None, names=None, jacobian=None, divergence=None, nullclines=None, fixed_points=None, eigenvalues=None, classifications=None, system=None, wavenumbers=None, magnitudes=None, growth_rates=None, frequencies=None, uniform=None, band=None)
dataclass
A result of stability, the linear stability of a system.
It holds the Jacobian, the nullclines, and the fixed points with their classes, or the growth rate of every wave of a field, such as a stable node at the carrying capacity of logistic growth. It reports whether a steady state of an epidemic, a chemical reactor, or a power grid returns after a small push.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec | None
|
The compiled problem, set for |
None
|
names
|
list[str] | None
|
The state component names, in the order of the rows of the Jacobian, set for |
None
|
jacobian
|
Matrix | None
|
The Sage matrix of the partial derivatives of the right sides by the states, set for |
None
|
divergence
|
Expression | None
|
The trace of the Jacobian, 0 for volume-preserving flows, set for |
None
|
nullclines
|
dict[str, Expression] | None
|
A mapping from state component name to its nullcline as a Sage relation, where its rate is 0 or where it
is its own next value, set for |
None
|
fixed_points
|
list[dict[str, Expression | float]] | None
|
One mapping from state component name to its value per point, the fixed points found or the given points,
set for |
None
|
eigenvalues
|
list[NDArray[complex128]] | None
|
The eigenvalues of the Jacobian at every point, set for |
None
|
classifications
|
list[str] | None
|
The class of every point: |
None
|
system
|
System | None
|
The |
None
|
wavenumbers
|
Array | None
|
The wave vector of every mode, one row per mode, set for |
None
|
magnitudes
|
Array | None
|
The length of every wave vector, set for |
None
|
growth_rates
|
Array | None
|
The largest real part of the eigenvalues of the linearisation at every mode, set for |
None
|
frequencies
|
Array | None
|
The imaginary part of the leading eigenvalue at every mode, nonzero for travelling or oscillating modes, set
for |
None
|
uniform
|
dict[str, float] | None
|
The uniform state the system is linearised around, by state name, set for |
None
|
band
|
Array | None
|
The lengths of the wave vectors whose modes grow, set for |
None
|
See Also
stability: Returns this result.
Examples:
>>> from skcomplex.core.analysis import stability
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> stability(LogisticGrowthSystem(), points=[{'population.x': 100.0}]).classifications
['stable node']
SurrogateTestResult(values, value, surrogates, p_value)
dataclass
A result of surrogate_test, a measure tested against surrogates.
It holds the data, the measure on the data and on every surrogate, where every variable is shuffled on its own, and the p-value, such as 0.05 for three copies of one coin flip tested against 19 surrogates. It reports whether a coupling between brain regions, markets, or climate indices is more than chance.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array
|
The data, one row per sample and one column per variable. |
required |
value
|
float
|
The measure on the data. |
required |
surrogates
|
Array
|
The measure on every surrogate. |
required |
p_value
|
float
|
The p-value of the data against the surrogates. |
required |
See Also
surrogate_test: Returns this result.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import bind_analysis, information, surrogate_test
>>> bits = np.column_stack([np.random.default_rng(0).integers(0, 2, 500)] * 3)
>>> measure = bind_analysis(information, kind='o-information')
>>> surrogate_test(bits, analysis=measure, attribute='information', n=19).surrogates.shape
(19,)
SymbolicResult(problem, equations=None, solutions=None, hamiltonian=None, inflows=None)
dataclass
A result of symbolic, the symbolic form of a system.
It holds the compiled problem and what the kind derives: the equations, their exact solution, the Hamiltonian, or
the flows across the boundary, such as x' = r x for exponential growth. It reports the equations of an epidemic,
a circuit, and a mechanical system, and their exact solutions where they exist.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ProblemSpec | OperatorProblemSpec
|
The compiled problem. |
required |
equations
|
dict[str, Expression] | None
|
A mapping from state component name to its equation, set for |
None
|
solutions
|
dict[str, Expression] | None
|
A mapping from state component name to its solution, a relation |
None
|
hamiltonian
|
Expression | None
|
The Hamiltonian, a Sage expression of local operators, set for |
None
|
inflows
|
dict[str, Expression] | None
|
The symbolic rate, or amount per step, at which each quantity enters the system from the environment, set
for |
None
|
See Also
symbolic: Returns this result.
Examples:
>>> from skcomplex.core.analysis import symbolic
>>> from skcomplex.systems.biology.ecology import ExponentialGrowthSystem
>>> symbolic(ExponentialGrowthSystem(), kind='solve', use_initial_state=True).solutions['population.x']
x_population(t) == 10*e^(r_growth*t)
alignment(source, *, kind='mean-vector', variables=None, group=None, vectors=False)
Return how well the members of a source line up at every frame.
Each member holds an angle or a direction, and the order is the length of their mean direction, 1 when every member
points the same way and about 1 / sqrt(n) for n random directions, as in alignment([0.0, 0.0, 0.0]). The
members are the agents of a group, the sites of a field, or the columns of a set of series, and other kinds measure
turning around a centre, line-up that ignores the sign, the mean phase, and the main axis of a matrix value. It
measures how well the birds of a flock fly together, how the spins of a magnet line up, and how the cells of a
tissue orient.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of angles, vectors, positions and velocities, or tensor components. |
required |
kind
|
str
|
What to measure. |
'mean-vector'
|
variables
|
Sequence[str] | None
|
The field or the series of a trajectory to read, or |
None
|
group
|
str | None
|
The path of the agent group of a trajectory, or |
None
|
vectors
|
bool
|
Whether the members hold vectors rather than angles. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
AlignmentResult
|
The members read and their alignment at every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, the trajectory holds no kind of data the function reads, or the source lacks what the kind needs. |
See Also
correlation: Measures how values at two places or times move together. spectrum: Finds the frequencies of a series.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import alignment
>>> phases = alignment([[0.5, 0.5], [0.0, np.pi]], kind='mean-phase')
>>> phases.order.round(6).tolist()
[1.0, 0.0]
Source code in src/skcomplex/core/analysis/_alignment.py
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 | |
applicable_analyses(source)
Return the analyses that apply to a trajectory, a system, or an array.
It reads the kinds of data the source holds, such as a field and a set of series for a 2D array, and keeps every
analysis of the library that reads one of them and needs no setting, bound once per kind. A system or a trajectory
of one also drops the analyses whose tags the system lacks, such as lyapunov of a random system. It answers which
measures fit a run of an epidemic, a grid of a forest, or a table of prices.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, the system, the graph, or the array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
ApplicableAnalysesResult
|
The data kinds of the source, how they are read, and the analyses of every kind. |
See Also
AnalysisTags: Names what an analysis needs of its data. bind_analysis: Fixes the settings of an analysis.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import applicable_analyses
>>> applicable_analyses(np.zeros((16, 16))).readings['series']
'every column of the array as a series'
Source code in src/skcomplex/core/analysis/_discovery.py
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 | |
autocatalytic_sets(source, *, food=None, frames=None)
Return the largest set of reactions that catalyse each other, at every frame.
The network is a snapshot whose hyperedges are reactions, each making its last member from the others, and whose
edges are catalysis, an edge from c to p making c a helper of every reaction that makes p. A set of
reactions is autocatalytic when every reaction has a helper made by the set or found in the food, and every reactant
can be made from the food by the set. The algorithm of Hordijk and Steel (2004) drops the reactions that fail, again
and again, and returns what is left, an empty set when there is none. It finds sets of molecules that make
themselves at the origin of life and goods that are made from each other in the economies of Hordijk and Kauffman
(2022).
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The network snapshot, or the trajectory of a network whose hyperedges change. |
required |
food
|
Sequence[int] | None
|
The node rows of the food set, or |
None
|
frames
|
Sequence[int] | None
|
The frames of a trajectory to analyse, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
AutocatalyticSetsResult
|
The snapshots, and the reactions, products, size, and share of the largest RAF of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The source is neither a network snapshot nor a trajectory of a network whose hyperedges change. |
See Also
loops: Finds the feedback loops of a network. elementary_modes: Finds the pathways of a metabolism.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import autocatalytic_sets
>>> from skcomplex.core.engine.problems import NetworkSnapshotSpec
>>> edges, reactions = np.array([[3, 4, 0], [2, 3, 4]]), np.array([[0, 1, 2], [2, 0, 3], [3, 1, 4]])
>>> autocatalytic_sets(NetworkSnapshotSpec(np.arange(5), *edges, np.arange(3), reactions)).reactions[0].tolist()
[0, 1, 2]
Source code in src/skcomplex/core/analysis/_autocatalytic.py
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 | |
automaton(source, *, kind='injective', method='auto', window=None, infinite=False, tries=200, random_state=None, max_radius=2, second=None, configuration=None, site=0, steps=1, windows=None, base=2.0, sweeps=100)
Return a decision or a measure of a cellular automaton or subshift of a system.
An automaton is a group of cells on a grid with one rule that updates every cell at once from its neighbours, such
as ElementaryAutomatonSystem(rule=170, size=8), which shifts every cell left. A subshift is a group whose value
lists forbidden patterns. The function decides whether the rule loses information, finds a grid no grid leads to,
builds the rule that undoes it, and counts or samples the allowed grids. Small grids are checked one by one and
larger ones with a SAT solver. It tells whether a model of traffic, of crystal growth, or of a computer loses
information, and reversible rules model physics that keeps energy.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system of the automaton or of the subshift. |
required |
kind
|
str
|
What to decide or measure. |
'injective'
|
method
|
str
|
|
'auto'
|
window
|
Sequence[int] | None
|
The sites where configurations may differ, or of the Garden of Eden pattern, or |
None
|
infinite
|
bool
|
Whether to decide a linear automaton on |
False
|
tries
|
int
|
The number of random patterns tried by SAT. |
200
|
random_state
|
int | Generator | None
|
The seed or generator of the random patterns or of the moves of a sample. |
None
|
max_radius
|
int
|
The largest radius of the memory of the inverse. |
2
|
second
|
DataSource | None
|
The system of the automaton applied after the analysed one. |
None
|
configuration
|
ArrayLike | None
|
The values of the sites: the initial ones of the difference pattern or of a sample, or the ones checked. |
None
|
site
|
int
|
The site of the changed cell. |
0
|
steps
|
int
|
The number of steps of the difference pattern. |
1
|
windows
|
Sequence[BaseSpace] | None
|
The windows of the entropy, such as lattices with fixed edges of growing size. |
None
|
base
|
float
|
The base of the logarithm. |
2.0
|
sweeps
|
int
|
The number of sweeps of a sample, each proposing a random value at every site in a random order. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
AutomatonResult
|
The system and the decision or measure of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The system holds nothing the kind reads, the method is unknown, enumeration is asked for too many configurations, composed automata differ in space or number of states, the rule returns a value outside the states, a linear automaton has a matrix on a ball or a polynomial without offsets, or the initial configuration of a sample is not admissible. |
See Also
symbolic: Turns a series into symbols and measures their patterns.
Examples:
>>> from skcomplex.core.analysis import automaton
>>> from skcomplex.systems.computer_science.automata import ElementaryAutomatonSystem
>>> automaton(ElementaryAutomatonSystem(rule=30, size=8), kind='injective').injective
False
Source code in src/skcomplex/core/analysis/_automata.py
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 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 | |
bind_analysis(analysis, **settings)
Return an analysis with fixed settings, in the role of make_scorer.
It fixes the settings of an analysis so the result takes the source alone, such as
bind_analysis(rolling, kind='variance', window=3), which an experiment applies to every run and names after the
function. The bound analysis keeps the function in func and the settings in keywords, so it travels to other
processes. It measures the variance before the collapse of a fishery, the entropy of every run of a market, and the
peak of every run of an epidemic.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis
|
Callable[..., ResultT]
|
The analysis function, such as |
required |
**settings
|
object
|
The settings of the analysis by name, as its keyword arguments take them. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
bound |
partial[ResultT]
|
The callable that applies the analysis with the settings to a source and returns its result. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The analysis is not callable, or it takes no setting of a given name. |
See Also
sweep: Runs a system over values and applies bound analyses to every run.
Examples:
>>> from skcomplex.core.analysis import bind_analysis, rolling
>>> variance = bind_analysis(rolling, kind='variance', window=3)
>>> variance([0.0, 1.0, 0.0, 1.0]).statistic.round(2).tolist()
[[nan, nan, 0.22, 0.22]]
Source code in src/skcomplex/core/analysis/_base.py
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 | |
cell_complex(source, *, kind, space=None, variables=None)
Return the split of a flow, the holes, or the curved faces of a complex.
It reads a value on the links of a CellComplexSpace from a trajectory, or an array with the complex passed as
space, one row per frame. The kind 'hodge' splits a flow on links into a flow that runs downhill from site to
site, a flow that circulates around faces, and a flow that does neither, three flows at right angles. The kind
'betti' counts the pieces, loops, and hollows of the complex, and 'curvature' finds the faces around which an
angle winds a whole turn. It splits the flows of a network, counts the holes of a pattern, and finds the vortices of
a gauge field.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array of values on the edges, or |
required |
kind
|
str
|
|
required |
space
|
CellComplexSpace | None
|
The cell complex, or |
None
|
variables
|
str | None
|
The dotted name of the state of a trajectory, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CellComplexResult
|
The complex, the values, and the results of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, the source names no state of a cell complex, or the values do not fit the complex. |
See Also
network_measures: Measures the structure of a graph.
Examples:
>>> from skcomplex.core.analysis import cell_complex
>>> from skcomplex.core.components.spaces import CellComplexSpace, LatticeSpace
>>> space = CellComplexSpace(LatticeSpace((4, 4))).prepare()
>>> cell_complex(None, kind='betti', space=space).betti
(1, 2, 1)
Source code in src/skcomplex/core/analysis/_cell_complex.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 | |
chain_shape(source, *, kind='gyration', group=None, reference=None)
Return the geometry of a chain of points per frame.
The chain is made of the positions of the members of a group in member order, and every frame gives one value of
its size or shape, such as the distance 5 between the ends of a chain from (0, 0) to (3, 4). It measures the
size of a polymer, the end to end distance of a strand of DNA, and how far a folding protein lies from its native
shape.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of frames by points by dimensions. |
required |
kind
|
str
|
|
'gyration'
|
group
|
str | None
|
The path of an agent or particle group of a trajectory, or the dotted name of a lattice state whose last
axis holds the coordinates of a point, or |
None
|
reference
|
ArrayLike | None
|
The positions the deviation compares with, points by dimensions, for the kind |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ChainShapeResult
|
The positions and the value of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, the kind |
See Also
displacement: Gives the mean squared distance particles travel over every lag. neighbors: Gives the neighbours of agents, grid cells, or network nodes.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import chain_shape
>>> chain = np.array([[[0.0, 0.0], [3.0, 4.0]]])
>>> chain_shape(chain, kind='end-to-end').values.tolist()
[5.0]
Source code in src/skcomplex/core/analysis/_shape.py
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 | |
clusters(source, *, kind='labels', variables=None, periodic=False, diagonal=False, axis=0, radius=None)
Return the clusters of a grid, a graph, or points.
A cluster is a set of occupied cells of a grid that touch through faces, or corners with diagonal=True, the
connected nodes of a graph, or points closer than twice radius, such as the clusters of sizes 2 and 1 in
[[1, 1, 0], [0, 0, 1]]. A trajectory gives its last field, network, or positions. A cluster spans when it joins
two opposite edges along axis. It finds the path of water through a porous rock, the burnt patches of a forest
fire, and the groups of an opinion model.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The grid or the grids, the graph, the points, or the trajectory. |
required |
kind
|
str
|
What to return. |
'labels'
|
variables
|
Sequence[str] | None
|
The field of a trajectory to read, or |
None
|
periodic
|
bool
|
Whether clusters of a grid wrap around its edges. |
False
|
diagonal
|
bool
|
Whether cells that share only a corner are connected. |
False
|
axis
|
int
|
The axis whose two opposite edges a spanning cluster joins. |
0
|
radius
|
float | None
|
The contact radius of points, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ClustersResult
|
What the source was read as, and the measures of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, the radius is not positive or comes with settings of grids, or a kind that reads grids gets a graph. |
See Also
domains: Finds the regions of equal value of a field. defects: Finds the defects of a field of angles.
Examples:
>>> from skcomplex.core.analysis import clusters
>>> result = clusters([[1, 1, 0], [1, 0, 1]], kind='percolation')
>>> result.strength, result.mean_size, result.spanning
(0.5, 1.0, True)
Source code in src/skcomplex/core/analysis/_clusters.py
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 | |
coarse_grain(source, *, shape=(32, 32), box=None, values=None, over=None, state=None)
Return agents counted on a grid, or members spread over the values of a state.
It counts the agents in every cell of a grid of shape over the box, one grid per frame, such as two agents in one
corner and one in the other of a box of side 1. With over, it counts every member at the given value nearest to
its own instead, and returns the share at every value. An array holds one snapshot, one row per agent, and a
trajectory gives the first group at every frame. It turns animals into the density of a herd, traders into the
spread of wealth, and particles into the density of a fluid.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of positions or of values of a state. |
required |
shape
|
Sequence[int]
|
The number of cells along every side. |
(32, 32)
|
box
|
Sequence[float] | None
|
The sides of the box, or |
None
|
values
|
ArrayLike | None
|
One value or one row of values per agent of an array, such as unit directions for a polarization field, or
|
None
|
over
|
ArrayLike | None
|
The increasing values of a state to coarse-grain the members over, or |
None
|
state
|
str | None
|
The dotted name of the state whose values a trajectory gives, such as |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CoarseGrainResult
|
The positions or values, the box, and the field. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A setting is invalid or missing, or the source holds no positions or values to coarse-grain. |
See Also
distribution: Fits and tests the distribution of values. clusters: Finds the clusters of a grid.
Examples:
>>> from skcomplex.core.analysis import coarse_grain
>>> positions = [[0.1, 0.1], [0.2, 0.1], [0.9, 0.9]]
>>> coarse_grain(positions, shape=[2, 2], box=[1.0, 1.0]).field.tolist()
[[2.0, 0.0], [0.0, 1.0]]
Source code in src/skcomplex/core/analysis/_coarse_grain.py
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 | |
complexity(source, *, variables=None, dimension=6, delay=1, ties='order', random_state=None)
Return the place of series on Rosso's complexity and entropy plane.
It turns every series, or every frame of a field, into the order patterns of its values and measures how even the
patterns are, the entropy, and how far they are from even, times the entropy, the complexity, with ordpy. Noise
has an entropy near 1 and a complexity near 0, a regular series both near 0, and chaos lies between with a high
complexity. It tells chaos from noise in heart beats, climate records, and the prices of a market.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array with one row per time and one column per series, or the frames of a field. |
required |
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
dimension
|
int | tuple[int, int]
|
The length of the patterns of a series, or the window |
6
|
delay
|
int
|
The number of steps between the values of a pattern. |
1
|
ties
|
str
|
|
'order'
|
random_state
|
int | None
|
The seed of the random ranks of equal values. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ComplexityResult
|
The values read, the place of every series or frame on the plane, and the bounds of the plane. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The ties are unknown, or the pattern length, the window, or the delay is below 1. |
See Also
entropy: Measures the entropy of a series. lyapunov: Measures how fast nearby runs drift apart.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import complexity
>>> plane = complexity(np.random.default_rng(0).standard_normal(50_000), dimension=4)
>>> plane.entropy.round(2).tolist(), plane.complexity.round(2).tolist()
([1.0], [0.0])
Source code in src/skcomplex/core/analysis/_complexity.py
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 | |
correlation(source, *, kind='auto', variables=None, max_lag=None, dt=None, waiting=None, lags=None, connected=False, max_distance=None, method='moment', spacing=1.0, frames=False)
Return the correlation of series, of an ensemble at two times, or of a field.
A correlation says how much a value at one time or place moves with the value at another, from 1 for together to -1
for opposite, such as -0.75 at lag 1 for a series that flips sign at every step. It reads series for the
correlation over time, an ensemble of runs for the correlation between two times, and a field for the correlation
over distance and how far it reaches. It finds how long a stock price remembers its past, how far order reaches in a
magnet, and how two regions of the brain move together.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array of series, an ensemble, a field, or a pair of replicas for |
required |
kind
|
str
|
|
'auto'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
max_lag
|
int | None
|
The largest lag in steps, or |
None
|
dt
|
float | None
|
The time between the samples of an array, or |
None
|
waiting
|
Sequence[int] | None
|
The waiting times |
None
|
lags
|
Sequence[int] | None
|
The lags |
None
|
connected
|
bool
|
Whether to subtract the product of the means at the two times. |
False
|
max_distance
|
int | None
|
The largest distance in cells, or |
None
|
method
|
str
|
The method of the correlation length, |
'moment'
|
spacing
|
float
|
The distance between neighbouring sites. |
1.0
|
frames
|
bool
|
Whether the first axis of an array indexes frames, and whether to read every frame of a trajectory. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
CorrelationResult
|
The data read and its correlation. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind or method is unknown, a setting the kind does not read is changed, a setting the kind needs is
missing, a setting is not positive, or |
See Also
spectrum: Finds the frequencies of a series. information: Measures shared information between series.
Examples:
>>> from skcomplex.core.analysis import correlation
>>> correlation([[1, -1, 1, 1], [1, -1, -1, 1]], kind='overlap').overlap
0.5
Source code in src/skcomplex/core/analysis/_correlation.py
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
data_collapse(source, *, kind='scaling', parameters=None, critical=None, nu=None, exponent=0.0, fit=(), waiting=None, lags=None, ratios=None)
Return the collapse of curves or distributions of several sizes or ages.
Curves measured at several sizes or ages often fall onto one curve once their axes are rescaled, and the rescaling
that does it gives the exponents of the system, such as y_L(p) = L^a f((p - p_c) L^(1/nu)) for curves of sizes L
near a critical point p_c. It fits the names of fit among critical, nu, and exponent, measures how far
aging curves stay apart, or finds where the curves of consecutive sizes cross. It estimates the critical point of a
magnet from lattices of several sizes, the growth exponents of a rough surface, and the aging of a glass.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
A mapping from size or age to its curve or samples, or an array with one curve per row. |
required |
kind
|
str
|
|
'scaling'
|
parameters
|
Sequence[float] | None
|
The control parameter values, shared by every curve of |
None
|
critical
|
float | None
|
The critical value, or the starting value of a fit. |
None
|
nu
|
float | None
|
The correlation length exponent, or the starting value of a fit. |
None
|
exponent
|
float
|
The exponent |
0.0
|
fit
|
Sequence[str]
|
The names among |
()
|
waiting
|
Sequence[float] | None
|
The waiting times of the curves of |
None
|
lags
|
Sequence[float] | None
|
The lags shared by every curve of |
None
|
ratios
|
Sequence[float] | None
|
The edges of the bins of |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
DataCollapseResult
|
The curves, their labels, and the collapse of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind or a fitted name is unknown, a setting the kind needs is missing or one it does not read is changed, or the source has too few sizes or is not a mapping where the kind needs one. |
See Also
scaling: Fits power laws and exponents.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import data_collapse
>>> grid = np.linspace(-1, 1, 401)
>>> curves = {size: np.tanh(grid * size) for size in (8, 16, 32)}
>>> round(data_collapse(curves, parameters=grid, critical=0.2, nu=1.5, fit=('critical', 'nu')).nu, 1)
1.0
Source code in src/skcomplex/core/analysis/_collapse.py
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 225 226 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 | |
defects(source, *, period=np.pi, variables=None, periodic=True)
Return the points where a field of angles winds around, at every frame.
Around every square of four neighbouring sites it adds the changes of the angle along the sides, each wrapped to within half a turn, and divides by a whole turn, so a square the angle winds around once holds a defect of charge 1. The charges of a periodic grid sum to 0. An array of two dimensions holds one frame and one of three dimensions one frame per row. It finds the vortices of a superfluid, the defects of a liquid crystal, and the swirls of a swarm of bacteria.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of angles of one snapshot or of one frame per row. |
required |
period
|
float
|
The period of the angles, |
pi
|
variables
|
Sequence[str] | None
|
The field of a trajectory to read, or |
None
|
periodic
|
bool
|
Whether the lattice joins its opposite edges, or has plaquettes only between its sites. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
DefectsResult
|
The angles, and the positions and the charges of the defects of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The period is not positive, or the field is not two-dimensional. |
See Also
alignment: Measures how well the members line up. domains: Finds the regions of a field.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import defects
>>> rows, columns = np.meshgrid(np.arange(8.0), np.arange(8.0), indexing='ij')
>>> result = defects(np.arctan2(rows - 3.5, columns - 3.5), period=2 * np.pi, periodic=False)
>>> result.positions[0].tolist(), result.charges[0].tolist()
([[3.5, 3.5]], [1.0])
Source code in src/skcomplex/core/analysis/_defects.py
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 | |
displacement(source, *, group=None, dt=1.0, lags=None, fit_range=None)
Return the mean squared distance particles travel over every lag.
For every lag it averages the squared distance each particle moves in that time,
MSD(tau) = <|x(t + tau) - x(t)|^2>, and fits MSD ~ tau^a, where a is 1 for diffusion and 2 for straight
flight, with an FFT over all lags at once. Positions must be unwrapped across periodic walls, as a trajectory gives
them. It tells diffusion from flight in the paths of molecules in a fluid, of cells in a tissue, and of animals that
forage.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of positions with time as the first axis. |
required |
group
|
str | None
|
The path of the agent group of a trajectory, or |
None
|
dt
|
float
|
The time between frames. |
1.0
|
lags
|
Sequence[int] | None
|
The lags in frames to keep, or |
None
|
fit_range
|
tuple[float, float] | None
|
The smallest and largest lags in time of the fits, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
DisplacementResult
|
The positions, the mean squared displacement at every lag, its exponent, and the diffusion coefficient. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The time step or a lag is not positive, the agents have no positions, or the fit range holds too few lags. |
See Also
passage: Measures the times to reach a level. kramers_moyal: Estimates the drift and noise of a path.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import displacement
>>> walks = np.cumsum(np.random.default_rng(0).standard_normal((2000, 500)), axis=0)
>>> round(displacement(walks).exponent, 1)
1.0
Source code in src/skcomplex/core/analysis/_displacement.py
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 | |
distribution(source, *, kind='histogram', variables=None, group=None, bins=30, log=False, absolute=False, orders=(4, 2), tail=10)
Return the distribution of the values of a source, of one kind.
It reads samples as columns, the series of a trajectory or an array, or the speeds of the agents at every frame, and measures how the values spread, such as the Gini coefficient, 0 when all hold the same and near 1 when one holds everything. Some kinds pool every sample into one and others describe every sample. It describes the spread of incomes in an economy, the sizes of cities, and the avalanches of a sandpile.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one column per sample. |
required |
kind
|
str
|
Pooled kinds: |
'histogram'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
group
|
str | None
|
The path of the agent or particle group whose speeds are read, or |
None
|
bins
|
int
|
The number of bins of the histogram. |
30
|
log
|
bool
|
Whether the bins of the histogram are equally spaced in the logarithm of the values, which needs positive values. |
False
|
absolute
|
bool
|
Whether the moments are those of the absolute values. |
False
|
orders
|
tuple[int, int]
|
The positive even orders |
(4, 2)
|
tail
|
int
|
The number of largest samples of the Hill estimate. |
10
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
DistributionResult
|
The samples and their description. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a setting is out of range, or the samples do not suit the kind. |
See Also
scaling: Fits power laws and exponents. coarse_grain: Counts members at values.
Examples:
>>> from skcomplex.core.analysis import distribution
>>> distribution([1, 1, 2, 4], kind='ccdf').survival.tolist()
[1.0, 0.5, 0.25]
Source code in src/skcomplex/core/analysis/_distribution.py
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 225 226 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 | |
domains(source, *, kind='size', variables=None, method='moment', spacing=1.0, fit_range=None, times=None, attribute='state')
Return the regions of every frame of a field, or of the states on a network.
A domain is a region of equal value, such as a patch of spins pointing up. It measures their typical size, how fast they grow, the dominant wavelength of a pattern, or the share of neighbours whose values differ, 0 for one domain and 1/2 for random values. A trajectory gives the frames and times of a lattice value, and a graph holds values on its nodes. It measures the growth of magnetic domains after a quench, of regions of opinion in a voter model, and of the phases of an alloy.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array of frames, or a graph. |
required |
kind
|
str
|
|
'size'
|
variables
|
Sequence[str] | None
|
The lattice state of a trajectory to read, or |
None
|
method
|
str
|
The domain size method, |
'moment'
|
spacing
|
float
|
The distance between neighbouring sites. |
1.0
|
fit_range
|
tuple[float, float] | None
|
The first and last times of the growth fit, or |
None
|
times
|
Sequence[float] | None
|
The time of every frame of an array, or |
None
|
attribute
|
str
|
The node attribute of the states of a graph. |
'state'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
DomainsResult
|
The frames, their times, and the domain measure of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind or method is unknown, a setting the kind does not read is changed, the spacing is not positive, or a kind that reads a field is given a graph. |
See Also
clusters: Finds the clusters of a grid. correlation: Measures how far order reaches.
Examples:
>>> from skcomplex.core.analysis import domains
>>> domains([[1, 1, -1, -1]] * 4, kind='interface-density').density.tolist()
[0.25]
Source code in src/skcomplex/core/analysis/_domains.py
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 191 192 | |
elementary_modes(source, *, kind='modes', normalize=None, exchanges=None, timeout=60.0, labels=None, irreversible=None, sort=None)
Return the simplest steady routes through a network of flows.
A steady route is a set of flows v that keeps every amount fixed, S v = 0, with every one-way flow running its
own way. The simplest routes use as few flows as they can, and every steady state is a mix of them. A system gives
the matrix and the directions of its linear program law at its initial values, and a matrix gives them directly with
the indices of its one-way columns. It lists the pathways of a metabolism, the routes of a chemical plant, and the
ways goods can flow through a supply chain.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, or the matrix. |
required |
kind
|
str
|
|
'modes'
|
normalize
|
str | None
|
The name of a variable to scale every row to one where it is not zero, or |
None
|
exchanges
|
Sequence[str] | None
|
The names of the exchange variables, or |
None
|
timeout
|
float
|
The time limit of the enumeration in seconds. |
60.0
|
labels
|
Sequence[str] | None
|
The names of the columns of a matrix, or |
None
|
irreversible
|
Sequence[int] | None
|
The indices of the irreversible columns of a matrix, or |
None
|
sort
|
str | None
|
The name of a variable to order the rows by, largest first, such as the growth flux of modes normalised to
the uptake, which orders them by yield, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ElementaryModesResult
|
The names of the columns, the generators, and the lines. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, the right side of a balance is not zero, a coefficient is not close to a fraction, or no system or matrix holds a program. |
EnumerationLimitError
|
The enumeration does not finish within the time limit. |
See Also
loops: Finds the feedback loops of a network. autocatalytic_sets: Finds sets of reactions that help each other.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import elementary_modes
>>> elementary_modes(np.array([[1.0, -1.0, 0.0], [0.0, 1.0, -1.0]]), normalize='v0').modes.tolist()
[[Fraction(1, 1), Fraction(1, 1), Fraction(1, 1)]]
Source code in src/skcomplex/core/analysis/_elementary_modes.py
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 | |
embedding(source, *, kind='delay', variables=None, delay=None, dimension=None, threshold=0.01, max_delay=100, max_dimension=10, bins=16, ratio=10.0, escape=2.0)
Return the points made of delayed copies of one series.
It builds the points (x_t, x_{t+delay}, ..., x_{t+(dimension-1) delay}), which rebuild the shape of the orbit of a
system from one measured series, such as [[0, 2], [1, 3], [2, 4]] for 0, 1, 2, 3, 4 with delay 2. Without a
delay it takes the first minimum of the auto mutual information, and without a dimension the first one whose share
of false neighbours lies below threshold. It rebuilds the orbit of a heart rate, of a river flow, and of a stock
price.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array that holds one series. |
required |
kind
|
str
|
|
'delay'
|
variables
|
Sequence[str] | None
|
The one variable of a trajectory to read, or |
None
|
delay
|
int | None
|
The delay in steps, or |
None
|
dimension
|
int | None
|
The dimension, or |
None
|
threshold
|
float
|
The fraction of false nearest neighbours accepted. |
0.01
|
max_delay
|
int
|
The largest delay tried. |
100
|
max_dimension
|
int
|
The largest dimension tried. |
10
|
bins
|
int
|
The number of equally populated bins of the auto mutual information. |
16
|
ratio
|
float
|
The threshold on the relative growth of the distance of a false neighbour. |
10.0
|
escape
|
float
|
The threshold on the distance of a false neighbour in the next dimension, in standard deviations. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
EmbeddingResult
|
The series, the delay, and the embedding or the fraction of false neighbours. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a size is below 1, the source holds several series, or no dimension has few enough false neighbours. |
See Also
recurrence: Finds when an orbit returns near itself. lyapunov: Measures how fast nearby runs drift apart.
Examples:
>>> from skcomplex.core.analysis import embedding
>>> embedding([0, 1, 2, 3, 4], delay=2, dimension=2).points.tolist()
[[0.0, 2.0], [1.0, 3.0], [2.0, 4.0]]
Source code in src/skcomplex/core/analysis/_embedding.py
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 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 | |
emergence(source, *, kind='causal', variables=None, partition=None, weighting='uniform', search='greedy', lag=1, history=1, estimator='plugin', k=3, base=2.0)
Return how much a coarse scale adds over a fine scale, of one kind.
It reads a matrix of the chances of moving between fine states, or series of fine variables, and asks whether grouping the states into coarse ones predicts better, such as the 2 bits of four states that each stay put. It asks whether a flock, a brain region, or an economy acts as more than its parts.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
A transition matrix or transition counts for |
required |
kind
|
str
|
|
'causal'
|
variables
|
Sequence[str] | None
|
The micro variables of a trajectory to read, or |
None
|
partition
|
Partition | None
|
The macro label of every integer micro state, numbered 0, 1, and so on, or a function from an array of
micro states, or from the micro series with one column per variable, to their macro labels. |
None
|
weighting
|
str
|
|
'uniform'
|
search
|
str
|
|
'greedy'
|
lag
|
int
|
The number of steps between the present and the future of the criteria. |
1
|
history
|
int
|
The number of past steps the closure conditions on. |
1
|
estimator
|
str
|
|
'plugin'
|
k
|
int
|
The number of neighbours of the |
3
|
base
|
float
|
The base of the logarithm, 2 for bits. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
EmergenceResult
|
The matrix or the micro series read, and the measures of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, a setting is out of range, the macro feature is missing, the matrix is not square or has no observed transition, the partition is not valid, or the exhaustive search gets more than 10 states. |
Warns:
| Type | Description |
|---|---|
UnobservedStatesWarning
|
Some rows of the micro matrix hold no transition, and the warning names their states. |
See Also
information: Measures shared information between series. markov: Fits a chain of moves between states.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import emergence
>>> emergence(np.eye(4), kind='effective-information').information
2.0
Source code in src/skcomplex/core/analysis/_emergence.py
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 225 226 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 | |
entropy(source, *, kind='shannon', variables=None, order=2.0, base=2.0, probabilities=False, dimension=3, delay=1, tolerance=0.2, scales=tuple(range(1, 11)), normalize=True, dt=1.0, measure='shannon', ties='order', random_state=None, reference=None)
Return the entropy of every series of a source, or of every frame of a field.
Entropy measures how unpredictable values are, in bits, such as 1 bit for a series that takes two values equally often and 0 for a constant one. The kinds read symbols, patterns, or real values. It measures the disorder of a heart rate, a written text, and the configurations of a lattice.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array with one row per time and one column per series, the frames of a field, or the outcomes of an ensemble. |
required |
kind
|
str
|
What to return. |
'shannon'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
order
|
float
|
The order of the Rényi entropy or the index of the Tsallis entropy. |
2.0
|
base
|
float
|
The base of the logarithm, 2 for bits. |
2.0
|
probabilities
|
bool
|
Whether every series is already a probability vector. |
False
|
dimension
|
int | tuple[int, int]
|
The length of patterns or the largest block length, or the window |
3
|
delay
|
int
|
The number of steps between the values of an ordinal pattern. |
1
|
tolerance
|
float
|
The largest distance of close patterns, as a fraction of the standard deviation. |
0.2
|
scales
|
Sequence[int]
|
The window lengths of the multiscale entropy. |
tuple(range(1, 11))
|
normalize
|
bool
|
Whether to divide by the largest value, so the entropy lies between 0 and 1. |
True
|
dt
|
float
|
The time between samples of the spectral entropy. |
1.0
|
measure
|
str
|
The entropy of the ordinal patterns: |
'shannon'
|
ties
|
str
|
|
'order'
|
random_state
|
int | None
|
The seed of the random ranks of equal values. |
None
|
reference
|
ArrayLike | None
|
The probability of every outcome under the reference law of an ensemble, such as the stationary law. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
EntropyResult
|
The values read, their entropy, and the divergence of an ensemble. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, a setting is out of range, or the outcomes of an ensemble lie outside the reference law. |
See Also
information: Gives the information among series. complexity: Places series on the complexity and entropy plane of Rosso.
Examples:
>>> from skcomplex.core.analysis import entropy
>>> entropy([0, 1, 0, 1]).entropy.tolist()
[1.0]
Source code in src/skcomplex/core/analysis/_entropy.py
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 225 226 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 | |
epsilon_machine(source, *, variables=None, max_length=3, significance=0.001)
Return the smallest machine of hidden states that predicts a series of symbols.
It groups the pasts of up to max_length symbols into hidden states, two pasts sharing a state when a chi-square
test finds the same chances of the next symbol after both, and splits states until every symbol leads to one next
state, the method CSSR. The machine shows how much a series remembers and how random it is. It finds the hidden
states of a cellular automaton, of the spikes of a neuron, and of a written text.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array that holds one series of symbols. |
required |
variables
|
Sequence[str] | None
|
The variable of a trajectory to read, a list of one name, or |
None
|
max_length
|
int
|
The longest history, kept well below the logarithm of the series length in the alphabet size. |
3
|
significance
|
float
|
The significance level of the test that splits a history from a state. |
0.001
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
EpsilonMachineResult
|
The series, the causal states with their histories, transitions, and laws, and their entropies. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A setting is out of range, the source does not hold one series, or the longest history is not shorter than the series. |
See Also
symbolic: Turns a series into symbols and measures their patterns. markov: Fits a chain of moves between observed states.
Examples:
>>> from skcomplex.core.analysis import epsilon_machine
>>> machine = epsilon_machine([0, 0, 1] * 300, max_length=3)
>>> len(machine.histories), round(machine.statistical_complexity, 3), round(machine.entropy_rate, 3)
(3, 1.585, 0.0)
Source code in src/skcomplex/core/analysis/_computational_mechanics.py
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 | |
ergodicity(source, *, kind='breaking', variables=None, start=0.01, dt=1.0, bins=None, value_range=None, edges=None, samples=100)
Return whether a time average equals an ensemble average, of one kind.
The ensemble kinds read one row per run and one column per time, such as ExperimentResult.get_ensemble returns,
and compare what one run visits over time with what all runs visit, such as a breaking of 0 for two runs that swap
between 1 and -1. The density kinds read one long run or a map of the line and give the density it settles to. It
asks whether the growth of one fortune, the motion of one gas molecule, or one firing neuron stands for the whole
ensemble.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource | Callable[[Array], Array]
|
The runs of an ensemble, one row per run, for the ensemble kinds, the trajectory or the values of one run
for |
required |
kind
|
str
|
What to return. |
'breaking'
|
variables
|
Sequence[str] | None
|
The variable of a trajectory whose values |
None
|
start
|
float
|
The fraction of the run after which the exponent of the metric is fitted, at 50 log-spaced times. |
0.01
|
dt
|
float
|
The time between the columns of the runs. |
1.0
|
bins
|
int | ArrayLike | None
|
The number of bins or their edges, or |
None
|
value_range
|
tuple[float, float] | None
|
The range of the bins, or |
None
|
edges
|
ArrayLike | None
|
The increasing edges of the cells of |
None
|
samples
|
int
|
The number of evenly spaced points per cell of |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ErgodicityResult
|
The values read and the diagnostic of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a setting is out of range, the edges of the Ulam chain are missing, the map is not callable, or the ensemble has fewer than two runs. |
See Also
irreversibility: Measures how far a run is from its reverse in time. markov: Estimates a Markov chain from a run.
Examples:
>>> from skcomplex.core.analysis import ergodicity
>>> runs = [[1.0, -1.0, 1.0, -1.0], [-1.0, 1.0, -1.0, 1.0]]
>>> ergodicity(runs).ergodicity_breaking
0.0
Source code in src/skcomplex/core/analysis/_ergodicity.py
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 225 226 227 228 229 230 231 232 233 234 235 | |
events(source, *, kind='detect', variables=None, threshold=0.0, window=None, start=0.0, end=None, max_step=40, dt=1.0)
Return the events of one series or of event times, of one kind.
An event is a run of consecutive values above a threshold, such as the bursts of sizes 4 and 2 in
[0, 3, 1, 0, 0, 2, 0], with the waiting time between them. Times are the times of a trajectory, and the step
indices of an array. It finds the crashes of a market, the spikes of a neuron, the avalanches of a sandpile, and
the floods of a river.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array that holds one series, or one column per trial for |
required |
kind
|
str
|
What to return. |
'detect'
|
variables
|
Sequence[str] | None
|
The one variable of a trajectory to read, or |
None
|
threshold
|
float
|
The value an event must exceed, or the largest absolute value of a laminar phase. |
0.0
|
window
|
float | None
|
The length of every window of |
None
|
start
|
float
|
The start of the first window. |
0.0
|
end
|
float | None
|
The end of the last full window, or |
None
|
max_step
|
int
|
The largest step |
40
|
dt
|
float
|
The duration of a step of the branching ratio. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
EventsResult
|
The values read and the events, counts, durations, excursions, or branching ratio of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a setting is out of range, or the source does not suit the kind. |
See Also
distribution: Fits the distribution of the sizes or the waiting times. fit_law: Fits a power law to the sizes of avalanches.
Examples:
>>> from skcomplex.core.analysis import events
>>> found = events([0, 3, 1, 0, 0, 2, 0])
>>> found.sizes.tolist(), found.durations.tolist(), found.waiting_times.tolist()
([4.0, 2.0], [2.0, 1.0], [2.0])
Source code in src/skcomplex/core/analysis/_events.py
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 225 226 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 | |
fit_law(source, *, law='power', variables=None, group=None, minimum=None, maximum=None, discrete=False, bootstrap=100, candidates=50, compare_with=ALTERNATIVES, block=None, fixed=None, simulations=199, random_state=0)
Return the law fitted to the values of a source, pooled into one sample.
It pools the series of a trajectory or an array, or the speeds of the agents of a trajectory at every frame, into
one sample and fits the law to it, such as an exponent near 2.5 for samples drawn from p(x) ∝ x^-2.5. It tests
whether the sizes of earthquakes, cities, or firms follow a power law, and whether the energies of a gas or the
money of traders are exponential.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of samples. |
required |
law
|
str
|
The law to fit. |
'power'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
group
|
str | None
|
The path of the agent or particle group whose speeds are read, or |
None
|
minimum
|
float | None
|
A fixed lower cutoff of the power law, or |
None
|
maximum
|
float | None
|
A fixed upper cutoff of the power law, or |
None
|
discrete
|
bool
|
Whether the samples of the power law are integers, such as avalanche sizes. |
False
|
bootstrap
|
int
|
The number of bootstrap samples for the p-value of the power law, 0 for none. |
100
|
candidates
|
int
|
The largest number of lower cutoffs tried. |
50
|
compare_with
|
Sequence[str]
|
The alternatives the power law is compared with, among |
ALTERNATIVES
|
block
|
int | None
|
The number of samples per block of the extreme-value law. |
None
|
fixed
|
Mapping[str, float] | None
|
The parameters of a named law held fixed by SciPy name, such as |
None
|
simulations
|
int
|
The number of Monte Carlo samples of the null distribution of a named law. |
199
|
random_state
|
int | None
|
The seed of the bootstrap of the power law and of the Monte Carlo samples of a named law. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
FitLawResult
|
The pooled sample and the fitted law. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The law or an alternative is unknown, a setting the law does not read is changed, a needed setting is missing, or the sample is too small for the fit. |
See Also
distribution: Measures the shape of a distribution without fitting a law. scaling: Fits how a measure grows with the size of a sample.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import fit_law
>>> samples = (1 - np.random.default_rng(0).random(5000)) ** (-1 / 1.5)
>>> round(fit_law(samples, law='power', minimum=1.0, bootstrap=0).exponent, 1)
2.5
Source code in src/skcomplex/core/analysis/_fit.py
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 225 226 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 | |
information(source, *, kind='mutual', variables=None, symbols=None, bins=2, order=3, delay=1, history=1, lag=1, max_delay=100, dimension=8, estimator='plugin', k=3, base=2.0)
Return the information among the series of a source, of one kind.
Information counts in bits how much knowing one series tells about another, about its own future, or how much all
series share, such as the 1 bit that a coin flip passes to a copy of it one step later. Every kind but
'kl-divergence' reads the series as symbols, or first turns them into symbols with symbols. It measures the
flow of information between regions of the brain, between markets, and between the members of a flock.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one row per time and one column per series. |
required |
kind
|
str
|
What to return. |
'mutual'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
symbols
|
str | None
|
|
None
|
bins
|
int
|
The number of symbols of bins and quantiles. |
2
|
order
|
int
|
The length of ordinal patterns. |
3
|
delay
|
int
|
The number of steps between the values of an ordinal pattern. |
1
|
history
|
int
|
The number of past values of the target of the transfer entropy, or of the series of the storage. |
1
|
lag
|
int
|
The delay of the source of the transfer entropy. |
1
|
max_delay
|
int
|
The largest delay of the auto mutual information. |
100
|
dimension
|
int
|
The largest block length of the correlation information. |
8
|
estimator
|
str
|
|
'plugin'
|
k
|
int
|
The number of neighbours of the |
3
|
base
|
float
|
The base of the logarithm, 2 for bits. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
InformationResult
|
The series, their symbols, and the information among them. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, or a setting is out of range. |
See Also
partial_information: Splits the information of two sources into unique, shared, and synergistic parts. local_information: Gives the information at every time step. entropy: Measures how unpredictable a series is.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import information
>>> x = np.random.default_rng(0).integers(0, 2, 10000)
>>> transfer = information(np.column_stack([x, np.roll(x, 1)]), kind='transfer')
>>> transfer.information.round(1).tolist()
[[nan, 1.0], [0.0, nan]]
Source code in src/skcomplex/core/analysis/_information.py
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 225 226 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 | |
invariants(source, *, expressions=(), samples=16, random_state=None)
Return the rates of expressions of a system and whether they are conserved.
The rate df/dt of an expression f is its derivative along the equations of the system, diff(f, t) + sum
df/dx x'. An expression is conserved when its rate simplifies to zero, or, when simplification does not decide,
when the rate is zero within a tolerance at random states with the parameters at their values, such as the energy
x² + x'² of a unit spring. The expressions are Observables whose expression is a function of the namespace of
the system, where s.<element>.<state> is the symbol of a state. It finds the conserved energy of a pendulum, the
conserved total of an epidemic, and the conserved money of an exchange economy.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, or a trajectory of it. |
required |
expressions
|
Sequence[Observable]
|
The expressions to check. |
()
|
samples
|
int
|
The number of random states of the numeric check. |
16
|
random_state
|
int | Generator | None
|
The seed or generator of the random states. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
InvariantsResult
|
The rates of the expressions and whether they are conserved. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The source is not a system, the system is not an ODE, or an expression or the number of samples is invalid. |
See Also
stability: Finds the fixed points of a system and whether they are stable. symbolic: Derives the equations of a system as symbolic expressions.
Examples:
>>> from skcomplex.core.analysis import invariants
>>> from skcomplex.core.components import Observable
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> energy = Observable('energy', lambda s: s.mass.x**2 + s.mass.x_d1**2)
>>> invariants(HarmonicOscillatorSystem(), expressions=[energy]).conserved
{'energy': True}
Source code in src/skcomplex/core/analysis/_invariants.py
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 | |
irreversibility(source, *, kind='entropy-production', variables=None, rates=None, duration=None, drive=1.0, intensity=1.0, dt=1.0, n_states=None, significance=0.05, bins=40, entropy=None, resamples=200, random_state=None, unperturbed=None, field=1.0, correlation=None)
Return the irreversibility of a process, of one kind.
A process is reversible when a film of it run backwards is as likely as the film run forwards. The kinds read a
rate matrix, jump paths, Langevin paths, samples, or ensembles, and give how much entropy the process produces,
whether its transitions balance, or how it responds to a field, such as an entropy production of ln 2 for a ring
of five states that steps forward twice as often as back. It measures how far molecular motors, heart beats, and
the prices of a market are from equilibrium.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The rate matrix, the trajectory or an array of paths, one row per path, the samples, or the ensemble the kind measures. |
required |
kind
|
str
|
What to return. |
'entropy-production'
|
variables
|
Sequence[str] | None
|
The discrete state or the position of a trajectory to read, or |
None
|
rates
|
ArrayLike | None
|
The rate of every jump, one row per origin. |
None
|
duration
|
float | None
|
The duration of every jump path, or |
None
|
drive
|
Callable[[Array], Array] | float
|
The drift along a Langevin path, a function of position or a constant. |
1.0
|
intensity
|
float
|
The factor |
1.0
|
dt
|
float
|
The time between frames of Langevin paths, or between records of a discrete path. |
1.0
|
n_states
|
int | None
|
The number of states, or |
None
|
significance
|
float
|
The level below which the p-value rejects detailed balance. |
0.05
|
bins
|
int
|
The number of bins of entropy, symmetric about 0. |
40
|
entropy
|
float | None
|
The mean entropy produced along a path over the duration of the currents. |
None
|
resamples
|
int
|
The number of bootstrap resamples of the standard error of the uncertainty product. |
200
|
random_state
|
int | None
|
The seed of the bootstrap. |
None
|
unperturbed
|
ArrayLike | None
|
The ensemble without the field, one row per run and one column per frame. |
None
|
field
|
float
|
The strength of the field. |
1.0
|
correlation
|
ArrayLike | None
|
The two-time correlation over lags from 0. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
IrreversibilityResult
|
The values read and the measures of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a setting the kind needs is missing, a setting is out of range, or the data do not suit the kind. |
See Also
ergodicity: Tells whether one run stands for the whole ensemble. markov: Estimates the Markov chain of a discrete path.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import irreversibility
>>> ring = 2 * np.roll(np.eye(5), 1, axis=1) + np.roll(np.eye(5), -1, axis=1)
>>> production = irreversibility(ring).entropy_production
>>> bool(abs(production - np.log(2)) < 1e-12)
True
Source code in src/skcomplex/core/analysis/_irreversibility.py
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 225 226 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 | |
kramers_moyal(source, *, variables=None, dt=1.0, bins=50, bandwidth=None)
Return the drift and the diffusion of one series.
The drift is the mean step from a value per unit time and the diffusion half the mean squared step, so a series
that follows dx = a(x) dt + sqrt(2 D(x)) dW gives a and D, such as a diffusion of 1 for a random walk whose
steps have the variance 2 dt. The steps are binned by the value they start from, and an Epanechnikov kernel
smooths the bins, the estimator of Lamouroux and Lehnertz. It estimates the pull and the noise of wind speeds,
heart rates, and exchange rates from one record.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array that holds one series. |
required |
variables
|
Sequence[str] | None
|
The variable of a trajectory to read, or |
None
|
dt
|
float
|
The time between samples. |
1.0
|
bins
|
int
|
The number of bins of values. |
50
|
bandwidth
|
float | None
|
The width of the Epanechnikov kernel, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
KramersMoyalResult
|
The series, the centres of the bins, and the drift and the diffusion in every bin. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A setting is not positive, the source does not hold one series of at least two values, or the series is constant without a bandwidth. |
See Also
sparse_identification: Finds the equations of a series from a library of terms. fit_law: Fits a law to the values of a series.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import kramers_moyal
>>> x = np.cumsum(np.random.default_rng(0).normal(0, np.sqrt(0.02), 100_000))
>>> round(float(np.median(kramers_moyal(x, dt=0.01, bins=21).diffusion)), 1)
1.0
Source code in src/skcomplex/core/analysis/_kramers_moyal.py
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 | |
large_deviations(source, *, kind='tilted', variables=None, weights=None, tilts=1.0, values=None, block=10, dt=1.0, observable=None, population=1000, interval=1.0, until=20.0, random_state=None, simulation=None, bins=41, value_range=None, log_weights=None)
Return the large deviations of a time-additive observable, of one kind.
A time-additive observable sums over a run, such as the number of jumps or the money paid out, and its rare
values have odds that fall off as exp(-T I(a)) with the length T of the run. The kinds estimate the scaled
cumulant generating function lambda(k) at the tilts, and with values the rate function
I(a) = max_k (k a - lambda(k)), such as lambda(1) = 2 (e - 1) for the count of a Poisson process of rate 2. It
estimates the odds of a run of losses of an insurer, a rare current through a channel, or a long drought.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource | ProblemSpec | Mapping[int, ArrayLike]
|
The rate matrix for |
required |
kind
|
str
|
What to return. |
'tilted'
|
variables
|
Sequence[str] | None
|
The series of a trajectory whose values are the increments of |
None
|
weights
|
ArrayLike | None
|
The increment of the observable at every jump of |
None
|
tilts
|
float | ArrayLike
|
The values of the tilt |
1.0
|
values
|
ArrayLike | None
|
The values |
None
|
block
|
int
|
The number of steps of every block. |
10
|
dt
|
float
|
The time of one step. |
1.0
|
observable
|
str | Callable[[Trajectory], float] | None
|
The dotted name of a state whose increment over each interval is the observable, such as a counter, or a function of the trajectory of one interval that returns the increment. |
None
|
population
|
int
|
The number of clones. |
1000
|
interval
|
float
|
The time between two selection steps. |
1.0
|
until
|
float
|
The simulated time of every clone, a multiple of the interval. |
20.0
|
random_state
|
int | None
|
The seed of the clones and of the selection. |
None
|
simulation
|
Mapping[str, object] | None
|
Other run settings, such as |
None
|
bins
|
int | ArrayLike
|
The number of bins or their edges of |
41
|
value_range
|
tuple[float, float] | None
|
The range of the bins, or |
None
|
log_weights
|
ArrayLike | None
|
The logarithm of the ratio of the new to the old probability of every sample. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
LargeDeviationsResult
|
The data read, the generating function at every tilt, and the rate function at the values. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a setting the kind needs is missing, a setting is out of range, or the source does not suit the kind. |
See Also
events: Finds the events of a series and counts them in windows. fit_law: Fits a law to the tail of a sample.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import large_deviations
>>> tilts = np.linspace(-3, 3, 6001)
>>> rate = large_deviations([[2.0]], weights=[[1.0]], tilts=tilts, values=[3.0])
>>> round(float(rate.rate_function[0]), 4)
0.2164
Source code in src/skcomplex/core/analysis/_large_deviations.py
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 225 226 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 | |
linearization(source, *, controls=None, outputs=None, at=None, state_weights=None, control_weights=None)
Return the linear state-space system of a system near an operating point.
The system is x' = A x + B u, y = C x + D u. The matrices are the Jacobians of the rates and of the outputs,
derived symbolically and evaluated at the operating point. The controls are parameters or adaptive parameters,
named by their dotted names, such as the force 'cart.force' that no law of the plant changes, and the outputs are
states or controls. The system is controllable when the rank of [B, AB, ..., A^(n-1) B] equals the number of
states, and observable when the rank of [C; CA; ...; C A^(n-1)] does. With weights of the states and the
controls, the gain K of the linear quadratic regulator u = -K x makes ∫ (x' Q x + u' R u) dt smallest. It
gives the linear model of an aircraft near trim, a power grid near its operating point, or an economy near its
steady state, for control.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it. |
required |
controls
|
Sequence[str] | None
|
The dotted names of the parameters or adaptive parameters that are inputs, or |
None
|
outputs
|
Sequence[str] | None
|
The dotted names of the states and controls that are outputs, or |
None
|
at
|
Mapping[str, float] | None
|
The values of states and controls at the operating point, by dotted name, or |
None
|
state_weights
|
ArrayLike | None
|
The weight |
None
|
control_weights
|
ArrayLike | None
|
The weight |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
LinearizationResult
|
The state-space matrices, their ranks, and the gain of the regulator. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
Only one of the weights is given, or a control or an output is unknown. |
ValidationError
|
The system does not run in continuous time. |
See Also
stability: Finds the fixed points of a system and whether they are stable. sparse_identification: Finds the equations of a system from its data.
Examples:
>>> from skcomplex.core.analysis import linearization
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> result = linearization(HarmonicOscillatorSystem(), controls=['spring.k'])
>>> result.B.tolist(), result.controllability
([[0.0], [-1.0]], 2)
Source code in src/skcomplex/core/analysis/_linearization.py
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 | |
local_information(source, *, kind='entropy', variables=None, history=1, lag=1, estimator='plugin', base=2.0)
Return the local information of every series or every pair of series.
Local information splits an average such as the entropy or the mutual information into one value per sample, so a
rare value carries more bits than a common one, such as 2 bits for the 1 of [0, 0, 0, 1]. The probabilities are
the frequencies of symbols, or the densities of a fitted Gaussian. It finds the moments when information moves in
a flock, in a cellular automaton, and in the spikes of neurons.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one row per time and one column per series. |
required |
kind
|
str
|
What to return. |
'entropy'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
history
|
int
|
The number of past target values of the transfer entropy. |
1
|
lag
|
int
|
The delay of the source of the transfer entropy. |
1
|
estimator
|
str
|
|
'plugin'
|
base
|
float
|
The base of the logarithm, 2 for bits. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
LocalInformationResult
|
The series and their local information. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, or a setting is out of range. |
See Also
information: Gives the average information among series. entropy: Measures how unpredictable a series is.
Examples:
>>> from skcomplex.core.analysis import local_information
>>> local = local_information([[0, 0], [0, 0], [1, 1], [1, 0]], kind='mutual')
>>> local.information[0, 1].round(3).tolist()
[0.415, 0.415, 1.0, -0.585]
Source code in src/skcomplex/core/analysis/_local_information.py
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 | |
loops(source, *, kind='loops', at=None, frame=-1, quantity=None)
Return the feedback loops of the signed dependency graph of a system.
The graph has the states as nodes and an edge from x_j to x_i when the rate of x_i depends on x_j, with
the sign of df_i/dx_j, the entry of the Jacobian, and a loop is a closed path of edges, reinforcing when the
product of its signs is positive and balancing when it is negative, such as word of mouth and saturation in the
spread of a product. The rate of a map is its next value minus itself, and delays and smoothings pass their input
with gain one. It finds the reinforcing and balancing loops of a model of system dynamics, a gene network, and an
ecosystem.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it, and a trajectory for |
required |
kind
|
str
|
What to return. |
'loops'
|
at
|
ArrayLike | None
|
The state vector the signs of |
None
|
frame
|
int
|
The index of the frame of the flow matrix. |
-1
|
quantity
|
str | None
|
The quantity whose flows form the rows of the flow matrix, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
LoopsResult
|
The loops with their graph, their gains along the trajectory, or the flow matrix. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, the kind reads a trajectory and gets another source, the system has no loop to dominate, or it declares no flows for a flow matrix. |
See Also
stability: Finds the fixed points of a system and whether they are stable. elementary_modes: Finds the simplest steady routes through a network of flows.
Examples:
>>> from skcomplex.core.analysis import loops
>>> from skcomplex.systems.economics.innovation import BassDiffusionSystem
>>> trajectory = BassDiffusionSystem().prepare().simulate(until=2, dt=1)
>>> loops(trajectory, kind='dominance').gains.shape
(3, 2)
Source code in src/skcomplex/core/analysis/_loops.py
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 | |
lyapunov(source, *, kind='spectrum', variables=None, n_exponents=None, until=None, dt=None, transient=None, parameters=None, dimension=3, delay=1, min_separation=None, trajectory_length=20, skip=0)
Return the Lyapunov exponents of a system, or the largest exponent of series.
An exponent is the average rate at which two nearby runs separate, |δx(t)| ≈ |δx(0)| exp(λ t), and a positive
largest exponent means chaos, such as ln 2 per step for the logistic map at r = 4. The exponents of a system
come from its equations, and the largest exponent of a series from how fast its close returns drift apart. It
measures how fast small errors grow in the weather, a double pendulum, and the orbits of asteroids.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it for |
required |
kind
|
str
|
What to return. |
'spectrum'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read for |
None
|
n_exponents
|
int | None
|
The number of exponents of the spectrum, or |
None
|
until
|
float | None
|
The time averaged over, or the number of iterations of a map, or |
None
|
dt
|
float | None
|
The fixed step of the RK4 integration of flows, or the time between samples of a series, or |
None
|
transient
|
float | None
|
The time, or the number of iterations, run before averaging, or |
None
|
parameters
|
Mapping[str, float] | None
|
Values of parameters by dotted path that replace the system's values. |
None
|
dimension
|
int
|
The dimension of the delay embedding. |
3
|
delay
|
int
|
The delay of the embedding in steps. |
1
|
min_separation
|
int | None
|
The fewest steps between neighbours, or |
None
|
trajectory_length
|
int
|
The number of steps over which the divergence of neighbours is followed and fitted. |
20
|
skip
|
int
|
The number of first steps of the divergence left out of the fit, while neighbours align with the unstable direction. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
LyapunovResult
|
The spectrum with its dimension and entropy, or the largest exponent of every series. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, or a setting is not positive. |
TagError
|
The system of the source is stochastic, since the exponents need a deterministic system. |
See Also
embedding: Gives the points made of delayed copies of one series. stability: Finds the fixed points of a system and whether they are stable.
Examples:
>>> from skcomplex.core.analysis import lyapunov
>>> from skcomplex.systems.mathematics.dynamical_systems import LogisticMapSystem
>>> float(lyapunov(LogisticMapSystem(r=4.0), until=20000).exponents[0].round(2))
0.69
Source code in src/skcomplex/core/analysis/_lyapunov.py
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 225 226 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 | |
markov(source, *, kind='transition-matrix', variables=None, matrix=None, n_states=None, lag=1, lags=(1,), n_timescales=1, n_metastable=None, reversible=True, dt=1.0)
Return the Markov chain of the paths of a source, or of a matrix.
A Markov chain moves between states with chances that depend only on the current state, so it is the matrix of
the chances of every move, such as the row [0.5, 0.5] of a state that the path [0, 1, 0, 1, 1] leaves for
either state alike. The kinds read the integer states of one path, or one row per path, or a matrix with matrix.
It estimates the chain of weather states, credit ratings, and the shapes of a folding protein from their paths.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory of a jump process or of a map with discrete states, an array of integer states with one
row per path, or a transition or rate matrix with |
required |
kind
|
str
|
What to return. |
'transition-matrix'
|
variables
|
Sequence[str] | None
|
The discrete state of a trajectory to read, or |
None
|
matrix
|
str | None
|
|
None
|
n_states
|
int | None
|
The number of states of the paths, or |
None
|
lag
|
int
|
The lag time in steps. |
1
|
lags
|
Sequence[int]
|
The lag times in steps of the implied timescales. |
(1,)
|
n_timescales
|
int
|
The number of implied timescales. |
1
|
n_metastable
|
int | None
|
The number of metastable sets PCCA+ groups the states into, or |
None
|
reversible
|
bool
|
Whether the state systems obey detailed balance, which PCCA+ needs. |
True
|
dt
|
float
|
The time of one step. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
MarkovResult
|
The paths or the matrix read, and the quantities of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, or a setting is out of range. |
See Also
passage: Measures the times a path takes to reach a level or a set of states. irreversibility: Measures how far a process is from its reverse in time.
Examples:
>>> from skcomplex.core.analysis import markov
>>> markov([0, 1, 0, 1, 1]).transition_matrix.tolist()
[[0.0, 1.0], [0.5, 0.5]]
Source code in src/skcomplex/core/analysis/_markov.py
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 225 226 227 228 229 230 231 232 233 234 | |
mode_decomposition(source, *, variables=None, rank=None, dictionary=None, inputs=None, validation=0.2, horizon=0, dt=1.0, label='surrogate')
Return the linear system fitted to series by dynamic mode decomposition.
It fits the matrix A of g(t + dt) = A g(t) to the pairs of consecutive samples of every run by the exact DMD of
PyDMD, and returns a System that follows dg/dt = L g with L = Phi diag(ln(mu) / dt) Phi^+, starting at the
first sample of the first run, such as the frequencies 1 and -1 of a point that turns on the unit circle. With a
dictionary, g holds the observables it computes from the variables, and with inputs the fit is
g(t + dt) = A g(t) + B u(t) and the system follows dg/dt = L g + M u. It finds the patterns of a fluid flow,
brain activity, and traffic in a city, and forecasts them.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Runs
|
A trajectory, an array with one row per sample, or several runs as a list or a 3-D array. |
required |
variables
|
Sequence[str] | None
|
The variables of trajectories, or |
None
|
rank
|
float | None
|
The rank of the truncated singular value decomposition: a number of modes, 0 for the optimal hard
threshold, a share of the energy below 1, or |
None
|
dictionary
|
TransformerMixin | None
|
A scikit-learn transformer that computes the observables, such as |
None
|
inputs
|
Sequence[str] | None
|
The names of the variables that are control inputs, or |
None
|
validation
|
float
|
The share of the samples of every run held out at its end to measure the validation error. |
0.2
|
horizon
|
int
|
The number of samples to forecast after the last sample of the last run, by iterating the map. |
0
|
dt
|
float
|
The time between the rows of an array. |
1.0
|
label
|
str
|
The label of the surrogate element. |
'surrogate'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ModeDecompositionResult
|
The fitted system, its errors, its modes and matrices, and the forecast. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The validation share lies outside |
See Also
sparse_identification: Finds nonlinear equations of series from a library of terms. reservoir: Fits a reservoir computer that forecasts series.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import mode_decomposition
>>> times = np.arange(0.0, 10.0, 0.1)
>>> result = mode_decomposition(np.column_stack([np.cos(times), np.sin(times)]), dt=0.1)
>>> np.sort(result.eigenvalues.imag).round(6).tolist()
[-1.0, 1.0]
Source code in src/skcomplex/core/analysis/_mode_decomposition.py
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 225 226 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 | |
motifs(source, *, kind='counts', size=3, null='switch', samples=100, random_state=None)
Return the motifs of three or four nodes of a graph or of the networks of a run.
A motif is a small connected pattern of links, such as a triangle or a path, counted wherever its nodes are linked
in that pattern and in no other way, such as the four triangles of four nodes all joined. Directed triads carry the
names of the triadic census, such as '030T' for the feedforward loop, undirected motifs the name of their shape,
and directed motifs of four nodes their smallest adjacency code. It counts the feedforward loops of a gene network,
the triangles of a social network, and the circuits of a food web.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, a graph, or a network snapshot. |
required |
kind
|
str
|
What to return. |
'counts'
|
size
|
int
|
The number of nodes of the motifs, 3 or 4. |
3
|
null
|
str
|
|
'switch'
|
samples
|
int
|
The number of random graphs. |
100
|
random_state
|
int | None
|
The seed of the ensemble. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
MotifsResult
|
The graphs and the counts or scores of their motifs. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind, size, or null ensemble is unknown, a setting the kind does not read is changed, or the number of samples is below 1. |
TagError
|
The system of a trajectory has no network space. |
See Also
network_measures: Gives measures of a graph or of the network of every frame. neighbors: Gives the neighbours of agents, grid cells, or network nodes.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import motifs
>>> motifs(nx.complete_graph(4)).counts
[{'path': 0, 'triangle': 4}]
Source code in src/skcomplex/core/analysis/_motifs.py
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 | |
neighbors(source, *, kind='distances', group=None, variables=None, box=None, bins=100, r_max=None, attribute='state', empty=None, diagonal=True)
Return the neighbours of agents in space, of grid cells, or of network nodes.
An array of positions holds one snapshot, one row per agent, or one snapshot per frame along its first axis, such
as a distance of 1 between two points at 0.5 and 9.5 in a periodic box of side 10. A trajectory gives the positions
of an agent group with the sides of its periodic space as the box, or its lattice frames for 'like-share'. A grid
array is one frame of states, and a graph carries the states on its nodes. It counts the neighbours of birds in a
flock, of cells in a tissue, of particles in a liquid, and of households in a city.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array of positions or of states, or a graph. |
required |
kind
|
str
|
What to return. |
'distances'
|
group
|
str | None
|
The path of the agent group of a trajectory, or |
None
|
variables
|
Sequence[str] | None
|
The lattice state of a trajectory whose frames |
None
|
box
|
Sequence[float] | None
|
The sides of a periodic box, or |
None
|
bins
|
int
|
The number of distance bins of |
100
|
r_max
|
float | None
|
The largest distance of |
None
|
attribute
|
str
|
The node attribute of the states of a graph. |
'state'
|
empty
|
float | None
|
The state of empty cells, left out as agents and as neighbours, or |
None
|
diagonal
|
bool
|
Whether grid cells that share only a corner are neighbours, as in Schelling's Moore neighbourhood. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
NeighborsResult
|
The data read and the neighbour statistic of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, the number of bins is below 1, the agents have no positions, or a kind that needs a periodic box has none. |
See Also
clusters: Finds the clusters of a grid, a graph, or points. motifs: Counts the small patterns of links of a network.
Examples:
>>> from skcomplex.core.analysis import neighbors
>>> neighbors([[0.5, 0.0], [9.5, 0.0]], box=[10.0, 10.0]).distances.tolist()
[[1.0, 1.0]]
Source code in src/skcomplex/core/analysis/_neighbors.py
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 191 192 193 194 195 196 197 198 199 200 201 202 | |
network_measures(source, *, kind='summary', orders=(1, 2), attribute=None, numeric=False, measure='degree', method='louvain', reference=None, random_state=None)
Return measures of a graph or of the network of every frame of a trajectory.
A network is a set of nodes joined by links, and the measures describe how many links each node has, how they cluster, and how far apart nodes are, such as the mean degree 2, clustering 0, and diameter 5 of a ring of 10 nodes. The kinds read the graph of every frame. It measures the hubs of the internet, the clustering of a social network, and the paths of a power grid.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, a graph, or a network snapshot. |
required |
kind
|
str
|
What to return. |
'summary'
|
orders
|
Sequence[int]
|
The orders |
(1, 2)
|
attribute
|
str | None
|
The node attribute of the assortativity, or |
None
|
numeric
|
bool
|
Whether the attribute is a number compared by correlation rather than a category compared by equality. |
False
|
measure
|
str
|
The centrality: |
'degree'
|
method
|
str
|
The community detection: |
'louvain'
|
reference
|
Sequence[object] | str | None
|
The reference community of every node in node order, the name of a node attribute that holds it, or
|
None
|
random_state
|
int | None
|
The seed of the Louvain method. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
NetworkMeasuresResult
|
The graphs and the measure of every frame. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind, centrality, or method is unknown, or a setting the kind does not read is changed. |
TagError
|
The system of a trajectory has no network space. |
See Also
motifs: Counts the small patterns of links of a network. neighbors: Gives the neighbours of agents, grid cells, or network nodes.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import network_measures
>>> summary = network_measures(nx.cycle_graph(10))
>>> summary.mean_degree.tolist(), summary.clustering.tolist(), summary.diameter.tolist()
([2.0], [0.0], [5])
Source code in src/skcomplex/core/analysis/_networks.py
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 225 226 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 | |
partial_information(source, *, variables=None, redundancy='mmi', base=2.0)
Return the partial information decomposition of two sources about a target.
The source holds three series: the first source, the second source, and the target. The mutual information of the
two sources together with the target splits into the information both give, the information only one of them
gives, and the information only the two together give, with a redundancy measure of dit, such as 1 bit of synergy
for a target that is the exclusive or of the sources. It splits what two genes tell about a trait, or two neurons
about a stimulus, into unique, shared, and synergistic parts.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of three columns: the two sources and the target. |
required |
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, the two sources and the target, or |
None
|
redundancy
|
str
|
The redundancy measure of |
'mmi'
|
base
|
float
|
The base of the logarithm, 2 for bits. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
PartialInformationResult
|
The symbols and the four parts of the information with their sum. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The redundancy measure is unknown, the base is not positive, or the source does not hold three series. |
See Also
information: Gives the information among series, such as the O-information of many series. local_information: Gives the information at every time step.
Examples:
>>> from skcomplex.core.analysis import partial_information
>>> xor = [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
>>> parts = partial_information(xor)
>>> round(parts.synergy, 6), round(parts.redundancy, 6)
(1.0, 0.0)
Source code in src/skcomplex/core/analysis/_partial_information.py
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 | |
passage(source, *, kind='first-passage', variables=None, threshold=None, target=None, origin=None, direction='up', level=0.0, lag=1, dt=1.0)
Return the passages of paths to a level or a set, or of a Markov chain.
A first passage is the first time a path reaches a level or enters a set of states, such as the time 2 of a path
that climbs one step at a time to the level 2, and a path that never gets there has nan. The kinds read paths,
one row per path on common times, or a transition matrix, which the matrix kinds estimate at lag from the jump
path of a trajectory. It finds the time until a population dies out, a price hits a barrier, or a protein folds.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, an array of paths, one row per path, a series for |
required |
kind
|
str
|
What to return. |
'first-passage'
|
variables
|
Sequence[str] | None
|
The discrete state of a trajectory to read, or the series for |
None
|
threshold
|
float | None
|
The level a first passage reaches. |
None
|
target
|
Sequence[float] | None
|
The states that end a passage, the absorbing states, or the target set of the chain. |
None
|
origin
|
Sequence[float] | None
|
The origin set of the chain. |
None
|
direction
|
str
|
|
'up'
|
level
|
float
|
The level of the returns. |
0.0
|
lag
|
int
|
The lag of the transition matrix in steps. |
1
|
dt
|
float
|
The time of one step of an array, while a trajectory gives its own times. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
PassageResult
|
The paths, the series, or the matrix read, and the passages of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A choice is unknown, a setting the kind does not read is changed, the sets the kind needs are missing, a setting is not positive, or the matrix is reducible. |
See Also
markov: Estimates the Markov chain of a discrete path. events: Finds the runs of a series above a threshold.
Examples:
>>> from skcomplex.core.analysis import passage
>>> passage([[0, 1, 2, 3], [0, 0, 0, 0]], threshold=2).passage_times.tolist()
[2.0, nan]
>>> passage([0, 1, 0, -1, -2, -1, 0], kind='return-times').return_times.tolist()
[2.0, 4.0]
Source code in src/skcomplex/core/analysis/_passage.py
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 | |
recurrence(source, *, variables=None, radius=None, rate=0.05, min_line=2, theiler=1, random_state=0)
Return which states of a run come close to each other, with statistics.
A run recurs when it returns close to a state it visited before. Every row of the series is a point, such as an
embedded series or the states of a trajectory, and the recurrence matrix marks every pair of times whose points lie
within radius of each other. The statistics of its diagonal and vertical lines tell periodic, chaotic, and random
runs apart, such as a determinism near 1 for a sine wave. It finds regular rhythms in heart rate records, regime
changes in climate series, and periodic orbits in simulated oscillators.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one row per point and one column per coordinate. |
required |
variables
|
Sequence[str] | None
|
The variables of a trajectory to read as coordinates, or |
None
|
radius
|
float | None
|
The recurrence radius, or |
None
|
rate
|
float
|
The share of recurrent pairs when the radius is not given. |
0.05
|
min_line
|
int
|
The shortest diagonal or vertical line counted. |
2
|
theiler
|
int
|
The number of diagonals next to the main one to leave out, so that states close in time do not count as returns. 1 leaves out the main diagonal alone. |
1
|
random_state
|
int | None
|
The seed of the sample of pairs that sets the radius of large sets. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
RecurrenceResult
|
The points, the recurrence matrix, and its quantification. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
A setting is out of range, or no pair of points recurs outside the Theiler window. |
See Also
embedding: Gives the points made of delayed copies of one series. passage: Measures the times between the returns of a series to a level.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import embedding, recurrence
>>> sine = embedding(np.sin(np.arange(2000) * 0.1), delay=15, dimension=2)
>>> bool(recurrence(sine.points).determinism > 0.95)
True
Source code in src/skcomplex/core/analysis/_recurrence.py
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 191 192 193 194 195 196 197 198 | |
renormalization(source, *, kind='laplacian', steps=3, time=None, block=2, angle='angle', beta=1.0)
Return the network at every scale of a coarse-graining of a graph or trajectory.
Every step merges nodes into supernodes, and two supernodes link when any of their nodes link, such as two dense groups joined by one link that become two linked supernodes. A trajectory gives the network of its last frame, with the values of the states and parameters of the group on its nodes as node attributes. It coarse-grains the internet, the brain, and transport networks to find their structure across scales.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, a graph, or a network snapshot. |
required |
kind
|
str
|
How to merge. |
'laplacian'
|
steps
|
int
|
The number of times the network is coarse-grained. |
3
|
time
|
float | None
|
The diffusion time of |
None
|
block
|
int
|
The number of nodes of every supernode of |
2
|
angle
|
str
|
The node attribute that holds the angle of |
'angle'
|
beta
|
float
|
The parameter of the geometric system that the weights of the angles of |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
RenormalizationResult
|
The network at every scale and its measures. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, the kind does not read a changed setting, |
TagError
|
The system of a trajectory has no network space. |
See Also
clusters: Finds the clusters of a grid, a graph, or points. network_measures: Gives measures of a graph or of the network of every frame.
Examples:
>>> import networkx as nx
>>> from skcomplex.core.analysis import renormalization
>>> blocks = nx.disjoint_union(nx.complete_graph(20), nx.complete_graph(20))
>>> blocks.add_edge(0, 20)
>>> sorted(renormalization(blocks, steps=1).graphs[1].degree())
[(0, 1), (1, 1)]
Source code in src/skcomplex/core/analysis/_renormalization.py
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 191 192 193 194 195 196 197 198 199 200 201 | |
reservoir(source, *, variables=None, kind='next_generation', delay=2, order=2, units=300, spectral_radius=0.9, leak=1.0, input_scaling=0.5, ridge=0.0001, standardize=True, warmup=None, validation=0.2, horizon=0, dt=1.0, random_state=0, label='surrogate')
Return the reservoir system whose ridge readout gives the variable increments.
A reservoir is a fixed set of features of the recent past of the variables, and a ridge regression from these
features to the change of the variables over one sample is fitted on the training samples, with ReservoirPy. The
fitted System steps once per sample and starts at the last sample of the last run with the memory the runs left,
so result.system.prepare().simulate(until=n) forecasts n samples, such as a sine wave continued to within 0.01.
It learns a model of a chaotic flow, a power demand, or a speech signal from series alone.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Runs
|
A trajectory, an array with one row per sample, or several runs as a list or a 3-D array. |
required |
variables
|
Sequence[str] | None
|
The variables of trajectories, or |
None
|
kind
|
str
|
The reservoir. |
'next_generation'
|
delay
|
int
|
The number of consecutive samples of a next-generation reservoir. |
2
|
order
|
int
|
The degree of the monomials of a next-generation reservoir. |
2
|
units
|
int
|
The number of units of an echo state network. |
300
|
spectral_radius
|
float
|
The spectral radius of the recurrent weights of an echo state network. |
0.9
|
leak
|
float
|
The leak rate of the units of an echo state network, 1 for no leak. |
1.0
|
input_scaling
|
float
|
The scale of the input weights of an echo state network. |
0.5
|
ridge
|
float
|
The strength of the ridge penalty of the readout. |
0.0001
|
standardize
|
bool
|
Whether the reservoir reads the variables divided by their standard deviations after removing their means, or the variables as they are. |
True
|
warmup
|
int | None
|
The number of first samples of every series left out of the fit while the memory fills, or |
None
|
validation
|
float
|
The share of the samples of every run held out at its end to measure the validation error. |
0.2
|
horizon
|
int
|
The number of samples to forecast after the last sample of the last run. |
0
|
dt
|
float
|
The time between the rows of an array. |
1.0
|
random_state
|
int | None
|
The seed of the random weights of an echo state network. |
0
|
label
|
str
|
The label of the surrogate element. |
'surrogate'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ReservoirResult
|
The fitted system, its errors, its reservoir map, and the forecast. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The reservoir kind is unknown, the validation share lies outside |
See Also
mode_decomposition: Fits a linear system to series. sparse_identification: Finds the equations of series from a library of terms.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import reservoir
>>> result = reservoir(np.sin(0.1 * np.arange(400.0)), variables=['x'], horizon=10)
>>> bool(abs(result.forecast[-1, 0] - np.sin(0.1 * 409)) < 0.01)
True
Source code in src/skcomplex/core/analysis/_reservoirs.py
224 225 226 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 | |
rolling(source, *, kind='variance', variables=None, window=None, detrend=False)
Return the statistic of every series in rolling windows, and its trend.
Every window holds the window values that end at a sample, possibly with a linear trend removed first, and the
statistic of the window is set at that sample. The trend of the statistic is the tau of Kendall against time, such
as 1 for the variance of [0, 1, 0, 2, 0, 3], whose swings grow. It finds the early warnings of a tipping point,
such as a rising variance before a lake turns turbid, a market crashes, or a climate shifts.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one row per time and one column per series. |
required |
kind
|
str
|
What to return. |
'variance'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
window
|
int | None
|
The number of values in every rolling window. |
None
|
detrend
|
bool
|
Whether to remove a linear trend in every window first. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
RollingResult
|
The series, the rolling statistic of every series, and its trend. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, or the window is missing or does not fit the series. |
See Also
correlation: Gives the correlation of series, of an ensemble, or of a field. events: Finds the runs of a series above a threshold.
Examples:
>>> from skcomplex.core.analysis import rolling
>>> rolling([0, 1, 0, 2, 0, 3], window=3).trend.tolist()
[1.0]
Source code in src/skcomplex/core/analysis/_rolling.py
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 | |
scaling(source, *, kind='detrended-fluctuation', variables=None, scales=None, order=1, fit_sums=(0.0001, 0.01), random_state=0, against='mean', parameters=None, critical=None, above=False, confidence=0.95, resamples=1000)
Return the scaling exponent of series, fractal dimension of points, or a law.
A scaling law says how a measure grows with the size of a window, a box, a radius, or a system, y ~ s^b, and the
exponent b is the slope of log y against log s, such as 1.5 for the fluctuations of a random walk. The kinds
read series, fields, points, or samples at several sizes. It measures the long memory of river flows, the fractal
dimension of a coastline, and the critical exponents of a magnet.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource | Mapping[float, ArrayLike]
|
The trajectory, the series, the field, the points, or a mapping from size to samples. |
required |
kind
|
str
|
What to return. |
'detrended-fluctuation'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
scales
|
Sequence[float] | None
|
The window sizes, the box sides in cells, or the radii, or |
None
|
order
|
int
|
The order of the detrending polynomial. |
1
|
fit_sums
|
tuple[float, float]
|
The smallest and largest correlation sums of the scaling region the slope is fitted in. |
(0.0001, 0.01)
|
random_state
|
int | None
|
The seed of the sample of pairs that sets the default radii, or of the bootstrap. |
0
|
against
|
str
|
What the variance-mean law is fitted against, |
'mean'
|
parameters
|
Sequence[float] | None
|
The control parameter value of every row of the series of |
None
|
critical
|
float | None
|
The value of the control parameter the distance is measured to. |
None
|
above
|
bool
|
Whether the fit uses the values above the critical value, as for couplings, rather than below it, as for temperatures. |
False
|
confidence
|
float
|
The confidence level of the interval of |
0.95
|
resamples
|
int
|
The number of bootstrap resamples of |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ScalingResult
|
What the source was read as, the exponent, and the curves it is fitted on. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind or a setting does not fit, or |
See Also
fit_law: Fits a power law to the tail of a sample. embedding: Gives the points made of delayed copies of one series.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import scaling
>>> walk = np.cumsum(np.random.default_rng(0).standard_normal(5000))
>>> scaling(walk).exponent.round(1).tolist()
[1.5]
Source code in src/skcomplex/core/analysis/_scaling.py
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 225 226 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 | |
section(source, *, kind='poincare', variables=None, state=None, value=0.0, direction=1, until=1000.0, transient=None, period=None, n_points=1000, solver=None, random_state=None)
Return the states of a flow where it crosses a value or at each period.
A section turns a flow into a map, by keeping only the states where one state crosses a value in one direction, or
the states at every period of a forcing, such as a unit spring that crosses x = 0 upward every 2 pi. It runs
the system. It turns a flow into a map of its crossings, as for the orbit of a planet, a forced pendulum, and a
heart rhythm.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it. |
required |
kind
|
str
|
What to return. |
'poincare'
|
variables
|
Sequence[str] | None
|
The dotted names of the states whose values to read at the points of a section, or |
None
|
state
|
str | None
|
The dotted name of the scalar state that defines a Poincaré section, such as |
None
|
value
|
float
|
The value of the state on the Poincaré section. |
0.0
|
direction
|
int
|
|
1
|
until
|
float
|
The time a Poincaré section runs until. |
1000.0
|
transient
|
float | None
|
The time before which crossings are discarded, or the number of periods discarded before the first
stroboscopic point. |
None
|
period
|
float | None
|
The period of the forcing, such as |
None
|
n_points
|
int
|
The number of points of a stroboscopic section. |
1000
|
solver
|
Solver | None
|
The solver, as in |
None
|
random_state
|
int | None
|
The seed of stochastic solvers. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SectionResult
|
The times, the states, and the values of the read states at the points of the section. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, a needed setting is missing, the system is not a flow in continuous time, or the state is not a scalar state. |
TagError
|
The system does not run in continuous time. |
See Also
lyapunov: Gives the rates at which nearby runs of a system separate. recurrence: Finds which states of a run come close to each other.
Examples:
>>> from skcomplex.core.analysis import section
>>> from skcomplex.systems.physics.mechanics import HarmonicOscillatorSystem
>>> len(section(HarmonicOscillatorSystem(), state='mass.x', until=20.0).times) > 2
True
Source code in src/skcomplex/core/analysis/_sections.py
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 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 | |
signatures(source)
Return the default analysis of every kind of data of a trajectory.
Every kind of data gets one figure with its curves, axis labels, and values. A series gives its power spectrum with the autocorrelation time, or its return map for a map, a jump path the survival function of its waiting times with the dispersion index of jumps per frame, and a field the structure factor of its last frame with the peak wavelength or the correlation length. Agents give their polar and milling orders over time, or their nearest neighbour distances against the Poisson law, and a network its degree distribution. It gives the first look at a run of an ecosystem, a market, or a chemical pattern.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
SignaturesResult
|
The data of every kind and one signature per kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The source is not a trajectory. |
See Also
spectrum: Gives the spectrum of every series of a source, or of a field. network_measures: Gives measures of a graph or of the network of every frame.
Examples:
>>> from skcomplex.core.analysis import signatures
>>> from skcomplex.systems.biology.ecology import LotkaVolterraSystem
>>> trajectory = LotkaVolterraSystem().prepare().simulate(until=20.0, random_state=0)
>>> [signature.title for signature in signatures(trajectory).signatures]
['Power spectrum']
Source code in src/skcomplex/core/analysis/_signatures.py
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 | |
sparse_identification(source, *, variables=None, degree=2, threshold=0.1, alpha=0.05, validation=0.2, horizon=0, dt=1.0, label='surrogate')
Return the sparse symbolic system fitted to series by SINDy, with PySINDy.
SINDy, the sparse identification of nonlinear dynamics, writes the derivative of every variable as a sum of few
monomials of the variables up to a degree, such as x' = -2 x for a decaying exponential. It estimates the
derivatives by centred finite differences and keeps the terms by least squares that drop small coefficients in
turn. The fitted System holds one rate law per variable and starts at the first sample of the first run, so
result.system.prepare().simulate(until=...) runs it. It finds the equations of a fluid flow, a chemical reaction,
and a predator and prey cycle from their series.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Runs
|
A trajectory, an array with one row per sample, or several runs as a list or a 3-D array. |
required |
variables
|
Sequence[str] | None
|
The variables of trajectories, or |
None
|
degree
|
int
|
The highest degree of the candidate monomials. |
2
|
threshold
|
float
|
The smallest magnitude of a kept coefficient. |
0.1
|
alpha
|
float
|
The strength of the ridge penalty of every least-squares fit. |
0.05
|
validation
|
float
|
The share of the samples of every run held out at its end to measure the validation error. |
0.2
|
horizon
|
int
|
The number of samples to forecast after the last sample of the last run, by simulating the fitted system. |
0
|
dt
|
float
|
The time between the rows of an array. |
1.0
|
label
|
str
|
The label of the surrogate element. |
'surrogate'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SparseIdentificationResult
|
The fitted system, its errors, its coefficients, and the forecast. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The validation share lies outside |
See Also
mode_decomposition: Fits a linear system to series. kramers_moyal: Gives the drift and the diffusion of one series.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import sparse_identification
>>> times = np.arange(0.0, 2.0, 0.001)
>>> result = sparse_identification(np.exp(-2 * times), variables=['x'], degree=1, dt=0.001)
>>> result.features, result.coefficients.round(3).tolist()
(['1', 'x'], [[0.0, -2.0]])
Source code in src/skcomplex/core/analysis/_sparse_identification.py
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 225 226 227 228 229 230 231 232 233 | |
spectrum(source, *, kind='power', variables=None, dt=1.0, spacing=1.0, frames=False)
Return the spectrum of every series of a source, or of a field.
A spectrum splits a series into waves of different frequencies and gives the power of each, such as a peak at 5
for a sine wave that turns 5 times per unit time. A field gives the power of its waves in space, read from the last
frame of a trajectory, or every frame when frames is true. It finds the rhythms of brain waves, the cycles of a
business, and the energy cascade of turbulence.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array of series or of a field. |
required |
kind
|
str
|
What to return. |
'power'
|
variables
|
Sequence[str] | None
|
The variables of a trajectory to read, or |
None
|
dt
|
float
|
The time between samples. |
1.0
|
spacing
|
float
|
The distance between neighbouring sites. |
1.0
|
frames
|
bool
|
Whether the first axis of an array indexes frames, and whether to read every frame of a trajectory. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SpectrumResult
|
The data read and its spectrum. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, or a setting is not positive. |
See Also
correlation: Gives the correlation of series, of an ensemble, or of a field. mode_decomposition: Fits a linear system to series and gives its modes.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import spectrum
>>> times = np.arange(4096) * 0.01
>>> result = spectrum(np.sin(2 * np.pi * 5 * times), dt=0.01)
>>> round(float(result.frequencies[result.power[0].argmax()]))
5
Source code in src/skcomplex/core/analysis/_spectrum.py
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 | |
stability(source, *, kind='fixed-points', parameters=None, points=None, at=None)
Return the linear stability of a system, of one kind.
A fixed point is a state that does not change, where every rate is 0 for a flow or every state equals its next value for a map, and it is stable when a small push dies out, such as the carrying capacity of logistic growth. The stability of every point comes from the eigenvalues of the Jacobian there, evaluated at the parameter values. It decides whether a steady state of an epidemic, a chemical reactor, or a power grid returns after a small push.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it for |
required |
kind
|
str
|
What to return. |
'fixed-points'
|
parameters
|
Mapping[str, float] | None
|
Values of parameters by dotted path that replace the system's values. They are substituted before solving, and without them the symbolic fixed points keep the parameters as symbols. |
None
|
points
|
Sequence[Point] | None
|
The points whose stability to analyse, each a mapping from state component name to its value, symbolic
or numeric, or |
None
|
at
|
Mapping[str, float] | None
|
The uniform state of the dispersion relation by state name, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
StabilityResult
|
The Jacobian, nullclines, and fixed points with their classes, or the dispersion relation. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The kind is unknown, a setting the kind does not read is changed, or the system has no form of the kind. |
See Also
linearization: Gives the linear state space system of a system near an operating point. lyapunov: Gives the rates at which nearby runs of a system separate.
Examples:
>>> from skcomplex.core.analysis import stability
>>> from skcomplex.systems.biology.ecology import LogisticGrowthSystem
>>> result = stability(LogisticGrowthSystem())
>>> sorted(str(point['population.x']) for point in result.fixed_points)
['0', 'K_growth']
Source code in src/skcomplex/core/analysis/_stability.py
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 | |
surrogate_test(source, *, analysis, attribute, variables=None, n=99, alternative='two-sided', random_state=None)
Return the test of an analysis of many variables against surrogates.
The surrogates shuffle every variable on its own, which keeps the values of each variable and breaks any link
between them. The analysis runs on the data and on n surrogates, and the field of its result gives the value of
each. The p-value is the fraction of surrogates, with the data counted among them, at least as extreme as the
data, such as 0.05 for three copies of one coin flip tested against 19 surrogates. It tests whether a coupling
between brain regions, markets, or climate indices is more than chance.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The trajectory, or an array with one row per sample and one column per variable. |
required |
analysis
|
Callable[[Array], object]
|
The analysis of the variables, a function of an array such as one |
required |
attribute
|
str
|
The scalar field of the result of the analysis that measures the dependence, such as |
required |
variables
|
Sequence[str] | None
|
The variables of a trajectory, or |
None
|
n
|
int
|
The number of surrogates. |
99
|
alternative
|
str
|
|
'two-sided'
|
random_state
|
int | None
|
The seed of the shuffles. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SurrogateTestResult
|
The data, the measure on the data and on every surrogate, and the p-value. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The alternative is unknown, the number of surrogates is below 1, or the analysis is not callable. |
See Also
information: Gives the information among series. correlation: Gives the correlation of series, of an ensemble, or of a field.
Examples:
>>> import numpy as np
>>> from skcomplex.core.analysis import bind_analysis, information, surrogate_test
>>> bits = np.column_stack([np.random.default_rng(0).integers(0, 2, 500)] * 3)
>>> measure = bind_analysis(information, kind='o-information')
>>> surrogate_test(bits, analysis=measure, attribute='information', n=19, random_state=0).p_value
0.05
Source code in src/skcomplex/core/analysis/_surrogates.py
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 | |
symbolic(source, *, kind='equations', use_initial_state=False)
Return the symbolic form of a system.
Each state component is a function of time t, and the equations say how it changes, such as x' = r x for
exponential growth, which Maxima solves to x(t) = x(0) e^(r t). The equations of a group hold for every member
and are named with the member index i, and components driven by a callable law or by a sum over members or pairs
are left out. It writes the equations of an epidemic, a circuit, and a mechanical system, and solves them exactly
where it can.
Read more in the user guide, under Analyse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The system, its compiled problem, or a trajectory of it. |
required |
kind
|
str
|
What to return. |
'equations'
|
use_initial_state
|
bool
|
Whether |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
SymbolicResult
|
The compiled problem and the symbolic form of the kind. |
Raises:
| Type | Description |
|---|---|
AnalysisError
|
The system has no form of the kind, such as a system that compiles to a form without equations, Maxima cannot solve its equations, or needs the sign of a parameter. |
ConservationError
|
The internal flows of a quantity do not cancel. |
See Also
invariants: Gives the rates of expressions of a system and whether they are conserved. stability: Finds the fixed points of a system and whether they are stable.
Examples:
>>> from skcomplex.core.analysis import symbolic
>>> from skcomplex.systems.biology.ecology import ExponentialGrowthSystem
>>> symbolic(ExponentialGrowthSystem()).equations['population.x']
diff(x_population(t), t) == r_growth*x_population(t)
Source code in src/skcomplex/core/analysis/_symbolic.py
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 | |