'Return the pre-sample predicted values using the Kalman Filter
Notes
See predict method for how to use start and p.'

def _presample_fit(self, params, start, p, end, y, predictedvalues):

    k = self.k_trend
    T_mat = KalmanFilter.T(params, p, k, p)
    R_mat = KalmanFilter.R(params, p, k, 0, p)
    alpha = np.zeros((p, 1))
    Q_0 = dot(inv((identity((p ** 2)) - np.kron(T_mat, T_mat))), dot(R_mat, R_mat.T).ravel('F'))
    Q_0 = Q_0.reshape(p, p, order='F')
    P = Q_0
    Z_mat = KalmanFilter.Z(p)
    for i in range(end):
        v_mat = (y[i] - dot(Z_mat, alpha))
        F_mat = dot(dot(Z_mat, P), Z_mat.T)
        Finv = (1.0 / F_mat)
        K = dot(dot(dot(T_mat, P), Z_mat.T), Finv)
        alpha = (dot(T_mat, alpha) + dot(K, v_mat))
        L = (T_mat - dot(K, Z_mat))
        P = (dot(dot(T_mat, P), L.T) + dot(R_mat, R_mat.T))
        if (i >= (start - 1)):
            predictedvalues[((i + 1) - start)] = dot(Z_mat, alpha)
