47 using namespace Eigen;
57 set_inference_method(method);
60 void CGaussianProcessMachine::init()
75 REQUIRE(m_method,
"Inference method should not be NULL\n")
88 feat=m_method->get_features();
91 CKernel* training_kernel=m_method->get_kernel();
95 kernel->
init(feat, data);
102 eigen_Ks*=
CMath::sq(m_method->get_scale());
127 eigen_mu_matrix.block(bl,0,1,m)=(eigen_Ks.adjoint()*eigen_alpha.block(bl*n,0,n,1)+eigen_mean).transpose();
135 REQUIRE(m_method,
"Inference method should not be NULL\n")
139 bool is_sparse=
false;
150 feat=m_method->get_features();
155 CKernel* training_kernel=m_method->get_kernel();
158 kernel->
init(data, data);
165 eigen_Kss_diag*=
CMath::sq(m_method->get_scale());
168 kernel->
init(feat, data);
175 eigen_Ks*=
CMath::sq(m_method->get_scale());
194 if (eigen_L.isUpperTriangular() && !is_sparse)
203 MatrixXd eigen_V=eigen_L.triangularView<Upper>().adjoint().solve(
204 eigen_sW.asDiagonal()*eigen_Ks);
205 MatrixXd eigen_sV=eigen_V.cwiseProduct(eigen_V);
207 eigen_s2=eigen_Kss_diag-eigen_sV.colwise().sum().adjoint();
211 if (m_method->supports_multiclass())
221 for(
index_t bl_i=0; bl_i<C; bl_i++)
224 MatrixXd bi=eigen_E.block(0,bl_i*n,n,n)*eigen_Ks;
225 MatrixXd c_cav=eigen_M.triangularView<Upper>().adjoint().solve(bi);
226 c_cav=eigen_M.triangularView<Upper>().solve(c_cav);
228 for(
index_t bl_j=0; bl_j<C; bl_j++)
230 MatrixXd bj=eigen_E.block(0,bl_j*n,n,n)*eigen_Ks;
231 for (
index_t idx_m=0; idx_m<m; idx_m++)
232 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();
234 for (
index_t idx_m=0; idx_m<m; idx_m++)
235 eigen_s2[bl_i+(bl_i+idx_m*C)*C]+=eigen_Kss_diag(idx_m)-(eigen_Ks.block(0,idx_m,n,1).array()*bi.block(0,idx_m,n,1).array()).sum();
240 SG_ERROR(
"Unsupported inference method!\n");
248 MatrixXd eigen_M=eigen_Ks.cwiseProduct(eigen_L*eigen_Ks);
249 eigen_s2=eigen_Kss_diag+eigen_M.colwise().sum().adjoint();
CGaussianProcessMachine()
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void optimize_inducing_features()
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.
The sparse inference base class for classification and regression for 1-D labels (1D regression and b...
virtual CFeatures * get_inducing_features()
static CKernel * obtain_from_generic(CSGObject *kernel)
all of classes and functions are contained in the shogun namespace
The Inference Method base class.
The class Features is the base class of all feature objects.
SGVector< float64_t > get_kernel_diagonal(SGVector< float64_t > preallocated=SGVector< float64_t >())
virtual ~CGaussianProcessMachine()