def compute_posteriors(self, initial_scores, transition_scores,
                           final_scores, emission_scores):
        '''Compute the state and transition posteriors:
        - The state posteriors are the probability of each state
        occurring at each position given the sequence of observations.
        - The transition posteriors are the joint probability of two states
        in consecutive positions given the sequence of observations.
        Both quantities are computed via the forward-backward algorithm.'''

        length = np.size(emission_scores, 0) # Length of the sequence.
        num_states = np.size(emission_scores, 1) # Number of states.

        # Run the forward algorithm.
        log_likelihood, forward = self.decoder.run_forward(initial_scores,
                                                           transition_scores,
                                                           final_scores,
                                                           emission_scores)

        # Run the backward algorithm.
        log_likelihood, backward = self.decoder.run_backward(initial_scores,
                                                             transition_scores,
                                                             final_scores,
                                                             emission_scores)

        # Multiply the forward and backward variables and divide by the
        # likelihood to obtain the state posteriors (sum/subtract in log-space).
	    # Note that log_likelihood is just a scalar whereas forward, backward
	    # are matrices. Python is smart enough to replicate log_likelihood
        # to form a matrix of the right size. This is called broadcasting.
        state_posteriors = np.zeros([length, num_states]) # State posteriors.
        for pos in xrange(length):
            state_posteriors[pos,:] = forward[pos,:] + backward[pos,:]
            state_posteriors[pos,:] -= log_likelihood

        # Use the forward and backward variables along with the transition
        # and emission scores to obtain the transition posteriors.
        transition_posteriors = np.zeros([1-length, num_states, num_states])
        for pos in xrange(length-1):
            for prev_state in xrange(num_states):
                for state in xrange(num_states):
                    transition_posteriors[pos, state, prev_state] = \
                        forward[pos, prev_state] + \
                        transition_scores[pos, state, prev_state] + \
                        emission_scores[pos+1, state] + \
                        backward[pos+1, state]
                    transition_posteriors[pos, state, prev_state] -= log_likelihood

        state_posteriors = np.exp(state_posteriors)
        transition_posteriors = np.exp(transition_posteriors)

        return state_posteriors, transition_posteriors, log_likelihood
dataset/ETHPy150Open LxMLS/lxmls-toolkit/lxmls/sequences/sequence_classifier.py/SequenceClassifier.compute_posteriors/swapped operands of `-`