In [5]:
import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
    print(f)


znorm_tinkah.ipynb

In [24]:
from numpy import genfromtxt
dd = genfromtxt("/home/psenin/git/saxpy/data/insect.txt", delimiter=',')

In [15]:
len(dd)


Out[15]:
18667

In [16]:
type(dd[1])


Out[16]:
numpy.float64

In [13]:
import matplotlib.pyplot as plt
plt.plot(dd)


/home/psenin/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:279: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  'Matplotlib is building the font cache using fc-list. '
Out[13]:
[<matplotlib.lines.Line2D at 0x7fcf94f40b38>]

In [14]:
plt.show()



In [25]:
import numpy as np
def znorm(series, znorm_threshold=0.01):
    """Fallback Python implementation."""
    sd = np.std(series)
    if (sd < znorm_threshold):
        return series
    mean = np.mean(series)
    res = (series - mean)/sd
    return res

In [26]:
dd_norm = znorm(dd, 0.001)

In [29]:
type(dd_norm)


Out[29]:
numpy.ndarray

In [27]:
plt.plot(dd_norm)
plt.show()



In [28]:
%timeit -r 10 a = znorm(dd, 0.001)


84.3 µs ± 3.98 µs per loop (mean ± std. dev. of 10 runs, 10000 loops each)

In [ ]:
setup = '''
from numpy import genfromtxt
dd = genfromtxt("/home/psenin/git/saxpy/data/insect.txt", delimiter=',')
from saxpy import znorm
'''
import timeit
timeit.Timer('a=znorm.znorm(dd, 0.001)', setup=setup).repeat(7, 1000)

In [ ]:
setup = '''
from numpy import genfromtxt
dd = genfromtxt("/home/psenin/git/saxpy/data/insect.txt", delimiter=',')
from saxpy import znorm
'''
import timeit
timeit.Timer('a=znorm.znorm(dd, 0.001)', setup=setup).repeat(7, 1000)

In [ ]:


In [ ]:
from numpy import std
from saxpy import znorm as zn

In [ ]:
"""Test the znorm implementation."""
ts = [-1., -2., -1., 0., 2., 1., 1., 0.]
z_thrsh = 0.001

x_scaled = [x / 100.0 for x in ts]

In [ ]:
zn.znorm(x_scaled, z_thrsh)

In [1]:
import inspect
from saxpy import znorm as zn
lines = inspect.getsourcelines(zn.znorm)
print("".join(lines[0]))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-08dcd0eed067> in <module>()
      1 import inspect
      2 from saxpy import znorm as zn
----> 3 lines = inspect.getsourcelines(zn.znorm)
      4 print("".join(lines[0]))

AttributeError: 'builtin_function_or_method' object has no attribute 'znorm'

In [ ]:
import numpy as np
def znorm(series, znorm_threshold=0.01):
    """Fallback Python implementation."""
    sd = np.std(series)
    if (sd < znorm_threshold):
        return series
    mean = np.mean(series)
    res = np.zeros(len(series))
    for i in range(0, len(series)):
        res[i] = (series[i] - mean) / sd
    return res.ravel()

In [ ]:
mean = np.mean(zz)
mean

In [ ]:
std = np.std(zz, axis=0, ddof=1)
std

In [ ]:


In [ ]:


In [ ]: