@@ -84,12 +84,14 @@ def num_of_nonzero_elements(my_vector):
84
84
return counter
85
85
86
86
87
- def normalize_markov_matrix (transition_matrix ):
87
+ def normalize_markov_matrix (transition_matrix , reversible = False ):
88
88
'''Transform a matrix of positive elements to a markov-like
89
89
matrix by divding each row by the sum of the elements of the
90
90
row.
91
91
'''
92
92
t_matrix = np .array (transition_matrix , dtype = np .float64 )
93
+ if reversible :
94
+ t_matrix = t_matrix .T + t_matrix
93
95
94
96
n_states = len (t_matrix )
95
97
assert (n_states == len (t_matrix [0 ]))
@@ -320,6 +322,46 @@ def pseudo_nm_tmatrix(markovian_tmatrix, stateA, stateB):
320
322
check_tmatrix (p_nm_tmatrix ) # just in case
321
323
return p_nm_tmatrix
322
324
325
+ def confindence_interval_cdf (populations , totCounts , conf_interval = 0.95 , n_samples = 100000 ):
326
+ counts = np .round (np .array (populations )* totCounts )
327
+ partialCounts = sum (counts )
328
+ myarray = list (counts )+ [totCounts - partialCounts ]
329
+ s = np .random .dirichlet (myarray , n_samples )
330
+
331
+ s_cdf = []
332
+
333
+ for line in s :
334
+ s_cdf .append (cdf (line ))
335
+ s_cdf = np .array (s_cdf )
336
+
337
+ s = np .transpose (s )
338
+ s_cdf = np .transpose (s_cdf )
339
+
340
+ minval = []
341
+ maxval = []
342
+ minvalcdf = []
343
+ maxvalcdf = []
344
+
345
+ for line in s :
346
+ sorted_line = np .sort (line )
347
+ minval .append (sorted_line [int ( (1 - conf_interval )/ 2 * len (sorted_line ))])
348
+ maxval .append (sorted_line [int ( (1 - (1 - conf_interval )/ 2 ) * len (sorted_line ))])
349
+
350
+ for line in s_cdf :
351
+ sorted_line = np .sort (line )
352
+ minvalcdf .append (sorted_line [int ( (1 - conf_interval )/ 2 * len (sorted_line ))])
353
+ maxvalcdf .append (sorted_line [int ( (1 - (1 - conf_interval )/ 2 ) * len (sorted_line ))])
354
+
355
+ return minvalcdf [:- 1 ], maxvalcdf [:- 1 ]
356
+
357
+ def cdf (pmf ):
358
+ mycdf = []
359
+ tot = 0
360
+ for element in pmf :
361
+ tot += element
362
+ mycdf .append (tot )
363
+ return np .array (mycdf )
364
+
323
365
324
366
if __name__ == '__main__' :
325
367
import mfpt
0 commit comments