forked from Anthony-Cov/Timesergraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtSerGenerator.py
50 lines (47 loc) · 1.33 KB
/
ArtSerGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''Artificial time-series generator'''
import numpy as np
import pandas as pd
from os import path, makedirs, listdir, remove
from itertools import product
def trans(n):
x=np.linspace(-n*.034, n*.01, n)
y=1-1/(1+np.exp(x))
return y
def period(n):
x=np.linspace(0,16*np.pi, n)
y=np.sin(x)/2+.5
return y
def noise(n):
y=np.random.randn(n)
y=(y-min(y))/(max(y)-min(y))
return y
def rndwalk(n):
y=[0.]
for i in range(n-1):
k=np.random.rand()
sign = 1. if np.random.randint(2) else -1.
y.append(y[-1]+sign*k)
y=np.array(y)
y=(y-min(y))/(max(y)-min(y))
return y
def compose(n,kt,kp,kn,kr):
y=kt*trans(n) + kp * period(n) + kn * noise(n) + kr * rndwalk(n)
y=(y-min(y))/(max(y)-min(y))
return y
artdir='Art_series' # new folder for the artificial set
n=750 #length of a series
if not path.exists(artdir):
makedirs(artdir)
else:
for f in listdir(artdir):
remove(artdir+'/'+f)
''' По всем параметрам :) '''
i=0
for k in product([0.0, .2, .5, 1.], repeat=4):
if sum(k) < 0.5:
continue
y=compose(n,k[0],k[1],k[2],k[3])
y=(y-min(y))/(max(y)-min(y))
ser=pd.DataFrame({'t':np.arange(n), 'val':y})
ser.to_csv(artdir+'/'+str(i).zfill(4)+'.csv', index=False)
i+=1