summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/fileformat4
-rw-r--r--estimate.py42
2 files changed, 42 insertions, 4 deletions
diff --git a/docs/fileformat b/docs/fileformat
index e147644..6a30aba 100644
--- a/docs/fileformat
+++ b/docs/fileformat
@@ -45,10 +45,10 @@ Status File Format
<sub-directory>#model-candidates-<num>.db#<score>
The lines are sorted by <score>.
Prune Status Files
- 1. 'merged.db', 'kmm_merged.text' , 'pruned.db', 'kmm_pruned.text', 'interpolation.text' are generated when running prune tools in 'finals/try<num>' sub-directory.
+ 1. 'merged.db', 'kmm_merged.text' , 'pruned.db', 'kmm_pruned.text', 'interpolation.text' are generated when running prune tools in 'finals/try<name>' sub-directory.
2. 'prune.status' file are generated also, like:
{'PruneEpoch': 4, 'PruneMergeNumber': 1000,
'PruneK':2, 'PruneCDF': 0.6}
Evaluate Status Files
1. 'evaluate.status' file are generated, like:
- {'EvaluateEpoch': 5, 'EvaluateCorrectionRate': 0.77} \ No newline at end of file
+ {'EvaluateEpoch': 5, 'EvaluateAverageLambda': 0.66, 'EvaluateCorrectionRate': 0.77} \ No newline at end of file
diff --git a/estimate.py b/estimate.py
index e621dcb..6ba0471 100644
--- a/estimate.py
+++ b/estimate.py
@@ -4,6 +4,7 @@ import os.path
import sys
from subprocess import Popen, PIPE
from argparse import ArgumentParser
+from operator import itemgetter
import utils
from myconfig import MyConfig
@@ -67,6 +68,12 @@ def walkThroughModels(path):
print('Unexpected file:' + filepath)
def gatherModels(path, indexname):
+ indexfilestatuspath = indexname + config.getStatusPostfix()
+ indexfilestatus = utils.load_status(indexfilestatuspath)
+ if utils.check_epoch(indexfilestatuspath, 'Estimate'):
+ return
+
+ #begin processing
indexfile = open(indexname, "w")
for root, dirs, files in os.walk(path, topdown=True, onerror=handleError):
for onefile in files:
@@ -91,9 +98,40 @@ def gatherModels(path, indexname):
else:
print('Unexpected file:' + filepath)
indexfile.close()
+ #end processing
-def sortModels(indexfilename, sortedindexfilename):
- pass
+ utils.sign_epoch(indexfilestatus, 'Estimate')
+ utils.store_status(indexfilestatuspath, indexfilestatus)
+
+def sortModels(indexname, sortedindexname):
+ sortedindexfilestatuspath = sortedindexname + config.getStatusPostfix()
+ sortedindexfilestatus = utils.load_status(sortedindexfilestatuspath)
+ if utils.check_epoch(sortedindexfilestatus, 'Estimate'):
+ return
+
+ #begin processing
+ records = []
+ indexfile = open(indexname, 'r')
+ for line in indexfile.readlines():
+ #remove the trailing '\n'
+ line = line.rstrip(os.linesep)
+ (subdir, modelname, score) = line.split('#', 2)
+ score = float(score)
+ records.append((subdir, modelname, score))
+ indexfile.close()
+
+ records.sort(key=itemgetter(2), reverse=True)
+
+ sortedindexfile = open(sortedindexname, 'w')
+ for record in records:
+ (subdir, modelname, score) = record
+ line = subdir + '#' + modelname + '#' + score
+ sortedindexfile.writelines([line])
+ sortedindexfile.close()
+ #end processing
+
+ utils.sign_epoch(sortedindexfilestatus, 'Estimate')
+ utils.store_status(sortedindexfilestatuspath, sortedindexfilestatus)
if __name__ == '__main__':
pass