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",
92 Map<VectorXd> eigen_result(result.
vector, len);
95 eigen_result=eigen_alpha;
119 eigen_s2=(eigen_C.array()*eigen_C.array()).rowwise().sum().matrix();
131 "The length of gradients (%d) should the same as the length of parameters (%d)\n",
151 Map<VectorXd> eigen_dnlz_alpha(gradient.
vector, len);
155 Map<VectorXd> eigen_dnlz_C_seq(gradient.
vector+len, gradient.
vlen-len);
158 Map<VectorXd> eigen_tmp(tmp.vector, tmp.vlen);
164 eigen_tmp.block(offset, 0, len-i, 1)=VectorXd::Map(eigen_dv.data()+i, len-i);
169 eigen_dnlz_C_seq=(-2.0*(eigen_C_seq.array()*eigen_tmp.array())).matrix();
171 get_lower_triangular_vector(m_InvK_C, tmp);
172 eigen_dnlz_C_seq+=eigen_tmp;
174 Map<VectorXd> eigen_tmp2(tmp.vector, eigen_C.rows());
176 eigen_tmp2=(1.0/eigen_C.diagonal().array()).matrix();
181 eigen_dnlz_C_seq.block(offset,0,1,1)-=VectorXd::Map(eigen_tmp2.data()+i,1);
202 float64_t trace=(eigen_InvK_C.array()*eigen_C.array()).sum();
205 float64_t result=-a+0.5*(-eigen_K.rows()+eigen_alpha.dot(eigen_mu-eigen_mean)+trace-log_det);
224 Map<VectorXd> eigen_s2(s2_tmp.
vector, s2_tmp.
vlen);
233 if (nlml_new<=nlml_def)
237 if (
m_alpha.
vlen*2 != total_len || nlml_def<nlml_new)
264 void CKLCholeskyInferenceMethod::update_C()
276 eigen_C.block(i, i, len-i ,1)=VectorXd::Map(eigen_C_seq.data()+offset, len-i);
281 void CKLCholeskyInferenceMethod::get_lower_triangular_vector(SGMatrix<float64_t> square_matrix,
282 SGVector<float64_t> target)
284 ASSERT(square_matrix.num_rows == square_matrix.num_cols);
286 ASSERT(target.vlen*2 == len*(len+1));
288 Map<MatrixXd> eigen_square_matrix(square_matrix.matrix, len, len);
289 Map<VectorXd> eigen_result(target.vector, target.vlen);
294 eigen_result.block(offset, 0, len-i, 1)=eigen_square_matrix.block(i, i, len-i, 1);
304 eigen_Sigma=eigen_C*(eigen_C.transpose());
313 eigen_InvK_Sigma=eigen_InvK_C*(eigen_C.transpose());
SGVector< float64_t > m_alpha
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const =0
The class Labels models labels, i.e. class assignments of objects.
virtual float64_t get_negative_log_marginal_likelihood_helper()
virtual int32_t get_num_labels() const =0
static T sum(T *vec, int32_t len)
return sum(vec)
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
TParameter * get_parameter(int32_t idx)
Eigen::MatrixXd solve_inverse(Eigen::MatrixXd A)
An abstract class of the mean function.
virtual SGVector< float64_t > get_alpha()
virtual void set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)
virtual void update_Sigma()
SGMatrix< float64_t > m_Sigma
The KL approximation inference method class.
virtual void update_InvK_Sigma()
virtual float64_t lbfgs_optimization()
virtual ~CKLCholeskyInferenceMethod()
virtual SGVector< float64_t > get_variational_expection()=0
virtual void update_alpha()
The class Features is the base class of all feature objects.
SGVector< float64_t > m_mu
SGVector< float64_t > m_s2
SGMatrix< float64_t > m_InvK_Sigma
virtual void lbfgs_precompute()
virtual CVariationalGaussianLikelihood * get_variational_likelihood() const
CKLCholeskyInferenceMethod()
SGVector< float64_t > m_mean_vec
virtual bool parameter_hash_changed()
float64_t m_log_det_Kernel
The Likelihood model base class.
SGMatrix< float64_t > m_ktrtr