def predict_sequence(self, X, A, pi, inference='<STR_LIT>'):
obsll = self.predict_proba(X)<EOL>T, S = obsll.shape<EOL>alpha = np.zeros((T, S))<EOL>alpha[<NUM_LIT:0>, :] = pi<EOL>for t in range(<NUM_LIT:1>, T):<EOL><INDENT>alpha[t, :] = np.dot(alpha[t-<NUM_LIT:1>, :], A)<EOL>for s in range(S):<EOL><INDENT>alpha[t, s] *= obsll[t, s]<EOL><DEDENT>alpha[t, :] = alpha[t, :]/sum(alpha[t, :])<EOL><DEDENT>if inference == '<STR_LIT>':<EOL><INDENT>return alpha<EOL><DEDENT>else:<EOL><INDENT>beta = np.zeros((T, S))<EOL>gamma = np.zeros((T, S))<EOL>beta[T-<NUM_LIT:1>, :] = np.ones(S)<EOL>for t in range(T-<NUM_LIT:2>, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>for i in range(S):<EOL><INDENT>for j in range(S):<EOL><INDENT>beta[t, i] += A[i, j]*obsll[t+<NUM_LIT:1>, j]*beta[t+<NUM_LIT:1>, j]<EOL><DEDENT><DEDENT>beta[t, :] = beta[t, :]/sum(beta[t, :])<EOL><DEDENT>for t in range(T):<EOL><INDENT>gamma[t, :] = alpha[t, :]*beta[t, :]<EOL>gamma[t, :] = gamma[t, :]/sum(gamma[t, :])<EOL><DEDENT>return gamma<EOL><DEDENT>
Calculate class probabilities for a sequence of data.

Parameters
----------
X : array
    Test data, of dimension N times d (rows are time frames, columns
    are data dimensions)
A : class transition matrix, where A[i,j] contains p(y_t=j|y_{t-1}=i)
pi : vector of initial class probabilities
inference : can be 'smoothing' or 'filtering'.

Returns:
-------
y_prob : array
    An array of dimension N times n_inlier_classes+1, containing
    the probabilities of each row of X being one of the inlier
    classes, or the outlier class (last column).