49 using namespace Eigen;
66 void CKLDiagonalInferenceMethod::init()
80 SG_SERROR(
"Provided inference is not of type CKLDiagonalInferenceMethod!\n")
104 eigen_result=eigen_alpha;
126 eigen_s2=eigen_log_v.array().exp();
136 "The length of gradients (%d) should the same as the length of parameters (%d)\n",
162 eigen_dnlz_log_v=(eigen_InvK.diagonal().array()-(1.0/eigen_s2.array()));
163 eigen_dnlz_log_v=(0.5*eigen_dnlz_log_v.array())-eigen_dv.array();
164 eigen_dnlz_log_v=eigen_dnlz_log_v.array()*eigen_s2.array();
182 float64_t trace=(eigen_s2.array()*eigen_InvK.diagonal().array()).sum();
185 float64_t result=-a+0.5*(-eigen_K.rows()+eigen_alpha.dot(eigen_mu-eigen_mean)+trace-log_det);
213 float64_t trace=eigen_InvK.diagonal().array().sum();
216 if (nlml_new<=nlml_def)
220 if (
m_alpha.
vlen != total_len || nlml_def<nlml_new)
238 eigen_Sigma=eigen_s2.asDiagonal();
virtual bool precompute()
virtual bool set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
virtual float64_t optimization()
virtual ~CKLDiagonalInferenceMethod()
virtual SGVector< float64_t > get_variational_first_derivative(const TParameter *param) const =0
The KL approximation inference method class.
virtual float64_t get_negative_log_marginal_likelihood_helper()
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 int32_t get_num_labels() const =0
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
virtual void update_InvK_Sigma()
TParameter * get_parameter(int32_t idx)
virtual void update_Sigma()
An abstract class of the mean function.
SGMatrix< float64_t > m_ktrtr
The KL approximation inference method class.
SGVector< float64_t > m_mu
static T sum(T *vec, int32_t len)
Return sum(vec)
virtual SGVector< float64_t > get_alpha()
virtual SGVector< float64_t > get_variational_expection()=0
CKLDiagonalInferenceMethod()
Eigen::MatrixXd solve_inverse(Eigen::MatrixXd A)
virtual void update_alpha()
SGMatrix< float64_t > m_Sigma
SGVector< float64_t > m_s2
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.
static float64_t exp(float64_t x)
SGMatrix< float64_t > m_InvK_Sigma
static CKLDiagonalInferenceMethod * obtain_from_generic(CInference *inference)
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)
float64_t m_log_det_Kernel
virtual bool parameter_hash_changed()
The Likelihood model base class.
SGVector< float64_t > m_alpha