49 using namespace Eigen;
59 set_inference_method(method);
62 void CGaussianProcessMachine::init()
77 REQUIRE(m_method,
"Inference method should not be NULL\n")
82 if (m_method->get_inference_type()==
INF_FITC)
90 feat=m_method->get_features();
93 CKernel* training_kernel=m_method->get_kernel();
97 kernel->
init(feat, data);
104 eigen_Ks*=
CMath::sq(m_method->get_scale());
129 eigen_mu_matrix.block(bl,0,1,m)=(eigen_Ks.adjoint()*eigen_alpha.block(bl*n,0,n,1)+eigen_mean).transpose();
137 REQUIRE(m_method,
"Inference method should not be NULL\n")
142 if (m_method->get_inference_type()==
INF_FITC)
150 feat=m_method->get_features();
155 CKernel* training_kernel=m_method->get_kernel();
159 kernel->
init(data, data);
166 eigen_Kss*=
CMath::sq(m_method->get_scale());
169 kernel->
init(feat, data);
176 eigen_Ks*=
CMath::sq(m_method->get_scale());
195 if (eigen_L.isUpperTriangular())
205 MatrixXd eigen_V=eigen_L.triangularView<Upper>().adjoint().solve(
206 eigen_sW.asDiagonal()*eigen_Ks);
207 MatrixXd eigen_sV=eigen_V.cwiseProduct(eigen_V);
209 eigen_s2=eigen_Kss.diagonal()-eigen_sV.colwise().sum().adjoint();
213 if (m_method->supports_multiclass())
223 for(
index_t bl_i=0; bl_i<C; bl_i++)
226 MatrixXd bi=eigen_E.block(0,bl_i*n,n,n)*eigen_Ks;
227 MatrixXd c_cav=eigen_M.triangularView<Upper>().adjoint().solve(bi);
228 c_cav=eigen_M.triangularView<Upper>().solve(c_cav);
230 for(
index_t bl_j=0; bl_j<C; bl_j++)
232 MatrixXd bj=eigen_E.block(0,bl_j*n,n,n)*eigen_Ks;
233 for (
index_t idx_m=0; idx_m<m; idx_m++)
234 eigen_s2[bl_j+(bl_i+idx_m*C)*C]=(bj.block(0,idx_m,n,1).array()*c_cav.block(0,idx_m,n,1).array()).
sum();
236 for (
index_t idx_m=0; idx_m<m; idx_m++)
237 eigen_s2[bl_i+(bl_i+idx_m*C)*C]+=eigen_Kss(idx_m,idx_m)-(eigen_Ks.block(0,idx_m,n,1).array()*bi.block(0,idx_m,n,1).array()).
sum();
242 SG_ERROR(
"Unsupported inference method!\n");
250 MatrixXd eigen_M=eigen_Ks.cwiseProduct(eigen_L*eigen_Ks);
251 eigen_s2=eigen_Kss.diagonal()+eigen_M.colwise().sum().adjoint();
CGaussianProcessMachine()
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual CFeatures * get_latent_features()
The Inference Method base class.
virtual CSGObject * clone()
SGVector< float64_t > get_posterior_variances(CFeatures *data)
SGVector< float64_t > get_posterior_means(CFeatures *data)
virtual SGVector< float64_t > get_mean_vector(const CFeatures *features) const =0
An abstract class of the mean function.
SGMatrix< float64_t > get_kernel_matrix()
Class SGObject is the base class of all shogun objects.
Matrix::Scalar sum(Matrix m, bool no_diag=false)
static CKernel * obtain_from_generic(CSGObject *kernel)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
The Fully Independent Conditional Training inference method class.
virtual ~CGaussianProcessMachine()
static CFITCInferenceMethod * obtain_from_generic(CInferenceMethod *inference)