1 """@namespace IMP.spatiotemporal.analysis
2 Functions to analyze spatiotemporal models.
8 output_fn=
'temporal_precision.txt'):
10 Function that reads in two labeled_pdfs from create_DAG and returns the
11 temporal_precision, defined as the probability overlap between two
14 @param labeled_pdf1_fn: string, labeled pdf file name (including the path);
15 labeled_pdf from one independent sampling
16 @param labeled_pdf2_fn: string, labeled pdf file name (including the path);
17 labeled_pdf from another independent sampling
18 @param output_fn: string, name of output file
19 (default: 'temporal_precision.txt')
20 @return temporal precision, written to output_fn
22 pdf_files = [labeled_pdf1_fn, labeled_pdf2_fn]
24 for pdf_file
in pdf_files:
28 old = open(pdf_file,
'r')
33 line_split = line.split()
36 if len(line_split) > 1:
38 if line_split[0] ==
'#':
42 prob = float(line_split[1])
48 dict_list.append(prob_dict)
50 key_list = dict_list[0].keys()
51 key_list2 = dict_list[1].keys()
53 if len(key_list) == 0
or len(key_list2) == 0:
54 raise Exception(
'Error reading labeled_pdf!!! Keys not found')
60 precision -= 0.5 * np.abs(dict_list[0][key] - dict_list[1][key])
64 precision -= 0.5 * np.abs(dict_list[1][key])
71 precision -= 0.5 * np.abs(dict_list[0][key])
72 with open(output_fn,
'w')
as new:
73 new.write(
'Temporal precision between ' + labeled_pdf1_fn +
' and '
74 + labeled_pdf2_fn +
':\n')
75 new.write(str(precision))
76 print(
'Temporal precision between ' + labeled_pdf1_fn +
' and '
77 + labeled_pdf2_fn +
':')
81 def purity(labeled_pdf_fn, output_fn='purity.txt'):
83 Function that reads in one labeled_pdf from create_DAG and returns the
84 purity, defined as the sum of the squared probability of all trajectories.
86 @param labeled_pdf_fn: string, labeled pdf file name (including the path);
87 labeled_pdf from the total model
88 @param output_fn: string, name of output file
89 (default: 'temporal_precision.txt')
90 @return temporal purity, written to output_fn
95 old = open(labeled_pdf_fn,
'r')
100 line_split = line.split()
103 if len(line_split) > 1:
105 if line_split[0] ==
'#':
108 prob = float(line_split[1])
110 prob_list.append(prob)
111 line = old.readline()
114 for prob
in prob_list:
116 with open(output_fn,
'w')
as new:
117 new.write(
'Purity of ' + labeled_pdf_fn +
':\n')
119 print(
'Purity of ' + labeled_pdf_fn)
def purity
Function that reads in one labeled_pdf from create_DAG and returns the purity, defined as the sum of ...
def temporal_precision
Function that reads in two labeled_pdfs from create_DAG and returns the temporal_precision, defined as the probability overlap between two pathway models.
The general base class for IMP exceptions.