Skip to content

Commit

Permalink
[msm-model] minor improvements (markovmodel#828)
Browse files Browse the repository at this point in the history
* explicit exception handling (AttributeError)
* pcca: convert argument to int
  • Loading branch information
marscher authored Jun 21, 2016
1 parent 467c961 commit ecee504
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pyemma/msm/models/msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def __init__(self, P, pi=None, reversible=None, dt_model='1 step', neig=None, nc
self.set_model_params(P=P, pi=pi, reversible=reversible, dt_model=dt_model, neig=neig)
self.ncv = ncv



# TODO: maybe rename to parametrize in order to avoid confusion with set_params that has a different behavior?
def set_model_params(self, P=None, pi=None, reversible=None, dt_model='1 step', neig=None):
""" Call to set all basic model parameters.
Expand Down Expand Up @@ -206,8 +204,9 @@ def transition_matrix(self):
"""
try:
return self.P
except:
raise AttributeError('MSM has not yet been parametrized. Call __init__ or set transition matrix')
except AttributeError:
raise AttributeError('MSM has not yet been parametrized.'
'Call "MSM(P)", set_model_params(P=P) or set transition matrix')

################################################################################
# Spectral quantities
Expand Down Expand Up @@ -243,7 +242,7 @@ def _ensure_eigenvalues(self, neig=None):
if m < neig:
# not enough eigenpairs present - recompute:
self._compute_eigenvalues(neig)
except:
except AttributeError:
# no eigendecomposition yet - compute:
self._compute_eigenvalues(neig)

Expand Down Expand Up @@ -278,7 +277,7 @@ def _ensure_eigendecomposition(self, neig=None):
if m < neig:
# not enough eigenpairs present - recompute:
self._compute_eigendecomposition(neig)
except:
except AttributeError:
# no eigendecomposition yet - compute:
self._compute_eigendecomposition(neig)

Expand Down Expand Up @@ -810,7 +809,7 @@ def _assert_metastable(self):
try:
if not self._metastable_computed:
raise ValueError('Metastable decomposition has not yet been computed. Please call pcca(m) first.')
except:
except AttributeError:
raise ValueError('Metastable decomposition has not yet been computed. Please call pcca(m) first.')

def pcca(self, m):
Expand Down Expand Up @@ -847,6 +846,7 @@ def pcca(self, m):
(2): 147-179
"""
m = int(m)
# can we do it?
if not self.reversible:
raise ValueError(
Expand All @@ -859,7 +859,7 @@ def pcca(self, m):
if self._pcca.n_metastable != m:
# incorrect number of states - recompute
self._pcca = PCCA(self.transition_matrix, m)
except:
except AttributeError:
# didn't have a pcca object yet - compute
self._pcca = PCCA(self.transition_matrix, m)

Expand Down

0 comments on commit ecee504

Please sign in to comment.