50 using namespace Eigen;
67 void CKLCholeskyInferenceMethod::init()
70 "The Cholesky represention of the variational co-variance matrix",
72 SG_ADD(&m_InvK_C,
"invK_C",
73 " The K^{-1}C matrix",
84 SG_SERROR(
"Provided inference is not of type CKLCholeskyInferenceMethod!\n")
108 eigen_result=eigen_alpha;
132 eigen_s2=(eigen_C.array()*eigen_C.array()).rowwise().sum().matrix();
147 "The length of gradients (%d) should the same as the length of parameters (%d)\n",
180 eigen_tmp.block(offset, 0, len-i, 1)=VectorXd::Map(eigen_dv.data()+i, len-i);
185 eigen_dnlz_C_seq=(-2.0*(eigen_C_seq.array()*eigen_tmp.array())).matrix();
187 get_lower_triangular_vector(m_InvK_C, tmp);
188 eigen_dnlz_C_seq+=eigen_tmp;
192 eigen_tmp2=(1.0/eigen_C.diagonal().array()).matrix();
197 eigen_dnlz_C_seq.block(offset,0,1,1)-=VectorXd::Map(eigen_tmp2.data()+i,1);
218 float64_t trace=(eigen_InvK_C.array()*eigen_C.array()).sum();
221 float64_t result=-a+0.5*(-eigen_K.rows()+eigen_alpha.dot(eigen_mu-eigen_mean)+trace-log_det);
249 if (nlml_new<=nlml_def)
253 if (
m_alpha.
vlen*2 != total_len || nlml_def<nlml_new)
280 void CKLCholeskyInferenceMethod::update_C()
292 eigen_C.block(i, i, len-i ,1)=VectorXd::Map(eigen_C_seq.data()+offset, len-i);
297 void CKLCholeskyInferenceMethod::get_lower_triangular_vector(SGMatrix<float64_t> square_matrix,
298 SGVector<float64_t> target)
300 ASSERT(square_matrix.num_rows == square_matrix.num_cols);
302 ASSERT(target.vlen*2 == len*(len+1));
304 Map<MatrixXd> eigen_square_matrix(square_matrix.matrix, len, len);
310 eigen_result.block(offset, 0, len-i, 1)=eigen_square_matrix.block(i, i, len-i, 1);
320 eigen_Sigma=eigen_C*(eigen_C.transpose());
329 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)
SGVector< float64_t > m_alpha
The Inference Method base class.
static CKLCholeskyInferenceMethod * obtain_from_generic(CInferenceMethod *inference)
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
virtual bool lbfgs_precompute()
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 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()
static T sum(T *vec, int32_t len)
Return sum(vec)
virtual SGVector< float64_t > get_variational_expection()=0
The KL approximation inference method class.
all of classes and functions are contained in the shogun namespace
virtual void update_alpha()
The class Features is the base class of all feature objects.
static float64_t exp(float64_t x)
SGVector< float64_t > m_mu
SGVector< float64_t > m_s2
SGMatrix< float64_t > m_InvK_Sigma
virtual EInferenceType get_inference_type() const
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