-
Notifications
You must be signed in to change notification settings - Fork 3
/
scriptController.py
117 lines (78 loc) · 3.52 KB
/
scriptController.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
import json
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='3' #disable tensorflow debugging
import sys
from multiprocessing import Pool
from datetime import datetime
import script
from handlers.fileHandler import getConfig
from handlers.fileHandler import *
from sideCode.animatedLoading import animatedLoading
#TODO: clear all WARNINGS!
def main(controllerConfig):
startTime = datetime.now()
with open(controllerConfig, 'r') as fileReader:
data = json.load(fileReader)
config = getConfig(data["configFile"])
##############################################################################
# OPTION GENERATION
##############################################################################
print("\nGENERATING OPTIONS...")
options = []
#GENERATE all possible case scenarios:
for cognitiveData in data["cognitiveData"]:
for feature in data["cognitiveData"][cognitiveData]["features"]:
for wordEmbedding in data["wordEmbeddings"]:
option = {"cognitiveData": "empty", "feature": "empty", "wordEmbedding": "empty"}
option["cognitiveData"] = cognitiveData
option["feature"] = feature
option["wordEmbedding"]=wordEmbedding
options.append(option)
loggings = []
word_errors = []
histories = []
print("\nSUCCESSFUL OPTIONS GENERATION")
##############################################################################
# JOINED DATAFRAMES GENERATION
##############################################################################
##############################################################################
# Parallelized version
##############################################################################
print("\nMODELS CREATION, FITTING, PREDICTION...\n ")
proc = min(os.cpu_count(),config["cpu_count"])
print("RUNNING ON "+str(proc)+" PROCESSORS\n")
pool = Pool(processes=proc)
async_results = [pool.apply_async(script.run,args=(config,
options[i]["wordEmbedding"],
options[i]["cognitiveData"],
options[i]["feature"])) for i in range(len(options))]
pool.close()
while (False in [async_results[i].ready() == True for i in range(len(async_results))]):
completed = [async_results[i].ready() == True for i in range(len(async_results))].count(True)
animatedLoading(completed, len(async_results))
pool.join()
for p in async_results:
logging, word_error, history = p.get()
loggings.append(logging)
word_errors.append(word_error)
histories.append(history)
print("\nSUCCESSFUL MODELS")
##############################################################################
# Store results
##############################################################################
print("\nSTORING RESULTS...")
all_runs = {}
for i in range(0,len(loggings)):
config = getConfig(data["configFile"])
writeResults(config, loggings[i], word_errors[i], histories[i])
options[i]["AVERAGE_MSE"] = loggings[i]["AVERAGE_MSE"]
all_runs[config["version"]] = options[i]
updateVersion(data["configFile"])
writeOptions(config,all_runs)
print("\nSUCCESSFUL STORING")
print("\nSUCCESSFUL RUN")
timeTaken = datetime.now() - startTime
print('\n' + str(timeTaken))
pass
if __name__=="__main__":
main("config/c.json")