summaryrefslogtreecommitdiff
path: root/compound-split/lattice-stats.py
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-22 05:12:27 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-22 05:12:27 +0000
commit7cc92b65a3185aa242088d830e166e495674efc9 (patch)
tree681fe5237612a4e96ce36fb9fabef00042c8ee61 /compound-split/lattice-stats.py
parent37728b8be4d0b3df9da81fdda2198ff55b4b2d91 (diff)
initial checkin
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@2 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'compound-split/lattice-stats.py')
-rwxr-xr-xcompound-split/lattice-stats.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/compound-split/lattice-stats.py b/compound-split/lattice-stats.py
new file mode 100755
index 00000000..424c2bfe
--- /dev/null
+++ b/compound-split/lattice-stats.py
@@ -0,0 +1,47 @@
+#!/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 "totalPaths=%f" % (float(total_depth))
+ print "Nodes/Len=%f" % (float(total_depth)/float(total_cols))
+ print "averageLen=%f" % (float(total_cols) / float(lc))