Ejemplo n.º 1
0
    def fit(self, data, callback: Callable = None):
        """
        Performs the estimation on either a count matrix or a previously estimated TransitionCountModel.

        Parameters
        ----------
        data : (N,N) count matrix or TransitionCountModel or MaximumLikelihoodMSM or MarkovStateModel
            a count matrix or a transition count model that was estimated from data

        callback: callable, optional, default=None
            Function to be called to indicate progress of sampling.

        Returns
        -------
        self : BayesianMSM
            Reference to self.
        """
        from deeptime.markov import TransitionCountModel
        if isinstance(data, TransitionCountModel) and data.counting_mode is not None \
                and "effective" not in data.counting_mode:
            raise ValueError(
                "The transition count model was not estimated using an effective counting method, "
                "therefore counts are likely to be strongly correlated yielding wrong confidences."
            )

        if isinstance(data, Estimator):
            if data.has_model:
                data = data.fetch_model()
            else:
                raise ValueError(
                    "Can only use estimators as input if they have been fit previously."
                )

        if isinstance(data, TransitionCountModel) or is_square_matrix(data):
            msm = MaximumLikelihoodMSM(
                reversible=self.reversible,
                stationary_distribution_constraint=self.
                stationary_distribution_constraint,
                sparse=self.sparse,
                maxiter=self.maxiter,
                maxerr=self.maxerr).fit(data).fetch_model()
        elif isinstance(data, MarkovStateModel):
            msm = data
        else:
            raise ValueError(
                "Unsupported input data, can only be count matrix (or TransitionCountModel, "
                "TransitionCountEstimator) or a MarkovStateModel instance or an estimator producing "
                "Markov state models.")

        return self.fit_from_msm(msm, callback=callback)
Ejemplo n.º 2
0
def test_is_square_matrix():
    assert_(is_square_matrix(np.ones((5, 5))))
    assert_(not is_square_matrix(np.ones((3, 5))))