├── .hgignore ├── LICENSE ├── README.rst ├── setup.py ├── src └── pypsr.py └── tests ├── gfnn_test_data.csv ├── test_data_lag_30_gfnn.csv └── test_pypsr.py /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.pyc 3 | *.pyo 4 | *.egg-info 5 | .coverage 6 | .cache 7 | build 8 | .idea 9 | dist 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Henry S. Harrison 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | pypsr 2 | ===== 3 | 4 | A work-in-progress library for phase-space reconstruction in Python! 5 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | from os.path import join, dirname, splitext, basename 3 | from glob import glob 4 | 5 | 6 | def read(name): 7 | return open(join(dirname(__file__), name)).read() 8 | 9 | 10 | setup( 11 | name='pypsr', 12 | version='0.0.1', 13 | license='MIT', 14 | 15 | description='Phase-space reconstruction in Python.', 16 | long_description=read('README.rst'), 17 | 18 | author='Henry S. Harrison', 19 | author_email='henry.schafer.harrison@gmail.com', 20 | 21 | url='https://bitbucket.org/hharrison/pypsr', 22 | download_url='https://bitbucket.org/hharrison/pypsr/get/default.tar.gz', 23 | 24 | package_dir={'': 'src'}, 25 | packages=find_packages('src'), 26 | py_modules=[splitext(basename(i))[0] for i in glob(join('src', '*.py'))], 27 | 28 | keywords='phase-space reconstruction psr Taken Takens embedding ami nonlinear dynamics chaos chaotic attractor', 29 | 30 | classifiers=[ 31 | 'Programming Language :: Python', 32 | 'Programming Language :: Python :: 2', 33 | 'Programming Language :: Python :: 3', 34 | 'License :: OSI Approved :: MIT License', 35 | 'Operating System :: OS Independent', 36 | 'Development Status :: 3 - Alpha', 37 | 'Intended Audience :: Science/Research', 38 | 'Topic :: Utilities', 39 | 'Topic :: Scientific/Engineering', 40 | ], 41 | 42 | install_requires=[ 43 | 'numpy', 44 | 'scipy', 45 | 'scikit-learn', 46 | 'toolz', 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /src/pypsr.py: -------------------------------------------------------------------------------- 1 | from operator import sub 2 | 3 | import numpy as np 4 | from sklearn import metrics 5 | from sklearn.neighbors import NearestNeighbors 6 | from toolz import curry 7 | 8 | 9 | def global_false_nearest_neighbors(x, lag, min_dims=1, max_dims=10, **cutoffs): 10 | """ 11 | Across a range of embedding dimensions $d$, embeds $x(t)$ with lag $\tau$, finds all nearest neighbors, 12 | and computes the percentage of neighbors that that remain neighbors when an additional dimension is unfolded. 13 | See [1] for more information. 14 | 15 | Parameters 16 | ---------- 17 | x : array-like 18 | Original signal $x(t). 19 | lag : int 20 | Time lag $\tau$ in units of the sampling time $h$ of $x(t)$. 21 | min_dims : int, optional 22 | The smallest embedding dimension $d$ to test. 23 | max_dims : int, optional 24 | The largest embedding dimension $d$ to test. 25 | relative_distance_cutoff : float, optional 26 | The cutoff for determining neighborliness, 27 | in distance increase relative to the original distance between neighboring points. 28 | The default, 15, is suggested in [1] (p. 41). 29 | relative_radius_cutoff : float, optional 30 | The cutoff for determining neighborliness, 31 | in distance increase relative to the radius of the attractor. 32 | The default, 2, is suggested in [1] (p. 42). 33 | 34 | Returns 35 | ------- 36 | dims : ndarray 37 | The tested dimensions $d$. 38 | gfnn : ndarray 39 | The percentage of nearest neighbors that are false neighbors at each dimension. 40 | 41 | See Also 42 | -------- 43 | reconstruct 44 | 45 | References 46 | ---------- 47 | [1] Arbanel, H. D. (1996). *Analysis of Observed Chaotic Data* (pp. 40-43). New York: Springer. 48 | 49 | """ 50 | x = _vector(x) 51 | 52 | dimensions = np.arange(min_dims, max_dims + 1) 53 | false_neighbor_pcts = np.array([_gfnn(x, lag, n_dims, **cutoffs) for n_dims in dimensions]) 54 | return dimensions, false_neighbor_pcts 55 | 56 | 57 | def _gfnn(x, lag, n_dims, **cutoffs): 58 | # Global false nearest neighbors at a particular dimension. 59 | # Returns percent of all nearest neighbors that are still neighbors when the next dimension is unfolded. 60 | # Neighbors that can't be embedded due to lack of data are not counted in the denominator. 61 | offset = lag*n_dims 62 | is_true_neighbor = _is_true_neighbor(x, _radius(x), offset) 63 | return np.mean([ 64 | not is_true_neighbor(indices, distance, **cutoffs) 65 | for indices, distance in _nearest_neighbors(reconstruct(x, lag, n_dims)) 66 | if (indices + offset < x.size).all() 67 | ]) 68 | 69 | 70 | def _radius(x): 71 | # Per Arbanel (p. 42): 72 | # "the nominal 'radius' of the attractor defined as the RMS value of the data about its mean." 73 | return np.sqrt(((x - x.mean())**2).mean()) 74 | 75 | 76 | @curry 77 | def _is_true_neighbor( 78 | x, attractor_radius, offset, indices, distance, 79 | relative_distance_cutoff=15, 80 | relative_radius_cutoff=2 81 | ): 82 | distance_increase = np.abs(sub(*x[indices + offset])) 83 | return (distance_increase / distance < relative_distance_cutoff and 84 | distance_increase / attractor_radius < relative_radius_cutoff) 85 | 86 | 87 | def _nearest_neighbors(y): 88 | """ 89 | Wrapper for sklearn.neighbors.NearestNeighbors. 90 | Yields the indices of the neighboring points, and the distance between them. 91 | 92 | """ 93 | distances, indices = NearestNeighbors(n_neighbors=2, algorithm='kd_tree').fit(y).kneighbors(y) 94 | for distance, index in zip(distances, indices): 95 | yield index, distance[1] 96 | 97 | 98 | def reconstruct(x, lag, n_dims): 99 | """Phase-space reconstruction. 100 | 101 | Given a signal $x(t)$, dimensionality $d$, and lag $\tau$, return the reconstructed signal 102 | \[ 103 | \mathbf{y}(t) = [x(t), x(t + \tau), \ldots, x(t + (d - 1)\tau)]. 104 | \] 105 | 106 | Parameters 107 | ---------- 108 | x : array-like 109 | Original signal $x(t)$. 110 | lag : int 111 | Time lag $\tau$ in units of the sampling time $h$ of $x(t)$. 112 | n_dims : int 113 | Embedding dimension $d$. 114 | 115 | Returns 116 | ------- 117 | ndarray 118 | $\mathbf{y}(t)$ as an array with $d$ columns. 119 | 120 | """ 121 | x = _vector(x) 122 | 123 | if lag * (n_dims - 1) >= x.shape[0] // 2: 124 | raise ValueError('longest lag cannot be longer than half the length of x(t)') 125 | 126 | lags = lag * np.arange(n_dims) 127 | return np.vstack([x[lag:lag - lags[-1] or None] for lag in lags]).transpose() 128 | 129 | 130 | def ami(x, y=None, n_bins=10): 131 | """Calculate the average mutual information between $x(t)$ and $y(t)$. 132 | 133 | Parameters 134 | ---------- 135 | x : array-like 136 | y : array-like, optional 137 | $x(t)$ and $y(t)$. 138 | If only `x` is passed, it must have two columns; 139 | the first column defines $x(t)$ and the second $y(t)$. 140 | n_bins : int 141 | The number of bins to use when computing the joint histogram. 142 | 143 | Returns 144 | ------- 145 | scalar 146 | Average mutual information between $x(t)$ and $y(t)$, in nats (natural log equivalent of bits). 147 | 148 | See Also 149 | -------- 150 | lagged_ami 151 | 152 | References 153 | ---------- 154 | Arbanel, H. D. (1996). *Analysis of Observed Chaotic Data* (p. 28). New York: Springer. 155 | 156 | """ 157 | x, y = _vector_pair(x, y) 158 | if x.shape[0] != y.shape[0]: 159 | raise ValueError('timeseries must have the same length') 160 | 161 | return metrics.mutual_info_score(None, None, contingency=np.histogram2d(x, y, bins=n_bins)[0]) 162 | 163 | 164 | def lagged_ami(x, min_lag=0, max_lag=None, lag_step=1, n_bins=10): 165 | """Calculate the average mutual information between $x(t)$ and $x(t + \tau)$, at multiple values of $\tau$. 166 | 167 | Parameters 168 | ---------- 169 | x : array-like 170 | $x(t)$. 171 | min_lag : int, optional 172 | The shortest lag to evaluate, in units of the sampling period $h$ of $x(t)$. 173 | max_lag : int, optional 174 | The longest lag to evaluate, in units of $h$. 175 | lag_step : int, optional 176 | The step between lags to evaluate, in units of $h$. 177 | n_bins : int 178 | The number of bins to use when computing the joint histogram in order to calculate mutual information. 179 | See |ami|. 180 | 181 | Returns 182 | ------- 183 | lags : ndarray 184 | The evaluated lags $\tau_i$, in units of $h$. 185 | amis : ndarray 186 | The average mutual information between $x(t)$ and $x(t + \tau_i)$. 187 | 188 | See Also 189 | -------- 190 | ami 191 | 192 | """ 193 | if max_lag is None: 194 | max_lag = x.shape[0]//2 195 | lags = np.arange(min_lag, max_lag, lag_step) 196 | 197 | amis = [ami(reconstruct(x, lag, 2), n_bins=n_bins) for lag in lags] 198 | return lags, np.array(amis) 199 | 200 | 201 | def _vector_pair(a, b): 202 | a = np.squeeze(a) 203 | if b is None: 204 | if a.ndim != 2 or a.shape[1] != 2: 205 | raise ValueError('with one input, array must have be 2D with two columns') 206 | a, b = a[:, 0], a[:, 1] 207 | return a, np.squeeze(b) 208 | 209 | 210 | def _vector(x): 211 | x = np.squeeze(x) 212 | if x.ndim != 1: 213 | raise ValueError('x(t) must be a 1-dimensional signal') 214 | return x 215 | -------------------------------------------------------------------------------- /tests/gfnn_test_data.csv: -------------------------------------------------------------------------------- 1 | 383,383,372,378,364,353,339,330,322,302,294,269,244,224,199,171,143,118,90,62,29,0,-25,-55,-83,-120,-145,-181,-212,-240,-262,-293,-307,-332,-343,-357,-371,-379,-396,-396,-387,-396,-390,-393,-379,-368,-362,-348,-337,-326,-307,-295,-279,-259,-237,-212,-186,-161,-133,-117,-92,-69,-44,-19,4,32,60,73,93,126,143,171,202,219,252,277,297,316,333,355,369,392,411,425,431,442,456,461,475,475,492,495,500,495,489,489,473,470,461,447,442,425,414,394,378,358,336,311,294,274,244,219,193,163,129,96,62,37,0,-30,-55,-86,-117,-147,-181,-209,-245,-270,-295,-309,-329,-348,-360,-368,-376,-382,-385,-385,-385,-376,-373,-365,-354,-343,-329,-315,-304,-298,-279,-262,-237,-214,-184,-164,-147,-120,-97,-72,-44,-19,0,32,60,87,115,140,174,205,235,252,277,286,302,322,336,350,369,380,392,406,408,414,420,431,428,422,420,420,414,408,403,389,383,372,361,347,333,319,302,283,255,224,196,174,140,113,79,57,26,1,-25,-53,-80,-100,-125,-150,-175,-200,-209,-226,-245,-262,-281,-293,-301,-312,-318,-326,-337,-343,-346,-346,-348,-354,-343,-343,-326,-320,-315,-295,-287,-273,-273,-256,-234,-214,-186,-167,-145,-125,-103,-83,-41,-13,29,57,87,115,138,166,199,224,241,269,291,308,319,333,347,367,372,383,394,411,411,420,431,436,439,436,431,434,425,420,411,408,397,386,367,350,339,319,302,283,260,241,213,196,160,124,101,68,34,1,-27,-69,-111,-142,-175,-209,-237,-259,-287,-312,-329,-334,-354,-362,-379,-385,-396,-401,-404,-410,-399,-404,-396,-390,-385,-373,-360,-346,-329,-312,-298,-276,-248,-226,-203,-181,-161,-147,-128,-94,-66,-33,0,40,73,87,113,129,146,168,182,202,227,247,252,260,272,286,300,311,325,341,350,355,364,378,380,383,392,400,403,411,411,411,411,408,408,406,397,397,392,383,375,367,353,347,325,302,286,266,249,227,202,174,152,118,96,71,40,15,-11,-41,-66,-103,-136,-161,-186,-217,-242,-270,-293,-318,-334,-357,-368,-382,-393,-404,-407,-415,-418,-418,-415,-415,-410,-401,-390,-382,-362,-346,-332,-315,-290,-265,-245,-217,-192,-164,-142,-108,-72,-41,-13,12,51,79,113,143,174,205,224,244,260,280,300,322,344,358,369,378,389,400,406,420,431,434,442,447,453,453,459,461,461,464,470,470,473,475,467,475,478,470,467,473,467,461,453,445,436,425,411,400,394,378,361,339,319,297,272,249,221,199,174,143,118,93,71,40,9,-13,-36,-58,-86,-108,-133,-159,-175,-195,-214,-237,-253,-276,-281,-298,-304,-318,-329,-337,-346,-348,-348,-346,-343,-346,-343,-337,-332,-315,-309,-290,-279,-259,-234,-214,-195,-175,-161,-136,-103,-83,-50,-22,12,48,79,107,135,157,188,216,230,260,283,308,319,339,358,372,392,403,411,414,422,442,442,453,459,459,456,470,473,475,470,473,473,467,464,459,461,459,447,439,442,431,431,422,414,411,406,392,392,380,369,355,336,325,316,300,283,266,233,205,185,152,126,99,73,51,20,1,-16,-44,-72,-97,-120,-147,-167,-184,-200,-226,-245,-256,-273,-284,-295,-312,-320,-320,-326,-323,-326,-323,-312,-307,-304,-301,-284,-270,-267,-240,-217,-203,-175,-150,-136,-114,-92,-58,-36,-2,20,46,76,107,132,152,185,219,238,263,283,297,305,333,344,361,369,392,394,400,400,411,417,422,420,414,420,420,411,411,406,406,400,397,392,392,378,372,367,355,353,347,336,325,313,308,294,277,258,249,233,216,205,182,166,143,126,110,90,65,48,26,0,-11,-39,-61,-80,-108,-125,-153,-170,-181,-203,-209,-226,-240,-248,-256,-259,-270,-270,-276,-276,-276,-279,-276,-273,-276,-273,-265,-259,-248,-245,-234,-212,-200,-178,-164,-147,-133,-111,-92,-69,-36,-8,18,46,71,96,115,140,168,191,213,224,244,269,280,294,302,319,333,341,364,372,375,383,386,383,383,380,386,383,375,375,361,358,353,344,339,339,336,322,319,313,297,272,260,235,230,207,191,177,157,132,118,96,85,65,46,34,18,4,-13,-27,-41,-55,-72,-92,-103,-122,-139,-156,-175,-184,-198,-203,-214,-223,-226,-234,-237,-251,-245,-256,-256,-251,-259,-251,-242,-242,-237,-237,-231,-234,-226,-223,-214,-209,-198,-189,-181,-164,-150,-128,-111,-86,-69,-47,-27,-5,15,51,62,96,118,138,154,177,202,224,247,263,280,297,305,325,347,364,369,380,392,403,414,422,422,431,431,428,431,431,425,425,420,408,406,392,392,383,375,369,358,353,336,330,316,300,283,266,252,238,219,199,182,160,140,115,99,73,54,37,15,-2,-22,-41,-58,-86,-94,-120,-139,-147,-167,-181,-189,-203,-214,-223,-226,-231,-231,-231,-240,-248,-242,-237,-240,-234,-234,-234,-223,-217,-214,-209,-206,-203,-198,-198,-192,-181,-170,-159,-136,-128,-103,-83,-64,-47,-19,0,34,51,85,115,138,160,174,196,224,252,272,288,316,333,344,361,378,403,414,425,431,439,445,456,459,470,470,475,470,473,467,467,459,453,445,434,422,411,400,394,389,369,358,344,336,319,297,277,263,247,227,205,188,154,143,121,90,68,51,34,12,-2,-19,-39,-61,-72,-89,-97,-111,-128,-142,-156,-161,-178,-181,-189,-198,-200,-209,-212,-209,-212,-214,-217,-217,-214,-214,-209,-212,-206,-206,-200,-192,-195,-184,-175,-175,-167,-156,-133,-125,-106,-83,-69,-47,-22,0,26,46,82,110,129,154,185,210,227,247,269,286,305,319,336,350,358,369,378,389,397,408,420,422,422,431,425,422,417,420,417,411,403,392,380,375,367,355,347,333,319,300,288,280,266,252,230,210,191,168,146,129,101,79,62,40,26,9,-2,-19,-27,-44,-58,-80,-97,-114,-136,-145,-159,-173,-186,-203,-209,-220,-228,-234,-240,-237,-242,-242,-242,-245,-234,-237,-226,-220,-214,-203,-195,-178,-164,-153,-147,-136,-125,-111,-92,-72,-58,-41,-22,-5,18,40,65,87,110,135,163,182,205,230,252,274,294,302,325,336,353,378,392,411,417,434,447,461,467,478,478,484,492,495,498,495,487,487,484,478,475,461,447,442,434,420,408,392,378,361,347,330,311,291,266,249,230,205,177,152,132,107,87,62,32,12,-5,-22,-47,-64,-80,-97,-111,-131,-145,-159,-175,-192,-198,-206,-223,-228,-237,-240,-248,-242,-248,-248,-245,-248,-242,-245,-248,-231,-231,-223,-214,-209,-195,-200,-178,-161,-153,-139,-122,-117,-97,-80,-64,-41,-13,12,34,62,85,110,121,143,168,185,202,227,249,266,269,286,294,319,336,344,358,367,380,389,397,397,406,408,411,408,406,406,406,386,386,375,375,367,358,344,325,311,300,280,258,241,219,207,182,160,149,121,96,71,48,34,1,-8,-22,-36,-58,-78,-97,-114,-128,-142,-159,-167,-192,-198,-206,-217,-220,-228,-231,-237,-245,-251,-251,-248,-251,-240,-231,-226,-223,-209,-200,-198,-181,-167,-150,-131,-114,-103,-83,-69,-39,-25,-8,12,29,46,68,79,107,135,160,177,202,227,247,260,277,294,311,341,369,383,408,420,431,450,467,487,498,509,523,528,542,545,548,554,551,545,545,540,528,520,514,509,500,492,475,461,445,425,411,389,367,344,319,294,274,238,210,188,143,104,76,37,6,-22,-53,-72,-100,-125,-145,-167,-189,-209,-217,-237,-251,-259,-265,-273,-279,-290,-293,-293,-290,-287,-276,-279,-273,-265,-253,-245,-240,-237,-226,-214,-198,-186,-164,-153,-133,-120,-100,-89,-64,-47,-27,-2,20,40,60,79,107,124,143,174,199,233,244,260,277,294,308,333,353,378,392,400,414,436,453,461,475,489,495,503,506,520,517,514,531,526,520,526,523,517,506,500,492,481,475,456,447,428,408,389,361,336,311,280,255,233,210,185,160,124,96,54,20,-11,-41,-58,-86,-108,-133,-147,-170,-189,-209,-223,-237,-251,-265,-270,-281,-281,-293,-290,-290,-287,-284,-281,-279,-270,-267,-262,-256,-251,-248,-242,-228,-214,-200,-186,-170,-156,-142,-122,-106,-100,-75,-69,-53,-30,-19,-8,9,32,62,93,121,154,177,193,219,235,263,288,302,327,347,372,397,406,431,442,461,475,492,506,517,523,537,542,548,554,556,559,562,556,554,537,537,531,517,512,500,489,467,445,425,406,392,372,350,327,308,283,263,244,213,196,168,149,121,93,71,43,26,1,-11,-41,-58,-86,-111,-131,-159,-184,-203,-231,-248,-273,-290,-293,-301,-309,-320,-320,-326,-334,-337,-337,-337,-337,-337,-337,-332,-334,-323,-323,-318,-309,-301,-293,-281,-273,-270,-251,-240,-231,-212,-186,-164,-145,-117,-89,-66,-36,-8,23,51,85,113,138,163,177,193,219,249,269,288,313,339,350,367,380,389,400,403,414,420,425,431,425,431,431,434,428,425,414,408,397,392,386,380,364,347,336,327,313,311,297,288,272,258,244,221,205,188,174,146,135,104,79,48,29,0,-16,-47,-66,-83,-114,-145,-167,-195,-214,-237,-248,-256,-279,-287,-298,-304,-315,-323,-337,-334,-343,-346,-348,-348,-348,-337,-337,-326,-334,-318,-318,-309,-301,-301,-293,-284,-265,-251,-248,-226,-209,-195,-170,-145,-120,-89,-72,-41,-13,9,43,68,96,129,152,166,193,210,224,241,260,277,297,313,336,347,364,375,383,397,400,408,411,411,411,406,394,392,394,380,372,367,350,347,333,322,316,297,286,269,258,241,227,210,188,166,143,113,96,73,51,34,20,4,-13,-33,-50,-69,-100,-117,-142,-159,-181,-203,-220,-237,-253,-265,-279,-290,-295,-301,-315,-323,-323,-329,-329,-332,-329,-332,-323,-320,-320,-309,-307,-298,-290,-279,-267,-253,-245,-231,-212,-189,-167,-145,-117,-89,-58,-30,-5,20,65,99,121,152,177,185,210,230,252,266,291,311,325,350,364,372,389,408,420,422,439,450,447,450,450,447,442,436,436,425,422,406,397,389,375,358,350,330,316,300,272,252,227,213,188,166,143,121,99,71,43,23,-2,-27,-41,-58,-86,-106,-131,-150,-170,-186,-209,-226,-248,-262,-279,-287,-304,-309,-318,-323,-337,-332,-334,-337,-334,-332,-332,-326,-320,-312,-301,-295,-287,-284,-276,-270,-256,-245,-240,-234,-217,-212,-198,-178,-161,-139,-120,-94,-72,-44,-22,6,26,65,96,126,154,177,202,219,247,266,286,311,327,350,364,380,392,411,422,431,442,450,456,464,470,467,470,467,464,464,453,450,445,445,425,420,408,400,389,375,364,350,333,319,297,274,255,224,196,174,154,132,113,87,51,29,6,-11,-33,-53,-78,-100,-122,-142,-164,-186,-206,-223,-240,-253,-270,-284,-293,-301,-304,-304,-301,-304,-298,-290,-290,-287,-273,-270,-256,-245,-242,-237,-223,-217,-206,-198,-181,-170,-164,-145,-136,-120,-94,-72,-44,-22,1,23,43,68,99,126,154,174,193,221,241,252,269,286,297,319,330,341,361,369,380,392,400,411,411,422,425,431,436,431,425,431,425,420,414,400,392,380,367,353,339,322,302,280,258,224,213,191,160,138,110,90,62,40,26,15,0,-11,-36,-50,-69,-83,-108,-122,-139,-156,-170,-181,-195,-206,-220,-234,-237,-245,-248,-256,-259,-265,-265,-267,-267,-259,-253,-259,-251,-245,-240,-231,-226,-217,-203,-192,-186,-181,-173,-164,-159,-150,-133,-120,-97,-78,-58,-33,-8,12,32,57,85,110,138,166,185,199,221,241,252,277,291,302,308,325,333,339,347,361,369,372,369,375,380,378,378,369,369,364,355,350,347,344,333,322,316,297,280,263,255,235,219,202,182,160,138,110,85,62,46,26,0,-19,-36,-58,-78,-100,-111,-131,-139,-150,-170,-186,-200,-206,-223,-226,-237,-248,-248,-251,-256,-259,-256,-256,-256,-262,-259,-256,-256,-259,-251,-242,-242,-234,-234,-220,-209,-195,-192,-186,-178,-167,-153,-139,-128,-114,-97,-78,-69,-44,-25,1,23,46,62,82,107,129,157,182,205,235,263,286,300,316,330,350,372,386,403,411,422,431,439,445,453,456,453,453,447,453,450,450,447,445,434,428,411,397,378,375,355,339,316,300,280,260,233,221,193,174,143,121,99,71,51,32,12,-11,-36,-61,-86,-106,-120,-136,-159,-178,-198,-214,-237,-253,-265,-281,-290,-293,-301,-312,-323,-323,-326,-337,-343,-334,-334,-337,-337,-326,-329,-326,-309,-304,-295,-284,-273,-262,-248,-240,-231,-217,-209,-192,-184,-156,-139,-114,-100,-78,-64,-36,-16,9,51,76,99,132,166,185,193,219,235,252,258,280,300,302,308,325,325,330,333,344,344,344,353,353,350,341,344,344,333,325,316,305,294,277,274,263,247,233,219,193,182,154,124,110,82,57,34,18,-5,-22,-39,-61,-86,-100,-122,-136,-153,-175,-192,-217,-231,-251,-270,-281,-295,-304,-315,-329,-329,-343,-348,-351,-357,-360,-362,-365,-362,-368,-362,-360,-354,-346,-340,-329,-329,-326,-315,-307,-301,-293,-276,-259,-237,-223,-209,-186,-164,-147,-128,-103,-75,-55,-27,-2,26,60,87,118,140,157,177,193,210,221,244,260,272,288,300,319,327,333,347,353,355,355,353,364,353,344,336,327,316,305,297,294,274,255,249,227,213,193,171,152,129,113,96,71,51,29,6,-13,-36,-66,-94,-114,-122,-145,-170,-192,-214,-231,-251,-270,-276,-290,-301,-309,-320,-320,-337,-337,-348,-354,-362,-365,-365,-371,-373,-368,-373,-373,-368,-360,-348,-346,-337,-326,-320,-315,-304,-281,-265,-248,-231,-217,-195,-175,-153,-131,-111,-80,-55,-25,0,29,68,99,138,163,205,224,247,263,280,308,325,339,347,367,375,386,400,406,411,420,422,414,420,420,417,417,408,400,400,386,380,361,353,344,333,313,302,280,266,238,227,199,180,138,121,93,68,43,18,1,-16,-41,-66,-86,-111,-133,-161,-186,-209,-240,-251,-270,-293,-304,-318,-329,-343,-348,-360,-368,-376,-379,-379,-387,-390,-399,-399,-393,-387,-376,-368,-365,-354,-346,-326,-318,-304,-287,-270,-251,-237,-214,-200,-181,-159,-133,-103,-69,-41,-13,23,48,82,126,157,188,213,247,263,283,294,322,330,344,361,372,386,392,403,411,411,425,425,431,436,442,434,422,428,417,408,394,383,369,353,330,313,288,269,249,219,193,166,126,107,82,54,40,20,-5,-30,-58,-83,-111,-136,-164,-189,-214,-240,-259,-270,-284,-298,-312,-320,-326,-343,-357,-354,-357,-360,-360,-360,-354,-351,-343,-348,-343,-334,-329,-323,-309,-293,-284,-273,-253,-240,-223,-206,-192,-181,-164,-145,-128,-106,-86,-61,-44,-30,0,23,51,73,96,124,143,163,182,196,219,241,263,274,300,316,333,344,358,372,389,403,411,420,431,431,431,436,442,439,442,439,425,425,428,420,408,403,386,375,355,347,336,308,297,280,263,241,227,205,174,143,118,82,60,29,6,-16,-41,-61,-80,-106,-133,-153,-167,-189,-206,-223,-240,-251,-259,-273,-276,-284,-284,-293,-301,-304,-298,-309,-309,-320,-309,-309,-301,-293,-290,-281,-273,-256,-242,-226,-212,-192,-178,-164,-147,-131,-117,-108,-83,-55,-33,-8,9,29,48,73,113,143,168,188,221,247,269,288,300,325,339,353,369,378,380,389,406,414,420,422,434,439,442,436,431,428,425,425,425,420,411,403,394,389,361,353,330,316,297,274,263,241,221,193,174,149,124,101,71,51,32,6,-8,-33,-47,-75,-92,-103,-125,-139,-164,-181,-198,-220,-228,-245,-259,-265,-273,-279,-290,-298,-301,-301,-307,-307,-304,-304,-295,-293,-287,-284,-270,-256,-245,-234,-220,-212,-203,-189,-178,-156,-142,-122,-97,-75,-55,-27,-8,12,40,68,99,121,140,168,182,202,227,252,266,288,302,316,330,336,344,358,369,369,380,386,392,392,394,394,397,389,383,380,369,367,364,355,341,322,313,300,291,272,249,235,224,207,182,154,124,99,71,46,23,4,-11,-27,-41,-64,-83,-108,-125,-139,-159,-175,-189,-206,-220,-226,-240,-251,-262,-267,-276,-284,-293,-293,-304,-304,-307,-309,-304,-298,-298,-298,-293,-284,-281,-267,-259,-256,-245,-234,-226,-223,-209,-198,-181,-161,-150,-136,-120,-103,-80,-58,-30,1,26,46,68,90,124,154,180,205,230,255,272,294,311,330,350,367,383,392,406,414,420,422,425,425,428,431,431,428,422,417,411,406,400,394,386,378,361,353,330,319,300,277,255,235,216,193,174,149,129,104,73,60,37,29,6,-8,-30,-47,-69,-83,-106,-122,-145,-159,-173,-195,-214,-240,-256,-270,-281,-295,-309,-307,-320,-323,-329,-337,-343,-343,-348,-354,-346,-346,-337,-337,-326,-323,-320,-312,-304,-295,-290,-279,-267,-251,-231,-214,-192,-178,-161,-131,-117,-94,-64,-36,-11,15,40,68,90,124,152,182,210,235,258,277,283,297,305,325,333,341,353,350,358,369,369,375,367,378,378,375,375,372,364,355,361,347,333,325,316,308,294,286,277,266,244,224,210,193,166,146,126,113,93,68,57,34,20,1,-11,-27,-47,-72,-92,-114,-131,-145,-156,-173,-186,-209,-223,-234,-245,-259,-267,-279,-284,-287,-293,-295,-293,-290,-287,-287,-276,-270,-265,-251,-242,-234,-223,-214,-203,-186,-175,-153,-128,-111,-86,-55,-33,-11,20,46,71,93,124,157,188,213,235,260,286,297,316,325,339,347,355,358,372,383,383,383,403,411,406,420,422,425,422,431,431,428,431,428,417,408,397,383,372,353,341,322,308,286,260,238,202,182,154,124,96,79,57,32,15,4,-16,-39,-58,-72,-89,-103,-117,-142,-159,-173,-189,-203,-212,-237,-240,-259,-267,-273,-287,-293,-298,-298,-307,-304,-309,-304,-301,-301,-293,-284,-281,-273,-267,-267,-251,-237,-231,-217,-209,-198,-181,-170,-156,-142,-120,-100,-80,-53,-25,1,23,43,68,87,113,138,166,202,219,244,255,283,297,311,333,344,350,369,372,383,389,397,394,400,394,397,397,392,394,389,378,372,358,350,330,316,291,277,252,238,213,191,160,138,113,85,62,40,26,1,-13,-36,-44,-64,-80,-103,-128,-136,-150,-173,-175,-189,-203,-220,-220,-231,-242,-248,-256,-259,-256,-259,-259,-262,-253,-253,-248,-242,-245,-234,-231,-212,-209,-192,-184,-164,-156,-139,-128,-120,-108,-97,-86,-66,-44,-25,-11,1,23,40,57,68,85,104,129,146,171,188,207,216,230,249,269,283,300,308,313,327,330,347,350,361,355,367,361,361,350,355,350,344,339,330,319,311,294,280,272,258,241,224,210,188,163,143,118,96,76,60,29,12,-16,-27,-50,-75,-89,-108,-120,-131,-145,-159,-175,-198,-212,-220,-234,-245,-251,-267,-267,-279,-290,-287,-290,-293,-290,-293,-290,-287,-287,-276,-281,-273,-270,-262,-248,-240,-226,-212,-192,-184,-164,-145,-133,-111,-86,-66,-44,-19,1,26,43,73,85,107,121,143,168,188,205,224,244,258,272,286,311,327,336,347,350,364,364,372,383,380,386,383,386,375,378,372,367,364,361,355,344,344,330,319,313,297,283,263,249,227,207,191,168,152,129,101,82,62,34,18,0,-30,-50,-69,-94,-111,-139,-159,-170,-195,-209,-226,-245,-245,-265,-265,-276,-281,-284,-293,-298,-304,-312,-315,-318,-320,-320,-320,-307,-312,-301,-295,-293,-284,-276,-270,-259,-251,-248,-237,-223,-212,-198,-184,-173,-150,-125,-111,-86,-61,-44,-8,15,46,73,104,121,143,168,180,199,221,238,255,274,294,308,327,341,353,364,367,378,386,392,397,400,397,397,397,400,394,380,375,372,358,344,333,327,319,308,294,288,277,266,249,244,233,219,207,191,182,168,154,140,124,101,93,73,54,40,26,1,-25,-47,-66,-97,-128,-145,-170,-192,-206,-223,-240,-248,-265,-267,-284,-293,-304,-309,-318,-320,-323,-329,-329,-329,-332,-337,-332,-320,-318,-320,-315,-307,-293,-290,-276,-265,-240,-226,-206,-198,-170,-159,-136,-111,-78,-44,-16,6,34,54,85,110,132,163,188,210,227,238,258,274,288,297,302,316,322,327,330,339,347,355,353,355,350,350,339,333,330,327,325,313,305,297,286,280,266,258,255,241,233,216,205,191,177,166,157,143,124,113,96,85,71,57,40,23,9,-8,-36,-53,-75,-92,-111,-128,-147,-170,-186,-200,-214,-231,-242,-259,-270,-284,-287,-295,-293,-301,-301,-298,-298,-298,-298,-295,-301,-293,-293,-279,-270,-265,-251,-237,-220,-209,-192,-175,-156,-125,-103,-75,-50,-25,4,32,68,107,138,166,199,216,233,258,272,300,313,325,336,353,364,378,380,397,403,408,414,420,420,428,428,428,422,422,420,417,411,408,400,397,389,389,375,367,353,339,330,313,302,291,277,263,252,241,233,216,196,180,157,135,115,85,65,40,20,1,-25,-44,-75,-103,-131,-161,-200,-220,-226,-242,-256,-270,-281,-293,-304,-301,-315,-312,-320,-320,-318,-323,-326,-318,-320,-318,-315,-309,-304,-290,-284,-276,-256,-240,-226,-200,-184,-159,-142,-111,-83,-55,-22,0,43,68,110,140,160,191,213,238,263,297,319,339,353,367,380,394,406,414,428,431,434,442,439,436,442,431,428,425,420,417,411,408,400,397,386,372,372,358,350,341,330,311,302,288,277,269,255,238,221,205,193,171,163,140,118,96,65,57,29,15,-5,-25,-44,-66,-92,-114,-133,-150,-170,-184,-198,-212,-217,-234,-240,-248,-251,-265,-265,-259,-259,-253,-251,-251,-251,-248,-242,-240,-231,-217,-212,-198,-186,-173,-153,-128,-103,-75,-53,-33,-19,4,29,68,96,135,160,188,213,238,269,294,322,336,355,378,397,408,420,431,445,453,459,459,464,461,461,467,461,461,456,456,445,434,428,420,408,392,386,378,361,344,322,311,297,288,269,258,252,241,227,216,191,166,146,129,104,85,57,40,9,-11,-36,-55,-72,-92,-117,-136,-145,-159,-175,-189,-209,-220,-223,-240,-245,-253,-265,-267,-265,-259,-262,-259,-253,-245,-242,-240,-237,-228,-220,-212,-203,-192,-173,-150,-136,-108,-94,-69,-47,-30,0,23,57,85,121,157,182,202,224,241,258,283,313,330,341,353,372,383,397,403,422,425,425,428,436,442,442,442,436,428,417,408,394,392,378,364,369,358,339,330,322,308,291,283,269,258,249,233,221,202,193,171,152,138,124,104,76,62,40,23,-2,-16,-39,-61,-78,-97,-120,-145,-164,-184,-212,-226,-240,-256,-273,-287,-287,-295,-304,-307,-315,-318,-315,-320,-320,-320,-318,-315,-320,-320,-307,-301,-293,-287,-276,-267,-253,-240,-223,-206,-195,-170,-147,-133,-106,-83,-58,-22,12,51,85,110,138,168,185,213,235,258,283,297,313,327,330,353,361,378,389,394,406,400,408,406,397,397,392,386,383,375,378,364,361,361,350,344,336,330,322,319,311,313,294,286,277,258,247,238,219,199,185,166,149,129,104,71,51,29,6,-19,-53,-75,-97,-122,-139,-167,-189,-209,-234,-256,-273,-290,-309,-323,-329,-343,-357,-360,-368,-379,-379,-385,-387,-385,-390,-385,-382,-379,-371,-376,-365,-362,-354,-340,-323,-315,-295,-276,-256,-240,-214,-184,-164,-147,-122,-97,-64,-36,-2,37,71,96,124,143,174,196,221,241,255,269,277,294,300,305,313,322,322,325,325,330,333,322,327,333,336,333,330,330,327,327,327,333,319,336,339,336,327,330,322,313,319,311,305,297,283,266,252,227,216,193,177,157,124,104,71,46,18,-2,-27,-47,-75,-94,-122,-142,-164,-181,-203,-214,-242,-253,-270,-281,-304,-312,-329,-340,-346,-357,-360,-371,-368,-368,-362,-368,-368,-362,-346,-348,-334,-326,-315,-298,-284,-267,-248,-226,-212,-189,-175,-150,-128,-97,-69,-41,-11,15,46,62,87,115,135,160,177,199,207,224,238,249,263,274,286,294,300,305,313,322,333,339,344,350,350,358,355,353,364,372,375,378,386,392,394,394,400,406,406,403,406,400,392,386,375,367,353,347,333,319,294,280,252,241,207,191,166,135,107,65,32,12,-16,-36,-64,-97,-128,-164,-192,-220,-248,-279,-307,-318,-337,-354,-368,-387,-390,-399,-410,-410,-415,-413,-418,-413,-404,-396,-387,-371,-371,-354,-340,-329,-312,-298,-276,-259,-242,-231,-206,-184,-161,-139,-111,-78,-50,-27,-2,18,46,82,110,143,166,193,205,224,235,255,266,280,291,297,311,322,333,333,353,355,367,372,383,392,397,408,417,425,428,434,436,442,439,445,450,447,450,445,445,434,434,417,406,397,383,369,364,341,316,291,258,233,210,174,146,110,79,43,15,-19,-55,-83,-111,-142,-181,-212,-237,-267,-290,-309,-332,-354,-371,-376,-390,-399,-410,-407,-413,-413,-418,-410,-407,-404,-393,-376,-360,-357,-343,-332,-307,-293,-270,-253,-234,-212,-189,-173,-145,-120,-94,-78,-61,-33,0,32,62,82,104,124,140,154,163,182,193,207,219,221,233,247,252,266,269,274,280,297,302,313,319,333,350,358,367,372,375,383,397,397,403,408,411,411,417,420,414,417,420,417,403,397,378,364,344,327,313,283,255,230,207,180,149,104,68,34,-5,-39,-80,-122,-159,-192,-231,-259,-293,-315,-326,-348,-362,-382,-393,-410,-415,-424,-432,-435,-440,-443,-440,-440,-435,-427,-421,-407,-399,-390,-379,-371,-348,-337,-326,-312,-290,-276,-256,-248,-226,-206,-192,-175,-150,-125,-100,-72,-41,-19,0,26,40,51,65,82,104,121,140,154,154,168,182,191,210,224,252,269,288,302,319,327,344,358,372,383,394,397,408,417,417,425,431,431,425,428,420,420,420,406,397,380,372,355,341,319,291,272,249,224,193,166,138,113,76,48,12,-16,-50,-78,-114,-147,-175,-206,-237,-265,-284,-304,-326,-343,-362,-368,-382,-393,-399,-404,-407,-410,-407,-404,-401,-399,-393,-376,-368,-354,-337,-326,-309,-298,-281,-265,-242,-223,-209,-203,-181,-170,-150,-120,-92,-64,-41,-16,12,32,51,79,99,110,129,143,160,177,185,205,202,213,224,238,249,266,272,277,291,302,316,325,339,350,358,369,375,383,392,397,403,406,406,408,406,406,403,397,394,386,383,367,353,333,313,283,258,224,207,182,146,115,76,51,23,-2,-39,-66,-100,-133,-156,-192,-217,-237,-259,-284,-301,-315,-337,-354,-357,-360,-371,-379,-376,-376,-379,-376,-368,-365,-348,-346,-340,-326,-315,-301,-281,-267,-248,-220,-203,-175,-153,-136,-114,-86,-75,-41,-8,9,43,62,93,110,126,143,163,168,182,193,205,216,230,238,252,266,266,277,288,297,302,313,322,327,336,350,358,375,380,389,397,406,411,422,422,428,431,436,434,428,425,414,406,389,378,372,350,333,313,288,266,235,210,188,157,138,107,73,40,4,-25,-66,-97,-131,-164,-195,-228,-251,-279,-290,-309,-320,-337,-348,-360,-371,-376,-379,-382,-382,-382,-379,-379,-373,-365,-357,-343,-346,-329,-315,-295,-281,-265,-251,-234,-214,-189,-175,-159,-145,-122,-106,-80,-58,-39,-13,4,34,54,76,93,104,124,143,168,185,205,219,227,233,244,255,260,277,288,305,311,327,347,364,369,380,386,389,400,420,420,425,422,420,414,417,422,422,420,411,408,397,375,361,336,330,311,286,263,233,210,171,149,129,99,65,40,12,-13,-41,-75,-103,-139,-181,-212,-234,-256,-276,-290,-307,-312,-329,-334,-346,-351,-354,-360,-365,-365,-357,-351,-351,-348,-337,-334,-326,-315,-312,-290,-276,-270,-262,-245,-231,-212,-203,-186,-164,-145,-125,-106,-86,-75,-44,-25,-5,20,51,76,93,118,140,160,168,182,205,207,230,247,252,269,283,294,308,325,333,347,355,364,380,386,397,408,417,422,431,436,434,439,436,442,445,442,442,442,436,428,414,400,392,375,361,344,322,302,277,255,233,207,188,168,129,93,65,32,1,-27,-58,-86,-114,-139,-175,-212,-237,-270,-284,-309,-329,-343,-354,-362,-371,-379,-385,-385,-387,-382,-382,-379,-371,-360,-354,-337,-323,-309,-290,-270,-253,-231,-214,-195,-173,-150,-128,-100,-75,-58,-33,-13,4,32,51,68,85,96,107,115,126,138,157,171,188,199,210,224,241,247,260,266,280,291,305,311,316,327,330,339,347,353,358,353,367,369,369,372,372,380,378,378,375,369,364,358,353,347,341,325,316,288,272,249,227,199,177,143,115,85,60,26,0,-30,-64,-94,-136,-161,-203,-223,-262,-281,-304,-320,-337,-354,-368,-385,-387,-396,-399,-410,-399,-401,-396,-387,-382,-373,-360,-354,-332,-320,-295,-284,-267,-251,-226,-203,-184,-164,-139,-117,-89,-64,-36,-11,23,51,76,96,121,149,163,180,191,210,224,233,241,255,266,272,286,283,291,297,305,313,325,330,339,353,350,364,375,380,392,389,392,397,400,403,403,400,403,403,392,392,375,378,367,353,336,322,302,288,272,247,221,193,166,143,118,79,57,26,1,-27,-66,-94,-131,-161,-198,-234,-253,-284,-304,-326,-354,-362,-376,-387,-396,-404,-407,-401,-404,-404,-407,-396,-404,-390,-382,-368,-354,-343,-326,-309,-290,-273,-251,-234,-203,-181,-164,-136,-108,-78,-58,-33,-2,15,29,51,68,93,107,135,154,168,180,199,207,224,230,230,249,255,263,272,286,286,294,300,308,311,319,322,339,347,347,355,361,369,380,383,392,392,403,406,408,408,406,403,397,383,380,364,341,325,305,288,266,233,207,185,157,129,115,96,68,54,37,20,1,-25,-39,-66,-106,-131,-156,-186,-223,-234,-251,-270,-290,-298,-307,-315,-320,-318,-326,-323,-312,-315,-309,-295,-287,-276,-256,-240,-217,-203,-184,-161,-136,-114,-89,-58,-30,-8,18,46,73,104,129,138,163,185,207,224,244,260,272,274,274,280,291,291,294,300,305,313,313,316,313,322,322,322,325,322,330,336,341,347,350,353,361,364,367,369,372,369,372,378,372,367,364,358,355,341,330,327,313,297,277,249,219,182,152,115,79,57,29,9,-13,-47,-69,-94,-125,-156,-186,-214,-240,-253,-270,-284,-304,-309,-318,-323,-332,-343,-348,-354,-354,-348,-351,-343,-337,-326,-320,-309,-304,-290,-276,-262,-248,-226,-203,-184,-167,-142,-120,-97,-72,-39,-13,15,37,71,99,118,140,163,177,196,216,224,238,255,272,280,283,286,288,294,291,302,308,322,333,341,347,358,361,369,372,380,389,392,394,408,406,406,414,417,414,420,411,408,403,394,386,378,380,375,367,347,330,308,291,274,247,230,205,177,154,113,87,48,26,-2,-36,-66,-103,-131,-167,-192,-226,-245,-265,-284,-301,-315,-329,-340,-354,-362,-365,-371,-373,-376,-379,-376,-368,-362,-348,-343,-332,-326,-304,-287,-276,-256,-237,-212,-189,-167,-142,-120,-94,-69,-53,-25,-2,23,46,71,99,113,126,157,182,199,224,249,258,272,274,291,305,313,330,333,344,341,350,347,353,367,367,367,378,383,389,386,400,403,414,411,417,420,428,425,428,428,431,428,422,417,411,403,392,372,353,330,313,300,277,258,238,219,182,152,126,99,73,54,26,-5,-25,-69,-97,-131,-159,-195,-226,-253,-276,-295,-318,-329,-343,-360,-362,-371,-382,-390,-387,-393,-401,-396,-393,-387,-376,-376,-362,-343,-337,-323,-309,-295,-279,-267,-248,-226,-206,-186,-167,-142,-117,-94,-61,-47,-25,1,26,57,85,107,132,154,174,191,210,230,241,260,277,283,294,297,313,322,330,344,347,355,367,375,378,392,403,411,420,425,434,445,442,445,453,456,450,453,447,450,450,436,436,431,425,408,386,367,341,325,305,286,260,244,224,193,168,149,118,96,60,29,6,-25,-58,-80,-114,-142,-173,-198,-220,-248,-276,-290,-309,-320,-329,-332,-337,-346,-343,-348,-348,-343,-337,-332,-320,-315,-301,-284,-270,-253,-237,-214,-198,-181,-164,-136,-111,-72,-47,-22,4,26,54,82,113,135,160,188,205,233,249,266,283,294,302,313,327,339,347,361,358,369,372,380,389,394,397,403,417,428,436,442,450,459,461,470,473,478,481,481,481,481,489,481,484,481,473,470,467,459,442,428,406,392,372,358,327,302,274,252,216,191,160,118,82,48,18,-13,-53,-94,-128,-167,-192,-223,-248,-270,-293,-309,-318,-332,-348,-360,-368,-373,-379,-379,-379,-382,-365,-365,-357,-346,-334,-312,-304,-281,-270,-248,-220,-203,-186,-147,-117,-86,-53,-19,15,54,85,118,143,168,193,210,221,249,280,302,325,339,347,353,369,380,392,406,414,422,431,434,436,447,445,453,461,464,475,475,481,478,481,492,492,487,495,495,495,495,487,489,478,481,473,461,461,450,442,425,414,400,383,369,350,325,288,263,241,213,202,168,143,118,90,51,18,-8,-39,-75,-108,-136,-167,-192,-214,-242,-248,-267,-284,-290,-301,-315,-315,-320,-326,-326,-312,-309,-307,-290,-273,-265,-242,-228,-212,-195,-175,-147,-122,-97,-64,-39,-5,23,57,90,118,143,180,210,241,260,288,305,322,339,347,358,361,369,378,386,397,397,406,400,411,414,422,425,420,422,422,428,425,431,434,434,445,442,439,453,445,450,453,453,459,459,445,445,442,431,428,417,408,394,386,375,358,344,330,313,286,277,258,230,207,171,149,110,87,62,26,6,-19,-53,-69,-97,-120,-145,-175,-192,-209,-226,-242,-253,-267,-281,-293,-287,-293,-295,-295,-293,-287,-287,-281,-273,-267,-253,-240,-231,-214,-203,-181,-161,-128,-103,-69,-41,-8,18,51,85,115,154,180,196,205,221,241,266,283,316,330,355,369,378,383,389,389,394,400,403,408,411,408,408,414,411,414,420,420,422,422,428,428,431,436,442,450,447,453,453,447,450,445,439,425,420,411,400,389,378,364,350,333,316,302,283,263,238,213,196,174,138,110,76,51,12,-2,-36,-64,-92,-122,-153,-186,-212,-234,-245,-267,-276,-290,-295,-307,-323,-320,-326,-326,-320,-320,-315,-309,-301,-293,-279,-270,-253,-245,-217,-198,-181,-156,-133,-108,-92,-64,-39,-13,26,54,87,126,154,177,199,227,252,277,305,330,350,364,375,380,394,389,400,403,400,414,411,411,420,422,422,425,434,434,445,445,456,464,470,481,478,484,481,487,487,487,478,478,478,464,464,450,442,428,425,408,394,383,358,339,308,283,258,235,207,182,152,121,85,57,23,-8,-41,-69,-97,-142,-161,-192,-217,-237,-251,-276,-284,-298,-307,-320,-320,-329,-337,-329,-329,-329,-320,-315,-312,-298,-287,-276,-259,-242,-237,-220,-198,-173,-150,-125,-94,-66,-30,-8,12,51,79,99,124,157,185,219,247,283,300,327,341,344,355,367,369,375,386,392,392,397,400,406,411,414,414,422,425,425,428,436,436,447,447,436,450,447,442,442,442,431,428,414,400,386,380,358,341,319,291,280,263,247,233,210,182,160,132,101,76,51,29,0,-30,-47,-75,-108,-128,-156,-181,-203,-217,-237,-251,-279,-284,-304,-315,-326,-329,-337,-343,-346,-337,-337,-334,-334,-320,-318,-304,-304,-284,-273,-253,-248,-231,-217,-198,-173,-145,-120,-94,-72,-47,-30,-2,23,46,62,93,121,146,160,174,191,207,221,244,260,274,291,302,311,316,327,333,341,344,353,353,364,372,372,378,383,392,397,397,397,406,411,406,406,403,403,406,400,394,392,378,364,350,330,313,305,291,269,241,219,188,154,126,101,76,48,23,-5,-27,-55,-80,-111,-139,-167,-192,-223,-240,-265,-279,-290,-298,-318,-329,-334,-337,-348,-343,-343,-343,-334,-329,-320,-309,-298,-284,-276,-259,-248,-226,-209,-186,-175,-145,-122,-97,-69,-44,-11,18,54,79,101,129,154,188,210,233,249,266,288,297,313,319,327,339,347,350,358,367,378,389,392,394,400,403,408,420,425,434,436,436,453,456,467,478,487,492,498,503,506,506,509,509,506,500,492,475,459,434,420,392,372,350,336,322,300,274,249,216,188,157,132,104,93,62,37,6,-19,-50,-83,-114,-136,-164,-195,-214,-240,-253,-273,-293,-304,-301,-315,-320,-326,-334,-334,-332,-332,-326,-320,-320,-315,-298,-304,-290,-281,-265,-253,-237,-214,-198,-178,-159,-145,-120,-100,-80,-58,-39,-8,26,54,90,124,157,180,196,210,233,247,255,274,286,300,313,316,327,333,341,355,361,364,367,378,389,392,403,420,431,436,456,461,464,467,473,473,470,473,475,475,467,461,453,447,436,411,403,394,378,350,336,316,291,280,263,238,219,196,177,149,118,90,54,15,-19,-44,-78,-103,-128,-150,-178,-203,-231,-253,-276,-298,-307,-318,-332,-337,-343,-354,-354,-357,-351,-348,-337,-337,-334,-320,-312,-312,-301,-284,-276,-259,-245,-228,-209,-198,-175,-156,-142,-106,-86,-53,-33,-8,20,43,73,93,110,129,149,160,174,196,199,221,238,252,263,280,294,305,316,327,339,358,367,369,383,397,406,408,420,428,434,447,456,464,467,473,478,478,478,478,489,478,473,475,473,459,450,436,425,406,397,372,361,347,325,311,291,277,252,227,207,185,157,126,96,62,32,1,-19,-53,-83,-111,-139,-170,-200,-226,-242,-262,-267,-287,-293,-301,-304,-318,-315,-312,-307,-307,-301,-298,-298,-290,-287,-281,-267,-248,-231,-212,-198,-181,-167,-147,-125,-106,-75,-50,-25,1,23,48,73,96,121,152,174,193,207,233,252,272,286,300,311,325,339,353,367,372,375,386,392,403,417,422,431,442,445,456,461,467,461,470,473,473,473,470,475,475,470,467,461,456,453,442,434,417,408,394,386,367,350,327,311,291,272,247,227,196,163,121,85,46,12,-22,-53,-86,-122,-153,-170,-195,-223,-240,-259,-270,-293,-304,-315,-318,-323,-334,-332,-337,-334,-323,-315,-309,-304,-298,-281,-276,-259,-242,-228,-214,-195,-173,-150,-128,-111,-89,-61,-47,-25,-5,18,43,71,101,124,149,168,188,207,216,233,238,260,269,288,302,316,327,333,344,361,372,380,383,400,403,408,417,422,428,436,447,450,453,456,456,456,456,456,459,453,450,439,436,431,422,411,400,392,364,361,344,316,300,272,252,230,219,196,168,149,113,87,60,26,4,-19,-47,-72,-100,-133,-147,-170,-189,-206,-226,-234,-251,-256,-262,-270,-267,-267,-265,-259,-262,-259,-253,-248,-242,-228,-226,-214,-203,-192,-181,-164,-147,-136,-122,-92,-69,-55,-25,-2,20,46,79,110,146,160,171,196,207,227,244,249,263,277,280,297,297,311,322,327,341,339,347,353,353,372,375,380,397,400,408,417,417,414,417,420,422,422,425,417,420,417,406,406,397,389,380,364,353,341,325,311,286,260,238,213,196,166,143,121,90,62,29,9,-22,-47,-75,-97,-122,-139,-164,-181,-206,-220,-242,-253,-270,-276,-293,-298,-290,-295,-304,-298,-295,-287,-279,-281,-265,-259,-251,-240,-231,-214,-200,-181,-159,-147,-120,-103,-75,-58,-33,-8,15,40,71,99,124,143,163,191,199,233,247,269,283,291,300,322,330,347,344,361,364,369,375,386,392,397,397,411,411,417,425,425,431,434,431,436,428,442,439,450,439,434,422,428,420,411,403,389,380,364,355,341,330,308,288,280,266,258,235,227,205,185,166,140,115,93,68,40,4,-16,-47,-69,-97,-114,-139,-159,-181,-195,-212,-223,-245,-253,-270,-276,-284,-290,-298,-290,-287,-281,-281,-279,-270,-270,-265,-248,-245,-228,-226,-209,-186,-175,-156,-136,-114,-103,-78,-53,-27,-11,9,20,43,57,76,99,118,143,168,188,196,219,221,238,249,255,269,277,286,297,305,313,316,327,333,344,364,361,375,375,380,392,392,400,403,408,408,406,414,411,397,403,403,397,400,389,383,372,358,353,344,330,313,297,274,255,235,213,182,154,129,104,71,57,23,-2,-25,-64,-86,-117,-147,-167,-195,-217,-234,-251,-270,-281,-298,-309,-312,-320,-323,-323,-320,-323,-315,-315,-301,-293,-279,-270,-259,-245,-226,-214,-186,-181,-147,-128,-100,-72,-50,-25,-8,15,29,57,82,99,124,146,171,193,207,224,235,252,269,274,297,302,316,322,336,350,364,369,383,394,400,406,411,414,428,428,434,445,447,450,453,459,461,459,461,461,461,459,459,450,442,425,417,414,406,394,380,364,341,322,291,263,238,213,182,160,135,99,76,46,15,-13,-39,-69,-94,-120,-142,-159,-178,-189,-203,-217,-228,-237,-248,-251,-259,-265,-256,-251,-251,-237,-237,-228,-220,-200,-186,-164,-153,-133,-117,-94,-66,-44,-13,1,34,51,82,107,126,149,160,182,202,224,247,263,286,294,302,313,322,330,339,339,347,347,353,350,353,355,364,355,367,364,364,364,361,358,367,372,378,386,386,392,400,403,394,403,403,397,392,394,386,380,372,369,358,339,336,322,291,280,255,235,207,188,168,138,113,85,62,40,9,-19,-41,-61,-89,-120,-136,-170,-189,-209,-226,-240,-251,-270,-287,-281,-287,-295,-293,-287,-293,-287,-279,-265,-256,-251,-237,-220,-217,-200,-181,-170,-156,-139,-120,-106,-69,-44,-19,1,18,46,79,107,132,157,182,205,224,252,272,291,308,319,333,344,350,355,361,358,364,375,383,389,400,406,408,406,411,411,406,414,414,420,422,422,425,428,434,434,436,431,425,422,417,408,400,394,375,367,355,336,308,283,260,238,219,177,152,118,79,51,15,-8,-36,-58,-86,-111,-133,-161,-192,-212,-245,-259,-279,-293,-304,-315,-320,-334,-337,-337,-340,-343,-340,-334,-332,-323,-315,-307,-295,-284,-276,-253,-248,-231,-214,-198,-186,-156,-136,-120,-92,-64,-36,-13,15,37,57,85,96,118,138,157,174,202,227,255,269,283,297,313,319,325,339,344,353,364,372,378,386,389,394,394,397,397,403,406,408,408,411,420,422,420,431,436,436,439,439,436,439,436,431,425,422,422,420,414,400,386,367,344,330,308,286,263,244,224,191,154,129,90,65,37,9,-11,-44,-69,-103,-133,-150,-167,-186,-203,-220,-237,-251,-265,-279,-281,-290,-298,-295,-298,-301,-298,-290,-284,-279,-267,-259,-251,-234,-226,-214,-198,-184,-167,-159,-131,-120,-103,-78,-58,-36,-8,12,32,51,79,104,121,152,166,182,193,210,224,241,252,258,274,288,297,305,311,319,325,330,336,341,350,355,367,375,383,389,400,408,417,420,422,428,428,431,434,431,422,428,420,417,408,400,397,383,372,353,341,322,300,280,263,241,219,191,168,143,110,82,54,26,-2,-27,-58,-80,-114,-136,-159,-184,-200,-220,-234,-256,-273,-281,-298,-301,-309,-315,-304,-307,-304,-301,-293,-287,-281,-270,-262,-245,-226,-217,-200,-181,-153,-136,-120,-92,-69,-44,-13,9,34,62,85,104,121,135,160,185,207,227,244,255,266,286,291,300,302,313,327,330,341,336,341,353,361,355,369,367,369,378,375,383,383,392,392,394,400,392,397,400,400,397,400,394,400,392,383,375,367,361,350,330,313,291,272,255,230,202,185,157,129,107,85,60,34,9,-13,-47,-64,-94,-120,-156,-181,-198,-217,-234,-253,-262,-270,-281,-298,-301,-312,-320,-320,-320,-320,-315,-315,-307,-298,-298,-290,-276,-267,-253,-231,-220,-195,-173,-159,-128,-100,-75,-53,-27,-2,20,40,76,104,129,143,177,199,219,241,263,280,294,313,325,327,341,347,350,358,369,375,380,383,389,389,392,397,408,400,417,411,422,425,425,428,428,428,431,436,431,425,420,420,408,400,397,389,378,364,353,344,330,311,288,269,249,221,188,154,126,90,60,37,12,-11,-36,-61,-89,-114,-136,-159,-181,-206,-231,-240,-262,-273,-284,-293,-298,-298,-309,-318,-312,-315,-315,-309,-301,-298,-284,-279,-273,-256,-245,-234,-217,-198,-184,-161,-131,-114,-86,-53,-33,-2,23,46,73,113,129,152,168,185,210,238,255,266,286,294,308,311,316,327,339,339,353,358,361,375,375,383,386,389,392,394,394,403,400,406,408,400,406,408,406,406,414,406,408,406,392,383,367,355,344,336,322,308,294,277,263,252,233,213,188,166,143,115,90,68,32,9,-11,-47,-61,-92,-108,-142,-170,-189,-212,-228,-251,-262,-279,-290,-298,-309,-318,-323,-323,-329,-323,-326,-329,-320,-315,-304,-293,-293,-279,-276,-253,-237,-223,-203,-192,-164,-142,-122,-97,-75,-44,-13,6,37,65,87,115,135,152,185,205,219,241,258,266,283,291,300,319,322,333,333,339,344,355,364,367,367,380,378,375,369,378,372,375,380,378,383,383,383,380,383,383,375,375,375,369,358,353,344,339,322,308,291,277,260,244,207,188,157,110,85,51,23,1,-25,-50,-75,-103,-122,-145,-173,-200,-220,-245,-265,-279,-287,-307,-309,-323,-326,-329,-334,-337,-343,-337,-337,-326,-326,-318,-312,-301,-293,-276,-259,-251,-226,-209,-195,-175,-145,-133,-100,-78,-47,-27,6,26,57,82,118,129,152,174,185,207,233,260,274,302,316,322,330,333,341,350,355,358,367,367,378,375,378,380,375,389,389,392,394,394,389,392,394,392,394,400,394,400,397,400,397,392,389,383,375,367,358,347,333,319,294,277,241,216,188,157,121,90,51,18,-13,-41,-78,-97,-133,-150,-184,-212,-237,-259,-287,-301,-309,-326,-337,-346,-357,-365,-371,-376,-379,-376,-373,-382,-373,-365,-362,-354,-346,-334,-318,-315,-298,-293,-273,-256,-242,-217,-192,-173,-153,-131,-97,-80,-55,-30,-11,18,37,68,96,132,163,177,207,230,244,260,266,286,302,308,322,336,339,358,361,367,375,383,383,397,406,397,414,420,425,434,431,442,442,436,442,436,439,442,436,434,434,422,414,408,397,389,380,364,358,344,325,302,288,260,235,219,185,157,132,99,62,32,6,-22,-55,-86,-117,-145,-173,-195,-217,-245,-265,-276,-298,-309,-312,-329,-326,-337,-340,-346,-337,-337,-329,-318,-315,-298,-298,-287,-270,-265,-242,-228,-220,-198,-181,-159,-136,-111,-97,-72,-58,-41,-22,-2,20,37,57,90,110,132,152,182,199,219,235,255,272,277,300,313,322,333,336,350,358,364,369,375,383,397,406,408,411,422,425,434,439,434,450,456,459,450,456,450,447,445,445,439,431,411,414,406,394,383,367,350,322,305,277,263,244,216,182,146,110,79,48,15,-11,-47,-72,-100,-136,-161,-186,-212,-226,-248,-270,-298,-307,-318,-326,-337,-348,-357,-348,-346,-354,-346,-346,-337,-337,-337,-320,-309,-307,-298,-279,-262,-242,-231,-209,-195,-170,-161,-133,-114,-89,-75,-53,-25,1,32,57,87,107,126,154,168,196,213,221,241,249,258,272,294,302,316,322,330,333,333,336,344,353,361,367,369,378,383,389,397,406,408,408,411,417,422,425,422,420,417,417,420,408,397,392,380,364,355,341,325,311,283,258,241,221,202,182,154,124,99,65,29,4,-27,-64,-94,-122,-142,-175,-206,-231,-262,-273,-290,-301,-318,-323,-337,-346,-348,-354,-354,-354,-351,-354,-354,-351,-340,-337,-326,-323,-312,-301,-295,-279,-270,-251,-240,-231,-214,-192,-181,-159,-125,-100,-75,-53,-36,-11,6,34,57,82,113,138,157,177,205,233,244,269,283,302,327,339,350,361,380,389,400,411,425,428,442,459,461,475,484,489,500,506,506,512,509,506,512,506,506,509,495,489,478,473,456,450,431,417,397,380,355,339,325,311,297,269,235,202,166,132,99,51,12,-16,-55,-80,-108,-142,-164,-192,-214,-234,-253,-267,-281,-293,-304,-304,-315,-320,-329,-329,-329,-320,-320,-315,-304,-301,-287,-279,-265,-256,-248,-228,-212,-198,-181,-167,-153,-142,-122,-108,-86,-58,-33,-8,18,40,65,90,118,138,157,174,196,210,224,244,258,272,286,305,316,336,344,358,383,394,406,414,425,431,442,450,459,473,475,487,495,498,500,498,500,506,506,500,495,489,481,464,453,422,403,386,375,347,325,305,288,260,241,219,191,166,140,107,79,43,15,-13,-41,-69,-92,-122,-147,-175,-192,-212,-231,-237,-251,-259,-265,-270,-276,-279,-276,-276,-270,-265,-262,-259,-242,-237,-226,-209,-192,-175,-161,-136,-117,-92,-69,-36,-16,9,32,57,87,118,149,180,207,230,249,269,294,313,333,344,350,358,358,369,375,380,392,394,406,417,420,422,428,434,450,456,464,473,475,487,487,495,500,506,503,512,506,500,495,487,487,473,464,450,434,414,397,386,367,353,330,313,291,266,249,224,199,171,140,115,90,62,32,1,-22,-50,-80,-103,-131,-147,-167,-192,-209,-223,-237,-251,-259,-270,-276,-281,-281,-279,-279,-279,-267,-262,-251,-242,-228,-214,-203,-189,-175,-161,-139,-108,-86,-58,-36,-13,15,40,73,96,113,140,166,188,219,241,266,286,302,319,333,344,355,361,383,394,397,408,414,422,428,436,445,450,453,453,461,459,461,461,467,473,473,475,475,478,475,470,467,467,464,461,450,445,431,422,400,386,367,344,330,313,300,286,258,230,205,182,157,129,101,68,46,26,-2,-25,-50,-69,-94,-120,-153,-175,-192,-214,-234,-256,-265,-276,-287,-293,-293,-301,-301,-307,-290,-287,-287,-279,-276,-256,-248,-237,-228,-212,-192,-173,-142,-125,-100,-72,-53,-25,-2,18,51,73,101,126,152,171,191,210,227,247,269,283,294,311,319,336,341,355,364,369,383,392,389,394,400,397,403,400,406,411,414,417,420,422,420,425,431,431,434,436,434,425,422,428,425,420,420,411,414,406,397,389,375,353,344,330,311,280,255,235,205,182,160,140,104,71,51,26,-5,-25,-53,-78,-106,-133,-147,-170,-192,-203,-212,-226,-242,-248,-256 -------------------------------------------------------------------------------- /tests/test_data_lag_30_gfnn.csv: -------------------------------------------------------------------------------- 1 | 0.9994534921849383,0.6109495117390401,0.12759303658917961,0.012967998326709893,0.0,0.0 -------------------------------------------------------------------------------- /tests/test_pypsr.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pytest 3 | 4 | import pypsr 5 | 6 | 7 | def test_ami(): 8 | a = np.arange(100) 9 | assert np.isclose(np.exp(pypsr.ami(a, a)), 10) 10 | assert np.isclose(pypsr.ami(a, np.ones_like(a)), 0) 11 | 12 | 13 | def test_ami_two_column_input(): 14 | a = np.arange(100) 15 | assert np.isclose(np.exp(pypsr.ami(np.vstack((a, a)).transpose())), 10) 16 | 17 | 18 | def test_ami_different_length_signals(): 19 | a = np.arange(10) 20 | with pytest.raises(ValueError): 21 | pypsr.ami(a, a[:-1]) 22 | 23 | 24 | def test_ami_only_one_signal(): 25 | with pytest.raises(ValueError): 26 | pypsr.ami(np.arange(10)) 27 | 28 | 29 | def test_lagged_ami(): 30 | lags, ami = pypsr.lagged_ami(np.arange(10), min_lag=0, max_lag=5) 31 | assert lags.dtype == 'int64' 32 | assert ami.dtype == 'float64' 33 | assert np.all(lags == np.arange(5)) 34 | assert np.all(np.isclose(np.exp(ami), np.arange(10, 5, -1))) 35 | 36 | 37 | def test_ami_unsqueezed_vector(): 38 | a = np.arange(10)[:, np.newaxis] 39 | assert np.isclose(np.exp(pypsr.ami(a, a)), 10) 40 | assert np.isclose(pypsr.ami(a, np.ones_like(a)), 0) 41 | 42 | 43 | def test_lagged_ami_unsqueezed_vector(): 44 | a = np.arange(10)[:, np.newaxis] 45 | lags, ami = pypsr.lagged_ami(a) 46 | assert np.all(lags == np.arange(5)) 47 | assert np.all(np.isclose(np.exp(ami), np.arange(10, 5, -1))) 48 | 49 | 50 | def test_reconstruction(): 51 | assert np.all( 52 | pypsr.reconstruct(np.arange(10), 1, 2) == np.vstack((np.arange(9), np.arange(1, 10))).transpose() 53 | ) 54 | assert np.all( 55 | pypsr.reconstruct(np.arange(10), 2, 3) 56 | == np.vstack((np.arange(6), np.arange(2, 8), np.arange(4, 10))).transpose() 57 | ) 58 | 59 | 60 | def test_reconstruction_wrong_dimension_input(): 61 | with pytest.raises(ValueError): 62 | pypsr.reconstruct(np.ones((10, 10)), 1, 2) 63 | 64 | 65 | def test_reconstruction_too_long_lag(): 66 | with pytest.raises(ValueError): 67 | pypsr.reconstruct(np.ones(10), 5, 2) 68 | with pytest.raises(ValueError): 69 | pypsr.reconstruct(np.ones(10), 2, 5) 70 | 71 | 72 | def test_gfnn(): 73 | test_data = np.loadtxt('gfnn_test_data.csv', delimiter=',') 74 | known_gfnn = np.loadtxt('test_data_lag_30_gfnn.csv', delimiter=',') 75 | lags, gfnn = pypsr.global_false_nearest_neighbors(test_data, 30, max_dims=known_gfnn.size) 76 | assert (lags == np.arange(1, known_gfnn.size + 1)).all() 77 | assert np.isclose(gfnn, known_gfnn).all() 78 | 79 | 80 | def test_gfnn_wrong_dimension_input(): 81 | with pytest.raises(ValueError): 82 | pypsr.global_false_nearest_neighbors(np.ones((10, 10)), 30) 83 | --------------------------------------------------------------------------------