-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrealdata_processor.py
More file actions
84 lines (73 loc) · 2.77 KB
/
realdata_processor.py
File metadata and controls
84 lines (73 loc) · 2.77 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Real Data Extractor
extract UCR time series dataset from 15 dataset
each dataset would be extracted one record to real_data_set.txt
Note:
drop Trajectory category cause the dataset contain lots of '?' data
"""
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from collections import OrderedDict
from tsseg.utils import *
from tsseg.greed import *
from tsseg.omslr import *
dnames = ['Device:SmallKitchenAppliances','ECG:ECGFiveDays','EOG:EOGVerticalSignal','EPG:InsectEPGRegularTrain','Hemodynamics:PigCVP','HRM:Fungi','Image:MiddlePhalanxOutlineAgeGroup','Motion:UWaveGestureLibraryAll','Power:PowerCons','Sensor:Plane','Simulated:CBF','Spectro:Ham','Spectrum:Rock','Traffic:Chinatown']
def extract():
dataset_list = OrderedDict({
'Device': 'SmallKitchenAppliances',
'ECG': 'ECGFiveDays',
'EOG': 'EOGVerticalSignal',
'EPG': 'InsectEPGRegularTrain',
'Hemodynamics': 'PigCVP',
'HRM': 'Fungi',
'Image': 'MiddlePhalanxOutlineAgeGroup',
'Motion': 'UWaveGestureLibraryAll',
'Power': 'PowerCons',
'Sensor': 'Plane',
'Simulated': 'CBF',
'Spectro': 'Ham',
'Spectrum': 'Rock',
'Traffic': 'Chinatown'
})
fw = open('realdataset.txt', 'w')
for k in dataset_list:
dname = dataset_list[k]
df = pd.read_csv('dataset/{0}/{0}_TRAIN.csv'.format(dname))
df = df.drop('target', axis=1)
# print(df.iloc[0].values.tolist())
fw.write('{}\n'.format(df.iloc[0].values.tolist()))
fw.close()
def omslr_testing():
dataset = [eval(line) for line in list(filter(None, open('realdataset.txt').read().split('\n')))]
t = dataset[2]
for i, t in enumerate(dataset):
sigma, beta, alpha = iter_sigma(t)
gamma, rho = omslr_minmax(t, 3, sigma)
pivots = get_pivots(gamma)
err = rho[-1][-1]
pvts_td = seg2pivots(top_down(t, err))
pvts_bu = seg2pivots(bottom_up(t, err))
with open('k_seg tesint.txt', 'a') as fa:
fa.write('{}:\n'.format(dnames[i]))
fa.write('error={}\n'.format(err))
fa.write('OMSLR MinMax\n')
fa.write('{}\n'.format(pivots))
fa.write('Top-Down')
fa.write('{}\n'.format(pvts_td))
fa.write('Bottom-Up')
fa.write('{}\n\n'.format(pvts_bu))
def plot_dataset():
dataset = [eval(line) for line in list(filter(None, open('realdataset.txt').read().split('\n')))]
L = len(dataset)
plt.figure(figsize=(16,90), dpi=150)
for i, ds in enumerate(dataset):
plt.subplot(L, 1, i+1)
plt.plot(ds, '.-', label=dnames[i])
plt.title(dnames[i])
plt.tight_layout()
plt.savefig('all_dataset')
extract()
plot_dataset()
# omslr_testing()