Пример #1
0
    def hmm(self, nstates):
        """Estimates a hidden Markov state model as described in [1]_

        Returns
        -------
        hmsm : :class:`MaximumLikelihoodHMSM`

        References
        ----------
        .. [1] F. Noe, H. Wu, J.-H. Prinz and N. Plattner:
            Projected and hidden Markov models for calculating kinetics and metastable states of complex molecules
            J. Chem. Phys. 139, 184114 (2013)

        """
        self._check_is_estimated()
        # run estimate
        from pyemma.msm.estimators.maximum_likelihood_hmsm import MaximumLikelihoodHMSM
        estimator = MaximumLikelihoodHMSM(lag=self.lagtime,
                                          nstates=nstates,
                                          msm_init=self,
                                          reversible=self.is_reversible,
                                          connectivity=self.connectivity,
                                          observe_active=True,
                                          dt_traj=self.dt_traj)
        estimator.estimate(self.discrete_trajectories_full)
        return estimator.model
Пример #2
0
    def submodel(self, states=None, obs=None, mincount_connectivity='1/n'):
        # call submodel on MaximumLikelihoodHMSM
        _MaximumLikelihoodHMSM.submodel(self, states=states, obs=obs, mincount_connectivity=mincount_connectivity)
        # if samples set, also reduce them
        if hasattr(self, 'samples') and self.samples is not None:
            subsamples = [sample.submodel(states=self.active_set, obs=self.observable_set)
                          for sample in self.samples]
            self.update_model_params(samples=subsamples)

        # return
        return self
Пример #3
0
    def hmm(self, nhidden):
        """Estimates a hidden Markov state model as described in [1]_

        Parameters
        ----------
        nhidden : int
            number of hidden (metastable) states

        Returns
        -------
        hmsm : :class:`MaximumLikelihoodHMSM`

        References
        ----------
        .. [1] F. Noe, H. Wu, J.-H. Prinz and N. Plattner:
            Projected and hidden Markov models for calculating kinetics and metastable states of complex molecules
            J. Chem. Phys. 139, 184114 (2013)

        """
        self._check_is_estimated()
        # check if the time-scale separation is OK
        # if hmm.nstates = msm.nstates there is no problem. Otherwise, check spectral gap
        if self.nstates > nhidden:
            timescale_ratios = self.timescales()[:-1] / self.timescales()[1:]
            if timescale_ratios[nhidden - 2] < 1.5:
                self.logger.warning(
                    'Requested coarse-grained model with {nhidden} metastable states at lag={lag}.'
                    ' The ratio of relaxation timescales between'
                    ' {nhidden} and {nhidden_1} states is only {ratio}'
                    ' while we recommend at least 1.5.'
                    ' It is possible that the resulting HMM is inaccurate. Handle with caution.'
                    .format(
                        lag=self.lag,
                        nhidden=nhidden,
                        nhidden_1=nhidden + 1,
                        ratio=timescale_ratios[nhidden - 2],
                    ))
        # run HMM estimate
        from pyemma.msm.estimators.maximum_likelihood_hmsm import MaximumLikelihoodHMSM
        estimator = MaximumLikelihoodHMSM(lag=self.lagtime,
                                          nstates=nhidden,
                                          msm_init=self,
                                          reversible=self.is_reversible,
                                          dt_traj=self.dt_traj)
        estimator.estimate(self.discrete_trajectories_full)
        return estimator.model