simple time series encoding package, focused on financial tasks.
this is an simple example:
import numpy as np
from series2gaf import GenerateGAF
# create a random sequence with 200 numbers
# all numbers are in the range of 50.0 to 150.0
random_series = np.random.uniform(low=50.0, high=150.0, size=(200,))
# set parameters
timeSeries = list(random_series)
windowSize = 50
rollingLength = 10
fileName = 'demo_%02d_%02d'%(windowSize, rollingLength)
# generate GAF pickle file (output by Numpy.dump)
GenerateGAF(all_ts = timeSeries,
window_size = windowSize,
rolling_length = rollingLength,
fname = fileName)
now we get a file named _demo_50_10_gaf.pkl_ in current directory. inside the pickle file, you got a grammian angular field with shape (15, 50, 50).
Thats It!
if we want to preview the image results, just add these to the code:
from series2gaf import PlotHeatmap
gaf = np.load('%s_gaf.pkl'%fileName)
PlotHeatmap(gaf)
we can now find GAF heapmap images in a new child directory _/output_img_!
def GenerateGAF(all_ts, window_size, rolling_length, fname,
normalize_window_scaling=1.0, method='summation', scale='[0,1]'):
...
def PlotHeatmap(all_img, save_dir='output_img'):
...
_all_ts: list_
the time series we want to transform.
_window_size: int_
the sliding window size for transforming sequences into GAF images
_rolling_length: int_
also known as "stride value" for the sliding window
fname: str
output file name, the output pickle file will be named as "[fname]_gaf.pkl"
_normalize_window_scaling: float, optional_
default: 1.0
normalize the values in the windows, but considering a ratio of previous values
method: str, optional
default: 'summation'
'summation'
is for GASF ( calculate cos(x1+x2) )
'difference'
if for GADF ( calculate sin(x1-x2) )
scale: str, optoinal
default: '[0,1]'
'[0,1]'
means normalize the sequence in the range of 0 and 1
'[-1,1]'
means normalize the sequence in the range of -1 and 1
_all_img: numpy.array_
input GAF multi-dimension array
_save_dir: str, optional_
_default: 'outputimg'
directory for output images