-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreate_Dummy_Dataset.py
119 lines (91 loc) · 3.03 KB
/
Create_Dummy_Dataset.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 24 16:47:15 2020
@author: afran
"""
import numpy as np
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn import svm
from sklearn import metrics
import sklearn
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from ripser import Rips
from persim import PersImage
import pandas as pd
import os
from ripser import ripser
import matplotlib.pyplot as plt
from scipy import sparse
import time
import scipy.io as sio
import math
import matplotlib as mpl
import random
#print(x)
"""
plt.xlabel('Time', fontsize = 22)
plt.ylabel('Amplitude', fontsize = 22)
plt.title('Sinusoid', fontsize = 24)
plt.tick_params(axis = 'both', labelsize = 16)
#plt.figure(num = 1, figsize = [10, 10])
plt.plot(t, x, linewidth=5)
"""
'''
noise = np.random.normal(0,1,len(t))/5
x = []
for time in range(len(t)):
x.append(math.sin(t[time]) + noise[time])
#print(x)
plt.xlabel('Time', fontsize = 22)
plt.ylabel('Amplitude', fontsize = 22)
plt.title('Sinusoid', fontsize = 24)
plt.tick_params(axis = 'both', labelsize = 16)
#plt.figure(num = 1, figsize = [10, 10])
plt.plot(t, x, linewidth=5)
'''
for i in range(50):
length = 2*random.random() + 9
shift = 10*random.random() - 5
t = np.linspace(0,length/2*math.pi,1000)
t_cos = np.linspace(0, length*math.pi,1000)
cos_amp = 4*random.random() - 2
sin_amp = 4*random.random() - 2
x = []
for time in range(len(t)):
x.append(cos_amp*math.cos(t_cos[time]) + sin_amp*math.sin(t[time]) + shift)
noise = np.random.normal(0,1,len(x))/10
#print(noise)
x_normal = x + noise
plt.figure(1)
plt.xlabel('Time', fontsize = 22)
plt.ylabel('Amplitude', fontsize = 22)
plt.title('Sinusoid', fontsize = 24)
plt.tick_params(axis = 'both', labelsize = 16)
#plt.figure(num = 1, figsize = [10, 10])
plt.plot(t, x_normal-np.mean(x_normal))
filename = "./Dummy_Dataset/Normal_Distortion/normal_sample_" + str(i) + ".mat"
sio.savemat(filename, dict([('x', x_normal)]))
for i in range(20):
length = 2*random.random() + 9
shift = 10*random.random() - 5
t = np.linspace(0,length*math.pi,1000)
t_cos = np.linspace(0, length/2*math.pi,1000)
cos_amp = 4*random.random() - 2
sin_amp = 4*random.random() - 2
x = []
for time in range(len(t)):
x.append(cos_amp*math.cos(t_cos[time]) + sin_amp*math.sin(t[time]) + shift)
more_noise = np.random.normal(0,1,len(x))/3
#print(more_noise)
x_more_noise = x + more_noise
plt.figure(2)
plt.xlabel('Time', fontsize = 22)
plt.ylabel('Amplitude', fontsize = 22)
plt.title('Sinusoid', fontsize = 24)
plt.tick_params(axis = 'both', labelsize = 16)
#plt.figure(num = 1, figsize = [10, 10])
plt.plot(t, x_more_noise-np.mean(x_more_noise))
filename = "./Dummy_Dataset/Increased_Distortion/increased_sample_" + str(i) + ".mat"
sio.savemat(filename, dict([('x', x_more_noise)]))