Predict samples on actual data.

        The result of this function is used for calculating the residuals.

        Parameters
        ----------
        data : array, shape (trials, channels, samples) or (channels, samples)
            Epoched or continuous data set.

        Returns
        -------
        predicted : array, shape `data`.shape
            Data as predicted by the VAR model.

        Notes
        -----
        Residuals are obtained by r = x - var.predict(x)

def predict(self, data):
        """Predict samples on actual data.

        The result of this function is used for calculating the residuals.

        Parameters
        ----------
        data : array, shape (trials, channels, samples) or (channels, samples)
            Epoched or continuous data set.

        Returns
        -------
        predicted : array, shape `data`.shape
            Data as predicted by the VAR model.

        Notes
        -----
        Residuals are obtained by r = x - var.predict(x)
        """
        data = atleast_3d(data)
        t, m, l = data.shape

        p = int(np.shape(self.coef)[1] / m)

        y = np.zeros(data.shape)
        if t > l - p:  # which takes less loop iterations
            for k in range(1, p + 1):
                bp = self.coef[:, (k - 1)::p]
                for n in range(p, l):
                    y[:, :, n] += np.dot(data[:, :, n - k], bp.T)
        else:
            for k in range(1, p + 1):
                bp = self.coef[:, (k - 1)::p]
                for s in range(t):
                    y[s, :, p:] += np.dot(bp, data[s, :, (p - k):(l - k)])

        return y