timeseries

This module defines tools for geometric analysis of one-dimensional (time-series) data sets. The main classes are

See timeseries-data for a more general outline.

Examples

>>> el = Signal([2.0, 3.0, 0.0, 5.0, 2.5, 2.9])
>>> el.make_pers()
>>> el.pers.diagram
   birth_index  death_index  birth  death  pers
0            0            1    2.0    3.0   1.0
1            4            3    2.5    5.0   2.5
2            2            3    0.0    5.0   5.0
>>> bin_counts, bins = el.pers.bin(1.0)
>>> print(bins)
[-inf   0.   1.   2.   3.   4.   5.  inf]
>>> print(bin_counts)
[[ 0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  1.]
 [ 0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  1.  1.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.]]
>>> sorted(list(el.pers.domains.keys()))
[(0, 1), (2, 3), (3, 4)]
>>> for interval in el.iter_intervals():
...     print("h_A( {} ) == {}".format(interval,el.interval_height(interval)))
h_A( (0, 1) ) == 1.0
h_A( (0, 2) ) == 0.0
h_A( (0, 3) ) == 0.0
h_A( (0, 4) ) == 0.0
h_A( (0, 5) ) == 0.0
h_A( (1, 2) ) == 0.0
h_A( (1, 3) ) == 0.0
h_A( (1, 4) ) == 0.0
h_A( (1, 5) ) == 0.0
h_A( (2, 3) ) == 5.0
h_A( (2, 4) ) == 0.0
h_A( (2, 5) ) == 0.0
h_A( (3, 4) ) == 2.5
h_A( (3, 5) ) == 0.0
h_A( (4, 5) ) == 0.0
>>> list(el.pers.forest.keys())
[None]
>>> sorted(list(el.pers.forest[None]))
[0, 1, 2]
>>> el.jagged(6.0)
0    0.0
1    0.0
2    0.0
3    0.0
4    0.0
5    0.0
dtype: float64
>>> el = Signal([6.5,0.0,2.0])
>>> el.make_pers()
>>> el.pers.diagram
   birth_index  death_index  birth  death  pers
0            1            0    0.0    6.5   6.5
>>> list(el.pers.forest[None])
[0]
>>> el.vertices
   time  height
0   0.0     6.5
1   1.0     0.0
2   2.0     2.0
>>> el.jagged() #el.pers.diagram,el.vertices.index,el.vertices.dtype)
0    6.5
1    0.0
2    0.0
dtype: float64
>>> elN = el.sample_near(sigma=0.1)
>>> elN.make_pers()
>>> elN.pers.domains == el.pers.domains
True
>>> el = Signal([6.5,7.0,2.0,4.5,3.9,9.0,8.3,8.7,5.5,9.9])
>>> el.vertices
   time  height
0   0.0     6.5
1   1.0     7.0
2   2.0     2.0
3   3.0     4.5
4   4.0     3.9
5   5.0     9.0
6   6.0     8.3
7   7.0     8.7
8   8.0     5.5
9   9.0     9.9
>>> el.edges
   src  dst  max  height
2    2    3    3     4.5
3    3    4    3     4.5
0    0    1    1     7.0
1    1    2    1     7.0
6    6    7    7     8.7
7    7    8    7     8.7
4    4    5    5     9.0
5    5    6    5     9.0
8    8    9    9     9.9
>>> el.make_pers()
>>> el.pers.diagram
   birth_index  death_index  birth  death  pers
2            6            7    8.3    8.7   0.4
1            0            1    6.5    7.0   0.5
0            4            3    3.9    4.5   0.6
3            8            5    5.5    9.0   3.5
4            2            9    2.0    9.9   7.9
>>> el.feature()
   time  height
2   2.0     2.0
3   3.0     4.5
4   4.0     3.9
5   5.0     9.0
6   6.0     8.3
7   7.0     8.7
8   8.0     5.5
9   9.0     9.9
>>> el.pers.syzygy((0,0))
2    0.4
1    0.5
0    0.6
3    3.5
4    7.9
dtype: float64
>>> el.pers.syzygy((1,2))
2     251.2908
1     159.2500
0      47.3850
3    1559.2500
4    1548.5580
dtype: float64
>>> el.pers.forest_parents == {0: 4, 1: None, 2: 3, 3: 4, 4: None}
True
>>> el.vertices['height'].sum()/len(el.vertices)
6.5299999999999994
>>> el.normalize()
>>> el2 = Signal(el.vertices)
>>> el2.make_pers()
>>> all(el2.pers.diagram == el.pers.diagram)
True
>>> el = Signal([0.0,3.0,1.5,2.2,0.001])
>>> el.make_pers()
>>> el.vertices
   time  height
0   0.0   0.000
1   1.0   3.000
2   2.0   1.500
3   3.0   2.200
4   4.0   0.001
>>> el.edges
   src  dst  max  height
2    2    3    3     2.2
3    3    4    3     2.2
0    0    1    1     3.0
1    1    2    1     3.0
>>> el.pers.diagram
   birth_index  death_index  birth  death   pers
0            2            3  1.500    2.2  0.700
1            4            1  0.001    3.0  2.999
2            0            1  0.000    3.0  3.000
>>> el = Signal([0.0,0.7,0.45,0.55,0.3, 1.0],
...             times=[0.1, 0.2, 0.3, 0.6, 0.8, 0.85])
>>> el.vertices
   time  height
0  0.10    0.00
1  0.20    0.70
2  0.30    0.45
3  0.60    0.55
4  0.80    0.30
5  0.85    1.00
>>> el.edges
   src  dst  max  height
2    2    3    3    0.55
3    3    4    3    0.55
0    0    1    1    0.70
1    1    2    1    0.70
4    4    5    5    1.00
>>> el.make_pers()
>>> el.pers.diagram
   birth_index  death_index  birth  death  pers
0            2            3   0.45   0.55   0.1
1            4            1   0.30   0.70   0.4
2            0            5   0.00   1.00   1.0
>>> el = Signal([0.0,0.5,0.4,0.9,0.1,1.0])
>>> el.make_pers()
>>> el.pers.diagram
   birth_index  death_index  birth  death  pers
0            2            1    0.4    0.5   0.1
1            4            3    0.1    0.9   0.8
2            0            5    0.0    1.0   1.0
>>> for F in el.iter_features(min_pers=0.5): print(F)
   time  height
0   0.0     0.0
1   1.0     0.5
2   2.0     0.4
3   3.0     0.9
4   4.0     0.1
5   5.0     1.0
   time  height
3   3.0     0.9
4   4.0     0.1
>>> el = Signal(np.sin(np.arange(0,8*np.pi,0.1)))
>>> el.make_pers()
>>> el.pers.domains == {(110, 204): 4, (204, 236): 3, (0, 16): 2, (47, 79): 0, (141, 173): 1}
True
>>> s = Signal([50.0, 120.0, 100, 180, 200, 150, 135])
>>> s.make_pers()
>>> s.pers.diagram
   birth_index  death_index  birth  death   pers
0            2            1  100.0  120.0   20.0
1            6            4  135.0  200.0   65.0
2            0            4   50.0  200.0  150.0
>>> s.pers.mergetree
{1: (0, 2), 4: (1, 6)}

Functions

jagged(persdiag, index) Produce a piecewise-linear function that matches the given persistence diagram.
wavy(pasrdiad, index) Produce a piecewise-sine function that matches the given persistence diagram.

Classes

Signal(values[, times])
SpaceCurve(tn[, px, py, pz, quality, …]) SpaceCurve is a Python class for studying curves in \(\mathbb{R}^2\) or \(\mathbb{R}^3\).