Skip to content

Commit 1611b57

Browse files
authored
Merge pull request #120 from marscher/rdl_discard_imag_for_reversible_input
[analyis/RDL] discard imaginary part for reversible input/norm
2 parents ad47bc4 + 1093c44 commit 1611b57

File tree

11 files changed

+19
-9
lines changed

11 files changed

+19
-9
lines changed

msmtools/analysis/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def mfpt(T, target, origin=None, tau=1, mu=None):
718718

719719

720720
def hitting_probability(T, target):
721-
"""
721+
r"""
722722
Computes the hitting probabilities for all states to the target states.
723723
724724
The hitting probability of state i to the target set A is defined as the minimal,
@@ -732,7 +732,7 @@ def hitting_probability(T, target):
732732
----------
733733
T : (M, M) ndarray or scipy.sparse matrix
734734
Transition matrix
735-
B : array_like
735+
target: array_like
736736
List of integer state labels for the target set
737737
738738
Returns

msmtools/analysis/dense/decomposition.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def eigenvalues(T, k=None, reversible=False, mu=None):
7474
if reversible:
7575
try:
7676
evals = eigenvalues_rev(T, k=k, mu=mu)
77-
except:
77+
except ValueError:
7878
evals = eigvals(T).real # use fallback code but cast to real
7979
else:
8080
evals = eigvals(T) # nonreversible
@@ -314,6 +314,9 @@ def rdl_decomposition(T, k=None, reversible=False, norm='standard', mu=None):
314314
else:
315315
R, D, L = rdl_decomposition_nrev(T, norm=norm)
316316

317+
if reversible or norm == 'reversible':
318+
D = D.real
319+
317320
if k is None:
318321
return R, D, L
319322
else:

msmtools/analysis/sparse/decomposition.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,13 @@ def rdl_decomposition(T, k=None, norm='auto', ncv=None, reversible=False, mu=Non
296296
else:
297297
norm = 'standard'
298298
if reversible:
299-
return rdl_decomposition_rev(T, k, norm=norm, ncv=ncv, mu=mu)
299+
R, D, L = rdl_decomposition_rev(T, k, norm=norm, ncv=ncv, mu=mu)
300300
else:
301-
return rdl_decomposition_nrev(T, k, norm=norm, ncv=ncv)
301+
R, D, L = rdl_decomposition_nrev(T, k, norm=norm, ncv=ncv)
302+
303+
if reversible or norm == 'reversible':
304+
D = D.real
305+
return R, D, L
302306

303307

304308
def rdl_decomposition_nrev(T, k, norm='standard', ncv=None):

msmtools/estimation/dense/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
from . import transition_matrix
2222
from . import covariance
2323

24-
#from .mle import mle_trev, mle_trev_given_pi
24+
from .mle import mle_trev, mle_trev_given_pi
2525
from .tmat_sampling import tmatrix_sampler

msmtools/estimation/dense/tmat_sampling/tmatrix_sampler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def __init__(self, C, reversible=False, mu=None, P0=None, nsteps=1, prior='spars
6262
nsteps = 1 # just force to 1, because this is independent sampling
6363
self.sampler = SamplerNonRev(C-1.0)
6464
else:
65-
msg = "Non reversible sampling with fixed stationary vector not implemented"
66-
raise ValueError(msg)
65+
raise ValueError('Non reversible sampling with fixed stationary vector not implemented')
6766

6867
# remember number of steps to decorrelate between samples
6968
self.nsteps = nsteps

msmtools/estimation/sparse/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
from . import likelihood
2929
from . import transition_matrix
3030
from . import prior
31+
32+
from .mle import mle_trev, mle_trev_given_pi

tests/analysis/test_decomposition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from msmtools.util.exceptions import SpectralWarning, ImaginaryEigenValueWarning
3333
from msmtools.util.birth_death_chain import BirthDeathChain
3434

35-
from msmtools.analysis import stationary_distribution, eigenvalues, eigenvectors
35+
from msmtools.analysis import stationary_distribution, eigenvalues, eigenvectors, is_reversible
3636
from msmtools.analysis import rdl_decomposition, timescales
3737

3838
################################################################################
@@ -162,6 +162,7 @@ def test_eigenvectors_reversible(self):
162162

163163
def test_rdl_decomposition(self):
164164
P = self.bdc.transition_matrix()
165+
assert is_reversible(P)
165166
mu = self.bdc.stationary_distribution()
166167

167168
"""Non-reversible"""
@@ -194,6 +195,7 @@ def test_rdl_decomposition(self):
194195

195196
"""k=None"""
196197
Rn, Dn, Ln = rdl_decomposition(P, norm='reversible')
198+
assert Dn.dtype in (np.float32, np.float64)
197199
Xn = np.dot(Ln, Rn)
198200
"""Right-eigenvectors"""
199201
assert_allclose(np.dot(P, Rn), np.dot(Rn, Dn))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)