diff options
author | Peng Wu <alexepico@gmail.com> | 2011-07-27 18:56:01 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-07-27 18:56:01 +0800 |
commit | c676243f85f22ace3ca18dcb07e79db2b133f21c (patch) | |
tree | 70079abc8c27822509868706e99528f0aee610f5 /estimate.py | |
parent | 5b2b30242c8b07b954e7a0bf7b647c2a6e219c47 (diff) | |
download | trainer-c676243f85f22ace3ca18dcb07e79db2b133f21c.tar.gz trainer-c676243f85f22ace3ca18dcb07e79db2b133f21c.tar.xz trainer-c676243f85f22ace3ca18dcb07e79db2b133f21c.zip |
fixes estimate.py
Diffstat (limited to 'estimate.py')
-rwxr-xr-x | estimate.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/estimate.py b/estimate.py index eaec334..ef5c40a 100755 --- a/estimate.py +++ b/estimate.py @@ -22,7 +22,7 @@ def handleError(error): sys.exit(error) -def handleOneModel(modelfile): +def handleOneModel(modelfile, reportfile): modelfilestatuspath = modelfile + config.getStatusPostfix() modelfilestatus = utils.load_status(modelfilestatuspath) if not utils.check_epoch(modelfilestatus, 'Generate'): @@ -30,6 +30,8 @@ def handleOneModel(modelfile): if utils.check_epoch(modelfilestatus, 'Estimate'): return + reporthandle = open(reportfile, 'wb') + result_line_prefix = "average lambda:" avg_lambda = 0. @@ -44,14 +46,21 @@ def handleOneModel(modelfile): close_fds=True) for line in subprocess.stdout.readlines(): + reporthandle.writelines([line]) #remove trailing '\n' + line = line.decode('utf-8') line = line.rstrip(os.linesep) if line.startswith(result_line_prefix): avg_lambda = float(line[len(result_line_prefix):]) - os.waitpid(subprocess.pid, 0) + reporthandle.close() + + (pid, status) = os.waitpid(subprocess.pid, 0) + if status != 0: + sys.exit('estimate k mixture model returns error.') #end processing + print('average lambda:', avg_lambda) modelfilestatus['EstimateScore'] = avg_lambda utils.sign_epoch(modelfilestatus, 'Estimate') utils.store_status(modelfilestatuspath, modelfilestatus) @@ -63,13 +72,16 @@ def walkThroughModels(path): filepath = os.path.join(root, onefile) if onefile.endswith(config.getModelPostfix()): subpath = os.path.relpath(filepath, path) + reportfile = filepath + config.getReportPostfix() print("Processing " + subpath) - handleOneModel(filepath) + handleOneModel(filepath, reportfile) print("Processed " + subpath) elif onefile.endswith(config.getStatusPostfix()): pass elif onefile.endswith(config.getIndexPostfix()): pass + elif onefile.endswith(config.getReportPostfix()): + pass else: print('Unexpected file:' + filepath) @@ -102,6 +114,8 @@ def gatherModels(path, indexname): pass elif onefile.endswith(config.getIndexPostfix()): pass + elif onefile.endswith(config.getReportPostfix()): + pass else: print('Unexpected file:' + filepath) indexfile.close() |