def trajectory_weights(self): r"""Uses the HMSM to assign a probability weight to each trajectory frame. This is a powerful function for the calculation of arbitrary observables in the trajectories one has started the analysis with. The stationary probability of the MSM will be used to reweigh all states. Returns a list of weight arrays, one for each trajectory, and with a number of elements equal to trajectory frames. Given :math:`N` trajectories of lengths :math:`T_1` to :math:`T_N`, this function returns corresponding weights: .. math:: (w_{1,1}, ..., w_{1,T_1}), (w_{N,1}, ..., w_{N,T_N}) that are normalized to one: .. math:: \sum_{i=1}^N \sum_{t=1}^{T_i} w_{i,t} = 1 Suppose you are interested in computing the expectation value of a function :math:`a(x)`, where :math:`x` are your input configurations. Use this function to compute the weights of all input configurations and obtain the estimated expectation by: .. math:: \langle a \rangle = \sum_{i=1}^N \sum_{t=1}^{T_i} w_{i,t} a(x_{i,t}) Or if you are interested in computing the time-lagged correlation between functions :math:`a(x)` and :math:`b(x)` you could do: .. math:: \langle a(t) b(t+\tau) \rangle_t = \sum_{i=1}^N \sum_{t=1}^{T_i} w_{i,t} a(x_{i,t}) a(x_{i,t+\tau}) Returns ------- The normalized trajectory weights. Given :math:`N` trajectories of lengths :math:`T_1` to :math:`T_N`, returns the corresponding weights: .. math:: (w_{1,1}, ..., w_{1,T_1}), (w_{N,1}, ..., w_{N,T_N}) """ # compute stationary distribution, expanded to full set statdist = self.stationary_distribution_obs statdist = _np.append(statdist, [ -1 ]) # add a zero weight at index -1, to deal with unobserved states # histogram observed states import msmtools.dtraj as msmtraj hist = 1.0 * msmtraj.count_states(self.discrete_trajectories_obs, ignore_negative=True) # simply read off stationary distribution and accumulate total weight W = [] wtot = 0.0 for dtraj in self.discrete_trajectories_obs: w = statdist[dtraj] / hist[dtraj] W.append(w) wtot += _np.sum(W) # normalize for w in W: w /= wtot # done return W
def __init__(self, dtrajs): # TODO: extensive input checking! from pyemma.util.types import ensure_dtraj_list # discrete trajectories self._dtrajs = ensure_dtraj_list(dtrajs) ## basic count statistics # histogram from msmtools.dtraj import count_states self._hist = count_states(self._dtrajs, ignore_negative=True) # total counts self._total_count = np.sum(self._hist) # number of states self._nstates = msmest.number_of_states(dtrajs) # not yet estimated self._counted_at_lag = False
def __init__(self, dtrajs): from pyerna.util.types import ensure_dtraj_list # discrete trajectories self._dtrajs = ensure_dtraj_list(dtrajs) # TODO: extensive input checking! if any([np.any(d < -1) for d in self._dtrajs]): raise ValueError('Discrete trajectory contains elements < -1.') ## basic count statistics # histogram from msmtools.dtraj import count_states self._hist = count_states(self._dtrajs, ignore_negative=True) # total counts self._total_count = np.sum(self._hist) # number of states self._nstates = msmest.number_of_states(dtrajs) # not yet estimated self._counted_at_lag = False