def inference(self, kern_r, kern_c, Xr, Xc, Zr, Zc, likelihood, Y, qU_mean ,qU_var_r, qU_var_c, indexD, output_dim):
N, D, Mr, Mc, Qr, Qc = Y.shape[<NUM_LIT:0>], output_dim,Zr.shape[<NUM_LIT:0>], Zc.shape[<NUM_LIT:0>], Zr.shape[<NUM_LIT:1>], Zc.shape[<NUM_LIT:1>]<EOL>uncertain_inputs_r = isinstance(Xr, VariationalPosterior)<EOL>uncertain_inputs_c = isinstance(Xc, VariationalPosterior)<EOL>uncertain_outputs = isinstance(Y, VariationalPosterior)<EOL>grad_dict = self._init_grad_dict(N,D,Mr,Mc)<EOL>beta = <NUM_LIT:1.>/likelihood.variance<EOL>if len(beta)==<NUM_LIT:1>:<EOL><INDENT>beta = np.zeros(D)+beta<EOL><DEDENT>psi0_r, psi1_r, psi2_r = self.gatherPsiStat(kern_r, Xr, Zr, uncertain_inputs_r)<EOL>psi0_c, psi1_c, psi2_c = self.gatherPsiStat(kern_c, Xc, Zc, uncertain_inputs_c)<EOL>Kuu_r = kern_r.K(Zr).copy()<EOL>diag.add(Kuu_r, self.const_jitter)<EOL>Lr = jitchol(Kuu_r)<EOL>Kuu_c = kern_c.K(Zc).copy()<EOL>diag.add(Kuu_c, self.const_jitter)<EOL>Lc = jitchol(Kuu_c)<EOL>mu, Sr, Sc = qU_mean, qU_var_r, qU_var_c<EOL>LSr = jitchol(Sr)<EOL>LSc = jitchol(Sc)<EOL>LcInvMLrInvT = dtrtrs(Lc,dtrtrs(Lr,mu.T)[<NUM_LIT:0>].T)[<NUM_LIT:0>]<EOL>LcInvLSc = dtrtrs(Lc, LSc)[<NUM_LIT:0>]<EOL>LrInvLSr = dtrtrs(Lr, LSr)[<NUM_LIT:0>]<EOL>LcInvScLcInvT = tdot(LcInvLSc)<EOL>LrInvSrLrInvT = tdot(LrInvLSr)<EOL>tr_LrInvSrLrInvT = np.square(LrInvLSr).sum()<EOL>tr_LcInvScLcInvT = np.square(LcInvLSc).sum()<EOL>mid_res = {<EOL>'<STR_LIT>': psi0_r,<EOL>'<STR_LIT>': psi1_r,<EOL>'<STR_LIT>': psi2_r,<EOL>'<STR_LIT>': psi0_c,<EOL>'<STR_LIT>': psi1_c,<EOL>'<STR_LIT>': psi2_c,<EOL>'<STR_LIT>':Lr,<EOL>'<STR_LIT>':Lc,<EOL>'<STR_LIT>': LcInvMLrInvT,<EOL>'<STR_LIT>': LcInvScLcInvT,<EOL>'<STR_LIT>': LrInvSrLrInvT,<EOL>}<EOL>logL = <NUM_LIT:0.><EOL>for d in range(D):<EOL><INDENT>logL += self.inference_d(d, beta, Y, indexD, grad_dict, mid_res, uncertain_inputs_r, uncertain_inputs_c, Mr, Mc)<EOL><DEDENT>logL += -Mc * (np.log(np.diag(Lr)).sum()-np.log(np.diag(LSr)).sum())  -Mr * (np.log(np.diag(Lc)).sum()-np.log(np.diag(LSc)).sum())- np.square(LcInvMLrInvT).sum()/<NUM_LIT> - tr_LrInvSrLrInvT * tr_LcInvScLcInvT/<NUM_LIT> + Mr*Mc/<NUM_LIT><EOL>tmp =  tdot(LcInvMLrInvT)/<NUM_LIT> + tr_LrInvSrLrInvT/<NUM_LIT> * LcInvScLcInvT - Mr/<NUM_LIT>*np.eye(Mc)<EOL>dL_dKuu_c = backsub_both_sides(Lc, tmp, '<STR_LIT:left>')<EOL>dL_dKuu_c += dL_dKuu_c.T<EOL>dL_dKuu_c *= <NUM_LIT:0.5><EOL>tmp =  tdot(LcInvMLrInvT.T)/<NUM_LIT> + tr_LcInvScLcInvT/<NUM_LIT> * LrInvSrLrInvT - Mc/<NUM_LIT>*np.eye(Mr)<EOL>dL_dKuu_r = backsub_both_sides(Lr, tmp, '<STR_LIT:left>')<EOL>dL_dKuu_r += dL_dKuu_r.T<EOL>dL_dKuu_r *= <NUM_LIT:0.5><EOL>tmp = - LcInvMLrInvT<EOL>dL_dqU_mean = dtrtrs(Lc, dtrtrs(Lr, tmp.T, trans=<NUM_LIT:1>)[<NUM_LIT:0>].T, trans=<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>LScInv = dtrtri(LSc)<EOL>tmp = -tr_LrInvSrLrInvT/<NUM_LIT>*np.eye(Mc)<EOL>dL_dqU_var_c = backsub_both_sides(Lc, tmp, '<STR_LIT:left>') + tdot(LScInv.T) * Mr/<NUM_LIT><EOL>LSrInv = dtrtri(LSr)<EOL>tmp =  -tr_LcInvScLcInvT/<NUM_LIT>*np.eye(Mr)<EOL>dL_dqU_var_r = backsub_both_sides(Lr, tmp, '<STR_LIT:left>') + tdot(LSrInv.T) * Mc/<NUM_LIT><EOL>post = PosteriorMultioutput(LcInvMLrInvT=LcInvMLrInvT, LcInvScLcInvT=LcInvScLcInvT,<EOL>LrInvSrLrInvT=LrInvSrLrInvT, Lr=Lr, Lc=Lc, kern_r=kern_r, Xr=Xr, Zr=Zr)<EOL>grad_dict['<STR_LIT>'] += dL_dqU_mean<EOL>grad_dict['<STR_LIT>'] += dL_dqU_var_c<EOL>grad_dict['<STR_LIT>'] += dL_dqU_var_r<EOL>grad_dict['<STR_LIT>'] += dL_dKuu_c<EOL>grad_dict['<STR_LIT>'] += dL_dKuu_r<EOL>if not uncertain_inputs_c:<EOL><INDENT>grad_dict['<STR_LIT>'] = grad_dict['<STR_LIT>']<EOL>grad_dict['<STR_LIT>'] = grad_dict['<STR_LIT>']<EOL><DEDENT>if not uncertain_inputs_r:<EOL><INDENT>grad_dict['<STR_LIT>'] = grad_dict['<STR_LIT>']<EOL>grad_dict['<STR_LIT>'] = grad_dict['<STR_LIT>']<EOL><DEDENT>return post, logL, grad_dict<EOL>
The SVI-VarDTC inference