-
Notifications
You must be signed in to change notification settings - Fork 0
/
MG.py
102 lines (81 loc) · 3.2 KB
/
MG.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
#entry point
import MGDataLoader
import MGNeuralNet
import MGVisualizer
import os
import argparse
import datetime
import time
import json
def GetDataList():
data = {}
with open('data/datalist.json') as data_list:
data = json.load(data_list)
return data
def SaveDataList(datalist):
with open('data/') as data_list:
json.dump(datalist, data_list)
#GLOBAL VARIABLES
VERBOSITY = False
DEBUG = False
def run(user, interval):
if not user:
raise(ValueException("Must run with a user"))
now = datetime.datetime.now()
datalist = GetDataList()
#Check if user is in datalist. If not create a user id for him
if user in datalist['users']:
userID = int(datalist['users'][user])
else
userID = len(datalist['users'])
datalist['users'][user] = userID
#Create experiment directory
expNum = len(datalist['experiments'])
expDir = 'data%sexp%d' % (os.pathsep, expNu)
imgDir = expDir + '%simg' % os.pathsep
if not os.path.exist(expDir):
os.makedirs(expDir, imgDir)
#make meta file
meta = {
'timestamp':now,
'user':user
}
meta_file_name = expDir+''+os.pathsep+'meta.json'
with open(meta_file_name, 'w') as meta_file:
json.dump(meta, meta_file)
#empty for now
info = {}
info_file_name = imgDir+''+os.pathsep+'data.json'
with open(info_file_name, 'w') as data_file:
json.dump(info, data_file)
params = {'metaFile':meta_file_name, 'infoFile':info_file_name, 'imgDir':imgDir, 'expNum':expNum, 'expDir':expDir, 'interval':interval, 'user':user, 'userID':userID, 'game':'BIT_TRIP'}
nnInput, nnMeta = MGDataLoader.CollectData(params, VERBOSITY, DEBUG)
nnTrainingData, currentNetwork = MGNeuralNet.Train(MGNeuralNet.Basic(), nnInput["training"], nnMeta, nnParams, VERBOSITY, DEBUG)
nnTestData = MGNeuralNet.Test(currentNetwork, nnInput["testing"], nnMeta, nnParams, VERBOSITY, DEBUG)
MGDataLoader.SaveNetwork(nnTrainingData, nnTestData, currentNetwork)
MGVisualizer.Analyze(nnTestData, VERBOSITY, DEBUG)
SaveDataList(datalist)
#load data from data.json and pass to Visualizer
def inspect(exp):
pass
#main loop
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='WashU BCI MindGames Data Processor')
parser.add_argument('--verbosity', '-v', help="increases output verbosity", action="store_true")
parser.add_argument('--debug', '-d', help="display debug information", action = "store_true")
parser.add_argument('--run', 'r', help="collect data and run it through the neural network", action="store_true")
parser.add_argument('--user', '-d', help="user of the emotive headset")
parser.add_argument('--runtime', help="how long to collect data (seconds)", type=int)
parser.add_argument('--inspect', 'i', help="See Visualizer data for a given experiment")
args = parser.parse_args()
if args.verbose:
print("verbosity turned on")
VERBOSITY = True
if args.debug:
print("debug turned on")
DEBUG = True
VERBOSITY = True
if args.run:
run(args.user, args.runtime)
elif not args.inspect:
inspect(args.inspect)