diff options
author | Chris Dyer <redpony@gmail.com> | 2009-12-07 16:53:07 -0500 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2009-12-07 16:53:07 -0500 |
commit | 289bff46b5695c89786ae5dc823479af9d9e7272 (patch) | |
tree | ad2b59b7e3e4e9c6362d5c5b71c6ec6d4fdf2368 /compound-split/lattice-stats.py | |
parent | 476d09e1df52cba0be8e5f50d52bf5f32795288f (diff) |
add compound splitter
Diffstat (limited to 'compound-split/lattice-stats.py')
-rwxr-xr-x | compound-split/lattice-stats.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/compound-split/lattice-stats.py b/compound-split/lattice-stats.py new file mode 100755 index 00000000..8b6ea608 --- /dev/null +++ b/compound-split/lattice-stats.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import sys +import optparse +from heapq import heappush, heappop +import math + +lc = 0 +maxdepth = -1 +total_depth = 0 +total_cols = 0 +total_paths = 0.0 + +optparser = optparse.OptionParser() +optparser.add_option("-k", "--k-best", dest="k", type='int', help="number of best paths", default=1) +(opts,args) = optparser.parse_args() +n = opts.k + +if len(args)==0: args=(sys.stdin) + +for fname in args: + if (type(fname) == type('')): + f = open(fname, "r") + else: + f = fname + lc = 0 + nodes = 0 + for line in f: + lc+=1 + cn = eval(line) + if (len(cn[0]) == 0): + continue + + paths = 1.0 + for col in cn: + depth=len(col) + paths*=float(depth) + nodes += depth + total_depth += depth + total_cols += 1 + total_paths+=paths + avg=float(total_depth)/float(lc) + print "averagePaths=%g" % (total_paths / float(lc)) + print "averageNodes=%f" % (float(total_depth) / float(lc)) + print "averageLen=%f" % (float(total_cols) / float(lc)) + print "Nodes/Len=%f" % (float(total_depth)/float(total_cols)) |