Skip to content

Commit f3f4241

Browse files
author
huergasi
committed
float32 for operations v3
1 parent 682ef24 commit f3f4241

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

scripts/preprocessData.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def parsefile(filename, targetoffset):
1818
i = 0
1919
for line in file:
2020
row = np.array(line.split(','))
21-
current = np.take(row, indices).astype(np.float)
21+
current = np.take(row, indices).astype(np.float32)
2222
if start == 0:
23-
previous = np.take(row, indices).astype(np.float)
24-
previous_volume = np.take(row, volume_index).astype(np.float)
23+
previous = np.take(row, indices).astype(np.float32)
24+
previous_volume = np.take(row, volume_index).astype(np.float32)
2525
start+=1
2626
else:
27-
current_volume = np.take(row, volume_index).astype(np.float)
27+
current_volume = np.take(row, volume_index).astype(np.float32)
2828
sample = np.empty((1,current.size + 1))
2929
for index in np.arange(current.size):
3030
sample[0][index] = ((current[index] - previous[index]) / previous[index]) * 100
@@ -44,28 +44,28 @@ def parse_and_normalize_file(filename, targetoffset, mu, sigma, y_max, y_min):
4444
file = open(filename, 'r')
4545
start = 0
4646
previous = []
47-
x= np.empty([1,13], dtype=t.config.floatX)
48-
y= np.empty([1], dtype=t.config.floatX)
47+
x= np.empty([1,13], dtype=np.float32)
48+
y= np.empty([1], dtype=np.float32)
4949
i = 0
5050
for line in file:
5151
row = np.array(line.split(','))
52-
current = np.take(row, indices).astype(np.float)
52+
current = np.take(row, indices).astype(np.float32)
5353
if start == 0:
54-
previous = np.take(row, indices).astype(np.float)
55-
previous_volume = np.take(row, volume_index).astype(np.float)
54+
previous = np.take(row, indices).astype(np.float32)
55+
previous_volume = np.take(row, volume_index).astype(np.float32)
5656
start+=1
5757
else:
58-
current_volume = np.take(row, volume_index).astype(np.float)
58+
current_volume = np.take(row, volume_index).astype(np.float32)
5959
sample = np.empty((1,current.size + 1))
6060
for index in np.arange(current.size):
6161
sample[0][index] = ((current[index] - previous[index]) / previous[index]) * 100
6262
sample[0][current.size] = current_volume
6363
previous = current
6464
if i < (original_data.size / 13) - targetoffset:
65-
sample = (sample - mu )/ sigma
65+
sample = ((sample - mu )/ sigma).astype(np.float32)
6666
x = np.vstack((x, sample))
67-
current_y = ((original_data[(i + targetoffset)*13] - current[0]) / current[0]) * 100
68-
current_y = (2* (current_y - y_min) / (y_max-y_min)) -1
67+
current_y = (((original_data[(i + targetoffset)*13] - current[0]) / current[0]) * 100).astype(np.float32)
68+
current_y = ((2 * (current_y - y_min) / (y_max-y_min)) - 1).astype(np.float32)
6969
y = np.vstack((y,current_y))
7070
i+=1
7171
x = np.delete(x, 0, 0)
@@ -77,8 +77,8 @@ def get_mu_sigma_y(filepath, targetoffset):
7777
files = [f for f in listdir(filepath) if isfile(join(filepath, f))]
7878
alldata = []
7979
ally=[]
80-
mu = np.zeros((13,), dtype=np.float64)
81-
sigma = np.zeros((13,), dtype=np.float64)
80+
mu = np.zeros((13,), dtype=np.float32)
81+
sigma = np.zeros((13,), dtype=np.float32)
8282
y_max = 0
8383
y_min = 0
8484
for f in files:
@@ -124,8 +124,8 @@ def getoriginaldata(filename):
124124
return data
125125

126126
def getdata():
127-
path_training=r"C:\Users\huergasi\MLCode\myCode\data\ib\30sec\training"
128-
path_testing=r"C:\Users\huergasi\MLCode\myCode\data\ib\30sec\testing"
127+
path_training=r"C:\Users\huergasi\MLCode\myCode\data\ib\30sec\training_sample"
128+
path_testing=r"C:\Users\huergasi\MLCode\myCode\data\ib\30sec\testing_sample"
129129
path_validation=r"C:\Users\huergasi\MLCode\myCode\data\ib\30sec\validation_sample"
130130

131131
training_files= [f for f in listdir(path_training) if isfile(join(path_training, f))]

0 commit comments

Comments
 (0)