3 """@namespace IMP.isd.History
4 Classes to store output from replicas.
7 from __future__
import print_function
14 """Class that contains the output of one replica, used by the
18 def __init__(self, filename):
19 self.filename = filename
22 def create_category(self, name):
25 def create_entry(self, cat, name):
26 if not cat
in self.data:
27 self.create_category(cat)
28 self.data[cat][name] = []
30 def add_data(self, cat, name, data):
31 self.data[cat][name].append(data)
34 """checks if all entries have same length and are of constant type"""
38 for name
in self.data[cat]:
40 goodlen = len(self.data[cat][name])
41 if len(self.data[cat][name]) != goodlen:
42 print(
"category %s entry %s : length %s expected, got %s"\
43 % (cat, name, goodlen, len(self.data[cat][name])))
45 goodtype = type(self.data[cat][name][0])
46 for ent
in self.data[cat][name]:
47 if not isinstance(ent, goodtype):
48 print(
"category %s entry %s : %s expected, got %s"\
49 % (cat, name, goodtype, type(ent)))
52 def get_data(self, cat, name):
53 return self.data[cat][name]
55 def get_categories(self):
56 i = sorted(self.data.keys())
62 def get_entries(self, cat):
63 i = sorted(self.data[cat].keys())
71 for name
in self.data[cat]:
72 self.data[cat][name] = [i
for i
in self.data[cat][name]
75 def toc(self, out=sys.stdout):
76 """print the "table of contents" of this History
77 tendency is a comparison of the last 200 frames, and whether it goes up
79 mean100 is the average over the last 100 frames
81 if not isinstance(out, file):
84 "category\tkey_name\tn_frames\ttype\taverage\tstd\tmean100\ttendency\n")
87 for name
in self.data[cat]:
88 ent = self.data[cat][name]
96 ent = numpy.array(ent)
98 avg100 = numpy.mean(ent[-100:])
99 avg200 = numpy.mean(ent[-200:-100])
101 st200 = numpy.std(ent[-200])
102 if st200 == 0
or abs(avg200 - avg100) / st200 > 3:
110 "\t%20s\t%12d\t%20s\t%10f\t%10f\t%10f\t%5s\n" %
111 (name, len(ent), tp, avg, st, avg100, tend))
115 out.write(
"\t%20s\t%12d\t%20s\n" % (name, len(ent), tp))
def sanity_check
checks if all entries have same length and are of constant type
def toc
print the "table of contents" of this History tendency is a comparison of the last 200 frames...
Class that contains the output of one replica, used by the Analysis class.