-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataReader.py
More file actions
160 lines (119 loc) · 4.59 KB
/
DataReader.py
File metadata and controls
160 lines (119 loc) · 4.59 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 17 11:26:01 2024
@author: the-brainputer
"""
import random as r
import numpy as np
pathRight = "TestData/Actions/RIGHT/"
pathLeft = "TestData/Actions/LEFT/"
"""-----------------------Read-Data--------------------------------"""
def readData(classToRead: str, testSamples: float):
"""
Read the Data from one or multiple classes (seperated by comma) and returns to you a sorted (unshuffled) trainingSet and testSet in the ratio you specified.
Parameters
----------
classToRead : str
Specify the classes you want to read. Seperate multiple classes by comma.
testSamples : float
percantage of test samples you want in range 0 to 1.0
Returns
-------
trainingSet : list
List of arrays for training pruposes
testSet : list
List of arrays for testing purposes
"""
trainingSet = []
trainingSetLabel = []
testSet = []
testSetLabel = []
#To have the classes seperated
classToRead = classToRead.replace(" ", "")
classToRead = classToRead.lower()
classToRead = classToRead.split(",")
for el in classToRead:
match el:
case "right":
t_trainingSet, t_testSet, t_trainingSetLabel, t_testSetLabel = _readClass(pathRight, testSamples, "right")
trainingSet += t_trainingSet
testSet += t_testSet
trainingSetLabel += t_trainingSetLabel
testSetLabel += t_testSetLabel
case "left":
t_trainingSet, t_testSet, t_trainingSetLabel, t_testSetLabel = _readClass(pathLeft, testSamples, "left")
trainingSet += t_trainingSet
testSet += t_testSet
trainingSetLabel += t_trainingSetLabel
testSetLabel += t_testSetLabel
case _:
print("Error: Class name not found")
return trainingSet, testSet, trainingSetLabel, testSetLabel
def readData(classToRead: str):
"""
Read the Data from one or multiple classes (seperated by comma) and returns to you a sorted (unshuffled) trainingSet.
Parameters
----------
classToRead : str
Specify the classes you want to read. Seperate multiple classes by comma.
Returns
-------
dataSet : list
List of arrays
dataSetLabel : list
List of Labels for dataSet
"""
dataSet = []
dataSetLabel = []
#To have the classes seperated
classToRead = classToRead.replace(" ", "")
classToRead = classToRead.lower()
classToRead = classToRead.split(",")
for el in classToRead:
match el:
case "right":
t_dataSet, t_dataSetLabel = _readClass(pathRight, "right")
dataSet += t_dataSet
dataSetLabel += t_dataSetLabel
case "left":
t_dataSet, t_dataSetLabel = _readClass(pathLeft, "left")
dataSet += t_dataSet
dataSetLabel += t_dataSetLabel
case _:
print("Error: Class name not found")
return dataSet, dataSetLabel
def _readClass(path: str, testSamples: float, label: str):
trainingSet = []
testSet = []
trainingSetLabel = []
testSetLabel = []
file = open(path + 'save.txt', 'r')
count = int(file.read())
for i in range(count):
data = np.load(path + "data{}.npy".format(i))
if(r.random() < testSamples):
testSet.append(data)
testSetLabel.append(label)
else:
trainingSet.append(data)
trainingSetLabel.append(label)
return trainingSet, testSet, trainingSetLabel, testSetLabel
def _readClass(path: str, label: str):
dataSet = []
dataSetLabel = []
file = open(path + 'save.txt', 'r')
count = int(file.read())
for i in range(count):
data = np.load(path + "data{}.npy".format(i))
dataSet.append(data)
dataSetLabel.append(label)
return dataSet, dataSetLabel
"""----------------------Modify-Data-------------------------------"""
def splitComplex(complexArrayToSplit: np.array):
arrayReal = complexArrayToSplit.real
arrayImag = complexArrayToSplit.imag
arrayComplex = np.empty((complexArrayToSplit.shape[0], complexArrayToSplit.shape[1], 2))
arrayComplex[ : , : , 0] = arrayReal
arrayComplex[ : , : , 1] = arrayImag
return arrayComplex