-
Notifications
You must be signed in to change notification settings - Fork 12
/
exstracs_timer.py
366 lines (290 loc) · 13.8 KB
/
exstracs_timer.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
"""
Name: ExSTraCS_Timer.py
Authors: Ryan Urbanowicz - Written at Dartmouth College, Hanover, NH, USA
Contact: [email protected]
Created: April 25, 2014
Modified: August 25,2014
Description: This module's role is largely for development and evaluation purposes. Specifically it tracks not only global run time for ExSTraCS, but
tracks the time utilized by different key mechanisms of the algorithm. This tracking likely wastes a bit of run time, so for optimal performance
check that all 'cons.timer.startXXXX', and 'cons.timer.stopXXXX' commands are commented out within ExSTraCS_Main, ExSTraCS_Test, ExSTraCS_Algorithm,
and ExSTraCS_ClassifierSet.
---------------------------------------------------------------------------------------------------------------------------------------------------------
ExSTraCS V2.0: Extended Supervised Tracking and Classifying System - An advanced LCS designed specifically for complex, noisy classification/data mining tasks,
such as biomedical/bioinformatics/epidemiological problem domains. This algorithm should be well suited to any supervised learning problem involving
classification, prediction, data mining, and knowledge discovery. This algorithm would NOT be suited to function approximation, behavioral modeling,
or other multi-step problems. This LCS algorithm is most closely based on the "UCS" algorithm, an LCS introduced by Ester Bernado-Mansilla and
Josep Garrell-Guiu (2003) which in turn is based heavily on "XCS", an LCS introduced by Stewart Wilson (1995).
Copyright (C) 2014 Ryan Urbanowicz
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABLILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
---------------------------------------------------------------------------------------------------------------------------------------------------------
"""
#Import Required Modules-------------------------------
from exstracs_constants import *
import time
#------------------------------------------------------
class Timer:
def __init__(self):
""" Initializes all Timer values for the algorithm """
# Global Time objects
self.globalStartRef = time.time()
self.globalTime = 0.0
self.addedTime = 0.0
# Match Time Variables
self.startRefMatching = 0.0
self.globalMatching = 0.0
# Covering Time Variables
self.startRefCovering = 0.0
self.globalCovering = 0.0
# Deletion Time Variables
self.startRefDeletion = 0.0
self.globalDeletion = 0.0
# Subsumption Time Variables
self.startRefSubsumption = 0.0
self.globalSubsumption = 0.0
# Selection Time Variables
self.startRefSelection = 0.0
self.globalSelection = 0.0
# Crossover Time Variables
self.startRefCrossover = 0.0
self.globalCrossover = 0.0
# Mutation Time Variables
self.startRefMutation = 0.0
self.globalMutation = 0.0
# Attribute Tracking and Feedback
self.startRefAT = 0.0
self.globalAT = 0.0
# Expert Knowledge (EK)
self.startRefEK = 0.0
self.globalEK = 0.0
# OutFile
self.startRefOutFile = 0.0
self.globalOutFile = 0.0
# Initialization
self.startRefInit = 0.0
self.globalInit = 0.0
# Add Classifier
self.startRefAdd = 0.0
self.globalAdd = 0.0
# Evaluation Time Variables
self.startRefEvaluation = 0.0
self.globalEvaluation = 0.0
# Rule Compaction
self.startRefRuleCmp = 0.0
self.globalRuleCmp = 0.0
# Rule Compaction
self.startRefTEST = 0.0
self.globalTEST = 0.0
#Debug Counter
self.globalTESTCounter = 0
# ************************************************************
def startTimeMatching(self):
""" Tracks MatchSet Time """
self.startRefMatching = time.time()
def stopTimeMatching(self):
""" Tracks MatchSet Time """
diff = time.time() - self.startRefMatching
self.globalMatching += diff
# ************************************************************
def startTimeCovering(self):
""" Tracks MatchSet Time """
self.startRefCovering = time.time()
def stopTimeCovering(self):
""" Tracks MatchSet Time """
diff = time.time() - self.startRefCovering
self.globalCovering += diff
# ************************************************************
def startTimeDeletion(self):
""" Tracks Deletion Time """
self.startRefDeletion = time.time()
def stopTimeDeletion(self):
""" Tracks Deletion Time """
diff = time.time() - self.startRefDeletion
self.globalDeletion += diff
# ************************************************************
def startTimeCrossover(self):
""" Tracks Crossover Time """
self.startRefCrossover = time.time()
def stopTimeCrossover(self):
""" Tracks Crossover Time """
diff = time.time() - self.startRefCrossover
self.globalCrossover += diff
# ************************************************************
def startTimeMutation(self):
""" Tracks Mutation Time """
self.startRefMutation = time.time()
def stopTimeMutation(self):
""" Tracks Mutation Time """
diff = time.time() - self.startRefMutation
self.globalMutation += diff
# ************************************************************
def startTimeSubsumption(self):
"""Tracks Subsumption Time """
self.startRefSubsumption = time.time()
def stopTimeSubsumption(self):
"""Tracks Subsumption Time """
diff = time.time() - self.startRefSubsumption
self.globalSubsumption += diff
# ************************************************************
def startTimeSelection(self):
""" Tracks Selection Time """
self.startRefSelection = time.time()
def stopTimeSelection(self):
""" Tracks Selection Time """
diff = time.time() - self.startRefSelection
self.globalSelection += diff
# ************************************************************
def startTimeEvaluation(self):
""" Tracks Evaluation Time """
self.startRefEvaluation = time.time()
def stopTimeEvaluation(self):
""" Tracks Evaluation Time """
diff = time.time() - self.startRefEvaluation
self.globalEvaluation += diff
# ************************************************************
def startTimeRuleCmp(self):
""" """
self.startRefRuleCmp = time.time()
def stopTimeRuleCmp(self):
""" """
diff = time.time() - self.startRefRuleCmp
self.globalRuleCmp += diff
# ***********************************************************
def startTimeAT(self):
""" """
self.startRefAT = time.time()
def stopTimeAT(self):
""" """
diff = time.time() - self.startRefAT
self.globalAT += diff
# ***********************************************************
def startTimeEK(self):
""" """
self.startRefEK = time.time()
def stopTimeEK(self):
""" """
diff = time.time() - self.startRefEK
self.globalEK += diff
# ***********************************************************
def startTimeOutFile(self):
""" """
self.startRefOutFile = time.time()
def stopTimeOutFile(self):
""" """
diff = time.time() - self.startRefOutFile
self.globalOutFile += diff
# ***********************************************************
def startTimeInit(self):
""" """
self.startRefInit = time.time()
def stopTimeInit(self):
""" """
diff = time.time() - self.startRefInit
self.globalInit += diff
# ***********************************************************
def startTimeAdd(self):
""" """
self.startRefAdd = time.time()
def stopTimeAdd(self):
""" """
diff = time.time() - self.startRefAdd
self.globalAdd += diff
# ***********************************************************
def startTimeTEST(self):
""" """
self.startRefTEST = time.time()
def stopTimeTEST(self):
""" """
diff = time.time() - self.startRefTEST
self.globalTEST += diff
# ***********************************************************
def returnGlobalTimer(self):
""" Set the global end timer, call at very end of algorithm. """
self.globalTime = (time.time() - self.globalStartRef) + self.addedTime #Reports time in minutes, addedTime is for population reboot.
return self.globalTime/ 60.0
def TESTCounter(self):
""" Set the global end timer, call at very end of algorithm. """
self.globalTESTCounter += 1
def setTimerRestart(self, remakeFile):
""" Sets all time values to the those previously evolved in the loaded popFile. """
print(remakeFile+"_PopStats.txt")
try:
fileObject = open(remakeFile+"_PopStats.txt", 'rU') # opens each datafile to read.
except Exception as inst:
print(type(inst))
print(inst.args)
print(inst)
print('cannot open', remakeFile+"_PopStats.txt")
raise
timeDataRef = 22
tempLine = None
for i in range(timeDataRef):
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.addedTime = float(tempList[1]) * 60 #previous global time added with Reboot.
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalMatching = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalCovering = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalDeletion = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalSubsumption = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalSelection = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalCrossover = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalMutation = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalAT = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalEK = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalOutFile = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalInit = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalAdd = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalEvaluation = float(tempList[1]) * 60
tempLine = fileObject.readline()
tempList = tempLine.strip().split('\t')
self.globalRuleCmp = float(tempList[1]) * 60
fileObject.close()
def reportTimes(self):
self.returnGlobalTimer()
""" Reports the time summaries for this run. Returns a string ready to be printed out."""
outputTime = "Global Time\t"+str(self.globalTime/ 60.0)+ \
"\nMatching Time\t" + str(self.globalMatching/ 60.0)+ \
"\nCovering Time\t" + str(self.globalCovering/ 60.0)+ \
"\nDeletion Time\t" + str(self.globalDeletion/ 60.0)+ \
"\nSubsumption Time\t" + str(self.globalSubsumption/ 60.0)+ \
"\nSelection Time\t"+str(self.globalSelection/ 60.0)+ \
"\nCrossover Time\t" + str(self.globalCrossover/ 60.0)+ \
"\nMutation Time\t" + str(self.globalMutation/ 60.0)+ \
"\nAttribute Tracking-Feedback Time\t"+str(self.globalAT/ 60.0) + \
"\nExpert Knowledge Time\t"+str(self.globalEK/ 60.0) + \
"\nOutput File Time\t"+str(self.globalOutFile/ 60.0) + \
"\nInitialization Time\t"+str(self.globalInit/ 60.0) + \
"\nAdd Classifier Time\t"+str(self.globalAdd/ 60.0) + \
"\nEvaluation Time\t"+str(self.globalEvaluation/ 60.0) + \
"\nRule Compaction Time\t"+str(self.globalRuleCmp/ 60.0) + "\n"
return outputTime