-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
executable file
·66 lines (49 loc) · 2.6 KB
/
Copy pathutils.py
File metadata and controls
executable file
·66 lines (49 loc) · 2.6 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
from imp import load_source
import logging
import sys
from numpy import array_equal
LOG_FORMAT = '%(asctime)s|[%(process)d_%(thread)d] - [%(module)s][%(funcName)s][%(lineno)d] %(levelname)s: %(message)s'
LOG_LEVEL = logging.DEBUG
def load_script(filename, script_type):
"""
Loads a fitness or configuration script. script_type is either
'fitness' or 'configuration'.
"""
try:
return load_source(script_type, filename)
except Exception,e:
logging.error(str(script_type.capitalize()) + ' file (' + str(filename) + ') could not be loaded ' + str(e))
return None
def numpy_array_index(multi_array, array):
#TODO - check if multi_array is non empty and if they match size.. throw appropariate warnings
if not multi_array is None:
try:
for i,trainp in enumerate(multi_array):
if array_equal(trainp,array):
return True, i
except:
pass ## should probabnly give debug messages
return False, 0
##returns class constructor
def get_trial_dict():
from model.trials.trial import PSOTrial, MOPSOTrial, PSOTrial_TimeAware
return {"PSOTrial" : PSOTrial,
"MOPSOTrial" : MOPSOTrial,
"PSOTrial_TimeAware" : PSOTrial_TimeAware,
"Blank" : None}
def get_trial_constructor(str_name):
return get_trial_dict()[str_name]
def get_possible_trial_type():
return get_trial_dict().keys()
def get_trial_type_visualizer(trial_name):
from views.visualizers.plot import MLOImageViewer, MOMLOImageViewer, MLOTimeAware_ImageViewer
return {"PSOTrial" : {"MLOImageViewer" : MLOImageViewer, "default" : MLOImageViewer},
"MOPSOTrial" : {"MOMLOImageViewer" : MOMLOImageViewer, "default" : MOMLOImageViewer},
"PSOTrial_TimeAware" : {"MLOTimeAware_ImageViewer" : MLOTimeAware_ImageViewer, "default" : MLOTimeAware_ImageViewer},
"Blank" : {"Blank" : None, "default" : None}}[trial_name]
def get_run_type_visualizer(trial_name):
from views.visualizers.plot import MLORunReportViewer,MLORegressionReportViewer
return {"PSOTrial" : {"MLOReportViewer" : MLORunReportViewer,"regressions": MLORegressionReportViewer, "default" : MLORunReportViewer},
"MOPSOTrial" : {"MLOReportViewer" : MLORunReportViewer,"regressions": MLORegressionReportViewer, "default" : MLORunReportViewer},
"PSOTrial_TimeAware" : {"MLOReportViewer" : MLORunReportViewer,"regressions": MLORegressionReportViewer, "default" : MLORunReportViewer},
"Blank" : {"Blank" : None, "default" : None}}[trial_name]