49 using namespace Eigen;
66 void CKLCholeskyInferenceMethod::init()
69 "The Cholesky represention of the variational co-variance matrix",
71 SG_ADD(&m_InvK_C,
"invK_C",
72 " The K^{-1}C matrix",
83 SG_SERROR(
"Provided inference is not of type CKLCholeskyInferenceMethod!\n")
107 eigen_result=eigen_alpha;
131 eigen_s2=(eigen_C.array()*eigen_C.array()).rowwise().sum().matrix();
146 "The length of gradients (%d) should the same as the length of parameters (%d)\n",
179 eigen_tmp.block(offset, 0, len-i, 1)=VectorXd::Map(eigen_dv.data()+i, len-i);
184 eigen_dnlz_C_seq=(-2.0*(eigen_C_seq.array()*eigen_tmp.array())).matrix();
186 get_lower_triangular_vector(m_InvK_C, tmp);
187 eigen_dnlz_C_seq+=eigen_tmp;
191 eigen_tmp2=(1.0/eigen_C.diagonal().array()).matrix();
196 eigen_dnlz_C_seq.block(offset,0,1,1)-=VectorXd::Map(eigen_tmp2.data()+i,1);
217 float64_t trace=(eigen_InvK_C.array()*eigen_C.array()).sum();
220 float64_t result=-a+0.5*(-eigen_K.rows()+eigen_alpha.dot(eigen_mu-eigen_mean)+trace-log_det);
248 if (nlml_new<=nlml_def)
252 if (
m_alpha.
vlen*2 != total_len || nlml_def<nlml_new)
279 void CKLCholeskyInferenceMethod::update_C()
291 eigen_C.block(i, i, len-i ,1)=VectorXd::Map(eigen_C_seq.data()+offset, len-i);
296 void CKLCholeskyInferenceMethod::get_lower_triangular_vector(SGMatrix<float64_t> square_matrix,
297 SGVector<float64_t> target)
299 ASSERT(square_matrix.num_rows == square_matrix.num_cols);
301 ASSERT(target.vlen*2 == len*(len+1));
303 Map<MatrixXd> eigen_square_matrix(square_matrix.matrix, len, len);
309 eigen_result.block(offset, 0, len-i, 1)=eigen_square_matrix.block(i, i, len-i, 1);
319 eigen_Sigma=eigen_C*(eigen_C.transpose());
328 eigen_InvK_Sigma=eigen_InvK_C*(eigen_C.transpose());
virtual bool set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual float64_t optimization()
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const =0
SGVector< float64_t > m_mean_vec
The class Labels models labels, i.e. class assignments of objects.
virtual EInferenceType get_inference_type() const
virtual CVariationalGaussianLikelihood * get_variational_likelihood() const
virtual float64_t get_negative_log_marginal_likelihood_helper()
virtual int32_t get_num_labels() const =0
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
TParameter * get_parameter(int32_t idx)
An abstract class of the mean function.
virtual SGVector< float64_t > get_alpha()
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)
SGMatrix< float64_t > m_ktrtr
virtual void update_Sigma()
The KL approximation inference method class.
virtual bool precompute()
virtual void update_InvK_Sigma()
virtual ~CKLCholeskyInferenceMethod()
static CKLCholeskyInferenceMethod * obtain_from_generic(CInference *inference)
SGVector< float64_t > m_mu
static T sum(T *vec, int32_t len)
Return sum(vec)
virtual SGVector< float64_t > get_variational_expection()=0
Eigen::MatrixXd solve_inverse(Eigen::MatrixXd A)
SGMatrix< float64_t > m_Sigma
SGVector< float64_t > m_s2
The KL approximation inference method class.
all of classes and functions are contained in the shogun namespace
The Inference Method base class.
virtual void update_alpha()
The class Features is the base class of all feature objects.
static float64_t exp(float64_t x)
CKLCholeskyInferenceMethod()
SGMatrix< float64_t > m_InvK_Sigma
float64_t m_log_det_Kernel
virtual bool parameter_hash_changed()
The Likelihood model base class.
SGVector< float64_t > m_alpha