Skip to content

Commit d4be6ba

Browse files
author
Suarez Alvarez
committed
update
1 parent a7c4253 commit d4be6ba

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

nmpath/auxfunctions.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ def num_of_nonzero_elements(my_vector):
8484
return counter
8585

8686

87-
def normalize_markov_matrix(transition_matrix):
87+
def normalize_markov_matrix(transition_matrix, reversible=False):
8888
'''Transform a matrix of positive elements to a markov-like
8989
matrix by divding each row by the sum of the elements of the
9090
row.
9191
'''
9292
t_matrix = np.array(transition_matrix, dtype=np.float64)
93+
if reversible:
94+
t_matrix = t_matrix.T + t_matrix
9395

9496
n_states = len(t_matrix)
9597
assert(n_states == len(t_matrix[0]))
@@ -320,6 +322,46 @@ def pseudo_nm_tmatrix(markovian_tmatrix, stateA, stateB):
320322
check_tmatrix(p_nm_tmatrix) # just in case
321323
return p_nm_tmatrix
322324

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+
323365

324366
if __name__ == '__main__':
325367
import mfpt

nmpath/ensembles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def empirical_mfpts(self, stateA, stateB):
123123
return direct_mfpts(self.trajectories, stateA,
124124
stateB, discrete=self.discrete,
125125
n_variables=self.n_variables,
126-
lag_time=self.lag_time)
126+
lag_time=self._lag_time)
127127

128128
def _count_matrix(self, n_states=None, map_function=None):
129129
if (map_function is None) or (n_states is None):

0 commit comments

Comments
 (0)