def check_consecutive(self, consecutive):

        decoded = viterbi_decoding(self.emission, self.transition,
                                   consecutive=consecutive)

        changeStatesAt = [-1] + list(np.where(np.diff(decoded) != 0)[0])
        lengths = np.diff(changeStatesAt)
        assert np.min(lengths) >= consecutive
    def check_constraint_mandatory(self, ratio):

        T, K = self.emission.shape

        constraint = VITERBI_CONSTRAINT_NONE * np.ones((T, K), dtype=int)

        N = int(ratio * T)
        Ts = np.random.choice(T, size=N, replace=False)
        Ks = np.random.randint(K, size=N)
        for t, k in itertools.izip(Ts, Ks):
            constraint[t, k] = VITERBI_CONSTRAINT_MANDATORY

        decoded = viterbi_decoding(self.emission, self.transition,
                                   constraint=constraint)

        for i in range(N):
            assert decoded[Ts[i]] == Ks[i]
    def test_simple(self):

        decoded = viterbi_decoding(self.emission, self.transition)
        errors = np.sum(decoded != self.states)
        assert float(errors) / len(self.states) < 0.2