def mode_computations(self, f_hat, Ki_f, K, Y, likelihood, kern, Y_metadata):
<EOL>W = -likelihood.d2logpdf_df2(f_hat, Y, Y_metadata=Y_metadata)<EOL>if np.any(np.isnan(W)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>K_Wi_i, logdet_I_KW, I_KW_i, Ki_W_i = self._compute_B_statistics(K, W, likelihood.log_concave)<EOL>log_marginal = -<NUM_LIT:0.5>*np.sum(np.dot(Ki_f.T, f_hat)) + np.sum(likelihood.logpdf(f_hat, Y, Y_metadata=Y_metadata)) - <NUM_LIT:0.5>*logdet_I_KW<EOL>dW_df = -likelihood.d3logpdf_df3(f_hat, Y, Y_metadata=Y_metadata) <EOL>if np.any(np.isnan(dW_df)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>dL_dfhat = -<NUM_LIT:0.5>*(np.diag(Ki_W_i)[:, None]*dW_df) <EOL>I_KW_i = np.eye(Y.shape[<NUM_LIT:0>]) - np.dot(K, K_Wi_i)<EOL>if kern.size > <NUM_LIT:0> and not kern.is_fixed:<EOL><INDENT>explicit_part = <NUM_LIT:0.5>*(np.dot(Ki_f, Ki_f.T) - K_Wi_i)<EOL>implicit_part = np.dot(Ki_f, dL_dfhat.T).dot(I_KW_i)<EOL>dL_dK = explicit_part + implicit_part<EOL><DEDENT>else:<EOL><INDENT>dL_dK = np.zeros(likelihood.size)<EOL><DEDENT>if likelihood.size > <NUM_LIT:0> and not likelihood.is_fixed:<EOL><INDENT>dlik_dthetaL, dlik_grad_dthetaL, dlik_hess_dthetaL = likelihood._laplace_gradients(f_hat, Y, Y_metadata=Y_metadata)<EOL>num_params = likelihood.size<EOL>dL_dthetaL = np.zeros(num_params)<EOL>for thetaL_i in range(num_params):<EOL><INDENT>dL_dthetaL_exp = ( np.sum(dlik_dthetaL[thetaL_i,:, :])<EOL>+ <NUM_LIT:0.5>*np.sum(np.diag(Ki_W_i)*np.squeeze(dlik_hess_dthetaL[thetaL_i, :, :]))<EOL>)<EOL>dfhat_dthetaL = mdot(I_KW_i, K, dlik_grad_dthetaL[thetaL_i, :, :])<EOL>dL_dthetaL_imp = np.dot(dL_dfhat.T, dfhat_dthetaL)<EOL>dL_dthetaL[thetaL_i] = np.sum(dL_dthetaL_exp + dL_dthetaL_imp)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dL_dthetaL = np.zeros(likelihood.size)<EOL><DEDENT>self.Ki_W_i = Ki_W_i<EOL>self.K = K<EOL>self.W = W<EOL>self.f_hat = f_hat<EOL>return log_marginal, K_Wi_i, dL_dK, dL_dthetaL<EOL>
At the mode, compute the hessian and effective covariance matrix.

returns: logZ : approximation to the marginal likelihood
         woodbury_inv : variable required for calculating the approximation to the covariance matrix
         dL_dthetaL : array of derivatives (1 x num_kernel_params)
         dL_dthetaL : array of derivatives (1 x num_likelihood_params)