<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _raw_predict(self, Xnew=None, Ynew=None, filteronly=False, p_balance=False, **kw):
 """ Performs the actual prediction for new X points. Inner function. It is called only from inside this class. Input: Xnews: vector or (n_points,1) matrix New time points where to evaluate predictions. Ynews: (n_train_points, ts_no) matrix This matrix can substitude the original training points (in order to use only the parameters of the model). filteronly: bool Use only Kalman Filter for prediction. In this case the output does not coincide with corresponding Gaussian process. balance: bool Whether to balance or not the model as a whole Output: m: vector Mean prediction V: vector Variance in every point """


        # Set defaults
        if Ynew is None:
            Ynew = self.Y

        # Make a single matrix containing training and testing points
        if Xnew is not None:
            X = np.vstack((self.X, Xnew))
            Y = np.vstack((Ynew, np.nan*np.zeros(Xnew.shape)))
            predict_only_training = False
        else:
            X = self.X
            Y = Ynew
            predict_only_training = True

        # Sort the matrix (save the order)
        _, return_index, return_inverse = np.unique(X,True,True)
        X = X[return_index] # TODO they are not used
        Y = Y[return_index]

        # Get the model matrices from the kernel
        (F,L,Qc,H,P_inf, P0, dF,dQc,dP_inf,dP0) = self.kern.sde()
        state_dim = F.shape[0]
        
        # Balancing
        if (p_balance==True):
            (F,L,Qc,H,P_inf,P0, dF,dQc,dP_inf,dP0) = ssm.balance_ss_model(F,L,Qc,H,P_inf,P0, dF,dQc,dP_inf, dP0)
            print("SSM _raw_predict balancing!")
            
        #Y = self.Y[:, 0,0]
        # Run the Kalman filter
        #import pdb; pdb.set_trace()
        kalman_filter_type = self.kalman_filter_type

        (M, P, log_likelihood,
         grad_log_likelihood,SmootherMatrObject) = ssm.ContDescrStateSpace.cont_discr_kalman_filter(
                                      F,L,Qc,H,float(self.Gaussian_noise.variance),P_inf,X,Y,m_init=None,
                                      P_init=P0, p_kalman_filter_type = kalman_filter_type,
                                      calc_log_likelihood=False,
                                      calc_grad_log_likelihood=False)

#        (filter_means, filter_covs, log_likelihood,
#         grad_log_likelihood,SmootherMatrObject) = ssm.ContDescrStateSpace.cont_discr_kalman_filter(F,L,Qc,H,
#                                      float(self.Gaussian_noise.variance),P_inf,self.X,self.Y,m_init=None,
#                                      P_init=P0, p_kalman_filter_type = kalman_filter_type, calc_log_likelihood=True,
#                                      calc_grad_log_likelihood=True,
#                                      grad_params_no=grad_params_no,
#                                      grad_calc_params=grad_calc_params)

        # Run the Rauch-Tung-Striebel smoother
        if not filteronly:
            (M, P) = ssm.ContDescrStateSpace.cont_discr_rts_smoother(state_dim, M, P,
                                p_dynamic_callables=SmootherMatrObject, X=X, F=F,L=L,Qc=Qc)

        # remove initial values
        M = M[1:,:,:]
        P = P[1:,:,:]

        # Put the data back in the original order
        M = M[return_inverse,:,:]
        P = P[return_inverse,:,:]

        # Only return the values for Xnew
        if not predict_only_training:
            M = M[self.num_data:,:,:]
            P = P[self.num_data:,:,:]

        # Calculate the mean and variance
        # after einsum m has dimension in 3D (sample_num, dim_no,time_series_no)
        m = np.einsum('ijl,kj', M, H)# np.dot(M,H.T)
        m.shape = (m.shape[0], m.shape[1]) # remove the third dimension

        V = np.einsum('ij,ajk,kl', H, P, H.T)

        V.shape = (V.shape[0], V.shape[1]) # remove the third dimension

        # Return the posterior of the state
        return (m, V)