25 using namespace Eigen;
40 void CFITCInferenceMethod::init()
42 SG_ADD((
CSGObject**)&m_latent_features,
"latent_features",
"Latent features",
45 m_latent_features=NULL;
60 SG_SERROR(
"Provided inference is not of type CFITCInferenceMethod!\n")
84 "FITC inference method can only use Gaussian likelihood function\n")
86 "of CRegressionLabels\n")
87 REQUIRE(m_latent_features,
"Latent features should not be NULL\n")
89 "Number of latent features must be greater than zero\n")
123 float64_t result=eigen_chol_utr.diagonal().array().log().sum()+
124 (eigen_dg.array().log().sum()+eigen_r.dot(eigen_r)-eigen_be.dot(eigen_be)+
187 LLT<MatrixXd> Luu(eigen_kuu*
CMath::sq(
m_scale)+m_ind_noise*MatrixXd::Identity(
195 eigen_chol_uu=Luu.matrixU();
198 MatrixXd V=eigen_chol_uu.triangularView<Upper>().adjoint().solve(eigen_ktru*
207 VectorXd::Ones(m_dg.
vlen)-(V.cwiseProduct(V)).colwise().sum().adjoint();
210 LLT<MatrixXd> Lu(V*((VectorXd::Ones(m_dg.
vlen)).cwiseQuotient(eigen_dg)).asDiagonal()*
216 Map<MatrixXd> eigen_chol_utr(m_chol_utr.matrix, m_chol_utr.num_rows,
217 m_chol_utr.num_cols);
218 eigen_chol_utr=Lu.matrixU();
227 VectorXd sqrt_dg=eigen_dg.array().sqrt();
233 eigen_r=(eigen_y-eigen_m).cwiseQuotient(sqrt_dg);
238 eigen_be=eigen_chol_utr.triangularView<Upper>().adjoint().solve(
239 V*eigen_r.cwiseQuotient(sqrt_dg));
245 MatrixXd eigen_prod=eigen_chol_utr*eigen_chol_uu;
249 eigen_chol=eigen_prod.triangularView<Upper>().adjoint().solve(
251 eigen_chol=eigen_prod.triangularView<Upper>().solve(eigen_chol)-iKuu;
267 eigen_alpha=eigen_chol_utr.triangularView<Upper>().solve(eigen_be);
268 eigen_alpha=eigen_chol_uu.triangularView<Upper>().solve(eigen_alpha);
291 MatrixXd V=eigen_Luu.triangularView<Upper>().adjoint().solve(eigen_Ktru*
299 eigen_al=((eigen_y-eigen_m)-(V.adjoint()*
300 eigen_Lu.triangularView<Upper>().solve(eigen_be))).cwiseQuotient(eigen_dg);
303 MatrixXd iKuu=eigen_Luu.triangularView<Upper>().adjoint().solve(
305 iKuu=eigen_Luu.triangularView<Upper>().solve(iKuu);
317 eigen_w=eigen_B*eigen_al;
324 eigen_W=eigen_Lu.triangularView<Upper>().adjoint().solve(V*VectorXd::Ones(
325 m_dg.
vlen).cwiseQuotient(eigen_dg).asDiagonal());
331 REQUIRE(!strcmp(param->
m_name,
"scale"),
"Can't compute derivative of "
332 "the nagative log marginal likelihood wrt %s.%s parameter\n",
361 VectorXd v=ddiagKi-R.cwiseProduct(eigen_B).colwise().sum().adjoint();
367 result[0]=(ddiagKi.dot(VectorXd::Ones(m_dg.
vlen).cwiseQuotient(eigen_dg))+
368 eigen_w.dot(dKuui*eigen_w-2*(dKui*eigen_al))-
369 eigen_al.dot(v.cwiseProduct(eigen_al))-
370 eigen_W.cwiseProduct(eigen_W).colwise().sum().dot(v)-
371 (R*eigen_W.adjoint()).cwiseProduct(eigen_B*eigen_W.adjoint()).
sum())/2.0;
379 REQUIRE(!strcmp(param->
m_name,
"sigma"),
"Can't compute derivative of "
380 "the nagative log marginal likelihood wrt %s.%s parameter\n",
397 result[0]=
CMath::sq(sigma)*(VectorXd::Ones(m_dg.
vlen).cwiseQuotient(
398 eigen_dg).sum()-eigen_W.cwiseProduct(eigen_W).sum()-eigen_al.dot(eigen_al));
402 VectorXd v=-R.cwiseProduct(eigen_B).colwise().sum().adjoint();
404 result[0]=result[0]+((eigen_w.dot(dKuui*eigen_w))-eigen_al.dot(
405 v.cwiseProduct(eigen_al))-eigen_W.cwiseProduct(eigen_W).colwise().sum().dot(v)-
406 (R*eigen_W.adjoint()).cwiseProduct(eigen_B*eigen_W.adjoint()).
sum())/2.0;
427 "Length of the parameter %s should not be NULL\n", param->
m_name)
479 VectorXd v=ddiagKi-R.cwiseProduct(eigen_B).colwise().sum().adjoint();
483 result[i]=(ddiagKi.dot(VectorXd::Ones(m_dg.
vlen).cwiseQuotient(eigen_dg))+
484 eigen_w.dot(dKuui*eigen_w-2*(dKui*eigen_al))-
485 eigen_al.dot(v.cwiseProduct(eigen_al))-
486 eigen_W.cwiseProduct(eigen_W).colwise().sum().dot(v)-
487 (R*eigen_W.adjoint()).cwiseProduct(eigen_B*eigen_W.adjoint()).
sum())/2.0;
505 "Length of the parameter %s should not be NULL\n", param->
m_name)
526 result[i]=-eigen_dmu.dot(eigen_al);
virtual const char * get_name() const =0
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void update_alpha()
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)
virtual ELabelType get_label_type() const =0
virtual void update_parameter_hash()
Class that models Gaussian likelihood.
Real Labels are real-valued labels.
SGVector< float64_t > m_alpha
The Inference Method base class.
virtual void update_chol()
virtual SGVector< float64_t > get_diagonal_vector()
The class Labels models labels, i.e. class assignments of objects.
real valued labels (e.g. for regression, classifier outputs)
virtual void update_train_kernel()
virtual ~CFITCInferenceMethod()
virtual const char * get_name() const
virtual ELikelihoodModelType get_model_type() const
virtual int32_t get_num_vectors() const =0
virtual SGMatrix< float64_t > get_cholesky()
#define SG_NOTIMPLEMENTED
virtual SGVector< float64_t > get_posterior_mean()
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()
virtual float64_t get_negative_log_marginal_likelihood()
virtual void check_members() const
SGMatrix< float64_t > m_L
Class SGObject is the base class of all shogun objects.
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)
Matrix::Scalar sum(Matrix m, bool no_diag=false)
virtual void update_train_kernel()
static void fill_vector(T *vec, int32_t len, T value)
static CGaussianLikelihood * obtain_from_generic(CLikelihoodModel *lik)
virtual SGVector< float64_t > get_parameter_derivative(const CFeatures *features, const TParameter *param, index_t index=-1)
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 SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)
virtual SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
static float64_t log(float64_t v)
virtual void set_latent_features(CFeatures *feat)
virtual void check_members() const
virtual void update_deriv()
virtual EInferenceType get_inference_type() const
SGVector< T > get_diagonal_vector() const
virtual SGVector< float64_t > get_derivative_wrt_mean(const TParameter *param)
virtual SGVector< float64_t > get_alpha()
virtual bool parameter_hash_changed()
The Likelihood model base class.
SGMatrix< float64_t > m_ktrtr
CLikelihoodModel * m_model
virtual SGMatrix< float64_t > get_posterior_covariance()
static CFITCInferenceMethod * obtain_from_generic(CInferenceMethod *inference)
static const float64_t PI