test
[ws10smt.git] / compound-split / lattice-stats.py
blob424c2bfe41036e309043717473b592b518e36102
1 #!/usr/bin/python
3 import sys
4 import optparse
5 from heapq import heappush, heappop
6 import math
8 lc = 0
9 maxdepth = -1
10 total_depth = 0
11 total_cols = 0
12 total_paths = 0.0
14 optparser = optparse.OptionParser()
15 optparser.add_option("-k", "--k-best", dest="k", type='int', help="number of best paths", default=1)
16 (opts,args) = optparser.parse_args()
17 n = opts.k
19 if len(args)==0: args=(sys.stdin)
21 for fname in args:
22 if (type(fname) == type('')):
23 f = open(fname, "r")
24 else:
25 f = fname
26 lc = 0
27 nodes = 0
28 for line in f:
29 lc+=1
30 cn = eval(line)
31 if (len(cn[0]) == 0):
32 continue
34 paths = 1.0
35 for col in cn:
36 depth=len(col)
37 paths*=float(depth)
38 nodes += depth
39 total_depth += depth
40 total_cols += 1
41 total_paths+=paths
42 avg=float(total_depth)/float(lc)
43 print "averagePaths=%g" % (total_paths / float(lc))
44 print "averageNodes=%f" % (float(total_depth) / float(lc))
45 print "totalPaths=%f" % (float(total_depth))
46 print "Nodes/Len=%f" % (float(total_depth)/float(total_cols))
47 print "averageLen=%f" % (float(total_cols) / float(lc))