38 using namespace Eigen;
58 REQUIRE(mod,
"the likelihood model must not be NULL\n")
61 "The provided likelihood model (%s) must support variational Gaussian inference. ",
62 "Please use a Variational Gaussian Likelihood model\n",
72 void CKLInferenceMethod::init()
79 "The noise factor used for correcting Kernel matrix",
82 "The exponential factor used for increasing noise_factor",
85 "The max number of attempt to correct Kernel matrix",
88 "The minimum coeefficient of kernel matrix in LDLT factorization used to check whether the kernel matrix is positive definite or not",
93 "The number of corrections to approximate the inverse Hessian matrix",
96 "The maximum number of trials to do line search for each L-BFGS update",
99 "The line search algorithm",
102 "The maximum number of iterations for L-BFGS update",
105 "Delta for convergence test based on the change of function value",
108 "Distance for delta-based convergence test",
111 "Epsilon for convergence test based on the change of gradient",
114 "The minimum step of the line search",
117 "The maximum step of the line search",
120 "A parameter used in Armijo condition",
123 "A parameter used in curvature condition",
126 "A parameter used in Morethuente linesearch to control the accuracy",
129 "The machine precision for floating-point values",
132 "Coeefficient for the L1 norm of variables",
135 "Start index for computing L1 norm of the variables",
138 "End index for computing L1 norm of the variables",
141 "Variational parameter sigma2",
144 "Variational parameter mu and posterior mean",
147 "Posterior covariance matrix Sigma",
172 REQUIRE(noise_factor>=0,
"The noise_factor %.20f should be non-negative\n", noise_factor);
178 REQUIRE(min_coeff_kernel>=0,
"The min_coeff_kernel %.20f should be non-negative\n", min_coeff_kernel);
184 REQUIRE(max_attempt>=0,
"The max_attempt %d should be non-negative. 0 means inifity attempts\n", max_attempt);
190 REQUIRE(exp_factor>1.0,
"The exp_factor %f should be greater than 1.0.\n", exp_factor);
205 Eigen::LDLT<Eigen::MatrixXd> ldlt;
209 MatrixXd Kernel_D=ldlt.vectorD();
215 SG_ERROR(
"The Kernel matrix is highly non-positive definite since the min_coeff_kernel is less than %.20f",
216 " even when adding %.20f noise to the diagonal elements at max %d attempts\n",
224 Kernel_D=ldlt.vectorD();
253 REQUIRE(obj_prt,
"The instance object passed to L-BFGS optimizer should not be NULL\n");
293 int orthantwise_start,
330 Map<VectorXd> eigen_lp_dhyp(lp_dhyp.
vector, lp_dhyp.
vlen);
333 result[0]=-eigen_lp_dhyp.
sum();
349 "Length of the parameter %s should not be NULL\n", param->
m_name)
368 Map<VectorXd> eigen_dmu(dmu.
vector, dmu.
vlen);
371 result[i]=-eigen_alpha.
dot(eigen_dmu);
398 void * obj_prt =
static_cast<void *
>(
this);
400 CKLInferenceMethod::evaluate,
401 NULL, obj_prt, &lbfgs_param);
408 REQUIRE(!strcmp(param->
m_name,
"scale"),
"Can't compute derivative of "
409 "the nagative log marginal likelihood wrt %s.%s parameter\n",
414 MatrixXd eigen_dK=eigen_K*
m_scale*2.0;
431 "Length of the parameter %s should not be NULL\n", param->
m_name)
virtual const char * get_name() const =0
virtual void set_model(CLikelihoodModel *mod)
float64_t m_orthantwise_c
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
virtual void update_parameter_hash()
virtual SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)
virtual void update_alpha()=0
SGVector< float64_t > m_alpha
virtual SGMatrix< float64_t > get_cholesky()
virtual SGVector< float64_t > get_first_derivative_wrt_hyperparameter(const TParameter *param) const =0
int32_t lbfgs(int32_t n, float64_t *x, float64_t *ptr_fx, lbfgs_evaluate_t proc_evaluate, lbfgs_progress_t proc_progress, void *instance, lbfgs_parameter_t *_param, lbfgs_adjust_step_t proc_adjust_step)
The Inference Method base class.
virtual void set_exp_factor(float64_t exp_factor)
The class Labels models labels, i.e. class assignments of objects.
static T sum(T *vec, int32_t len)
return sum(vec)
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
virtual void update_init()
virtual void update_approx_cov()=0
virtual float64_t get_derivative_related_cov(Eigen::MatrixXd eigen_dK)=0
virtual SGVector< float64_t > get_derivative_wrt_mean(const TParameter *param)
An abstract class of the mean function.
virtual const char * get_name() const
virtual void set_variational_distribution(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab)
static const float64_t epsilon
SGMatrix< float64_t > m_Sigma
float64_t m_min_coeff_kernel
SGMatrix< float64_t > m_L
virtual float64_t get_negative_log_marginal_likelihood()
virtual void set_min_coeff_kernel(float64_t min_coeff_kernel)
virtual void check_variational_likelihood(CLikelihoodModel *mod) const
virtual float64_t lbfgs_optimization()
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)
virtual void set_max_attempt(index_t max_attempt)
virtual SGVector< float64_t > get_posterior_mean()
virtual SGMatrix< float64_t > get_posterior_covariance()
virtual Eigen::LDLT< Eigen::MatrixXd > update_init_helper()
The KL approximation inference method class.
virtual void set_lbfgs_parameters(int m=100, int max_linesearch=1000, int linesearch=LBFGS_LINESEARCH_DEFAULT, int max_iterations=1000, float64_t delta=0.0, int past=0, float64_t epsilon=1e-5, float64_t min_step=1e-20, float64_t max_step=1e+20, float64_t ftol=1e-4, float64_t wolfe=0.9, float64_t gtol=0.9, float64_t xtol=1e-16, float64_t orthantwise_c=0.0, int orthantwise_start=0, int orthantwise_end=1)
virtual void lbfgs_precompute()=0
virtual float64_t get_nlml_wrt_parameters()
virtual SGVector< float64_t > get_parameter_derivative(const CFeatures *features, const TParameter *param, index_t index=-1)
virtual void set_noise_factor(float64_t noise_factor)
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)
The class Features is the base class of all feature objects.
virtual void update_chol()=0
virtual SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
The Variational Likelihood base class.
SGVector< float64_t > m_mu
SGVector< float64_t > m_s2
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)=0
virtual CVariationalGaussianLikelihood * get_variational_likelihood() const
virtual bool supports_derivative_wrt_hyperparameter() const =0
virtual void update_deriv()=0
virtual ~CKLInferenceMethod()
virtual void set_model(CLikelihoodModel *mod)
virtual bool parameter_hash_changed()
The Likelihood model base class.
SGMatrix< float64_t > m_ktrtr
virtual float64_t get_negative_log_marginal_likelihood_helper()=0
CLikelihoodModel * m_model