SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KLInference.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Wu Lin
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  *
30  * Code adapted from
31  * http://hannes.nickisch.org/code/approxXX.tar.gz
32  * and Gaussian Process Machine Learning Toolbox
33  * http://www.gaussianprocess.org/gpml/code/matlab/doc/
34  * and the reference paper is
35  * Nickisch, Hannes, and Carl Edward Rasmussen.
36  * "Approximations for Binary Gaussian Process Classification."
37  * Journal of Machine Learning Research 9.10 (2008).
38  *
39  */
40 
41 #ifndef _KLINFERENCE_H_
42 #define _KLINFERENCE_H_
43 
44 #include <shogun/lib/config.h>
45 
48 
49 namespace Eigen
50 {
51  template <class, int, int, int, int, int> class Matrix;
52  template <class, int> class LDLT;
53 
54  typedef Matrix<float64_t,-1,-1,0,-1,-1> MatrixXd;
55 }
56 
57 namespace shogun
58 {
75 class CKLInference: public CInference
76 {
78 public:
80  CKLInference();
81 
90  CKLInference(CKernel* kernel, CFeatures* features,
91  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
92 
93  virtual ~CKLInference();
94 
97  virtual EInferenceType get_inference_type() const { return INF_KL; }
98 
103  virtual const char* get_name() const { return "KLInference"; }
104 
117 
130 
150 
155  virtual bool supports_regression() const
156  {
157  check_members();
158  return m_model->supports_regression();
159  }
160 
165  virtual bool supports_binary() const
166  {
167  check_members();
168  return m_model->supports_binary();
169  }
170 
175  virtual void set_model(CLikelihoodModel* mod);
176 
178  virtual void update();
179 
196 
204  virtual void set_noise_factor(float64_t noise_factor);
205 
212  virtual void set_max_attempt(index_t max_attempt);
213 
220  virtual void set_exp_factor(float64_t exp_factor);
221 
228  virtual void set_min_coeff_kernel(float64_t min_coeff_kernel);
229 
234  virtual void register_minimizer(Minimizer* minimizer);
235 protected:
236 
238  virtual void compute_gradient();
239 
242 
245 
248 
251 
255  virtual void update_init();
256 
262 
267 
273  virtual void check_variational_likelihood(CLikelihoodModel* mod) const;
274 
276  virtual void update_approx_cov()=0;
277 
289 
291  virtual float64_t optimization();
292 
301  const TParameter* param);
302 
311  const TParameter* param);
312 
321  const TParameter* param);
322 
331  const TParameter* param);
332 
339 
346 
353 
362  virtual bool precompute()=0;
363 
368 
371 
376 private:
377  void init();
378 };
379 }
380 #endif /* _KLINFERENCE_H_ */
virtual float64_t optimization()
virtual void set_min_coeff_kernel(float64_t min_coeff_kernel)
virtual bool supports_regression() const
Definition: KLInference.h:155
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)
virtual void update()
virtual void set_max_attempt(index_t max_attempt)
virtual bool supports_binary() const
Definition: KLInference.h:165
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual CVariationalGaussianLikelihood * get_variational_likelihood() const
virtual SGVector< float64_t > get_derivative_wrt_mean(const TParameter *param)
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
virtual void set_model(CLikelihoodModel *mod)
Definition: SGMatrix.h:20
parameter struct
An abstract class of the mean function.
Definition: MeanFunction.h:49
virtual float64_t get_negative_log_marginal_likelihood_helper()=0
virtual void register_minimizer(Minimizer *minimizer)
virtual Eigen::LDLT< Eigen::MatrixXd, 0x1 > update_init_helper()
friend class KLInferenceCostFunction
Definition: KLInference.h:77
float64_t m_noise_factor
Definition: KLInference.h:244
virtual void check_variational_likelihood(CLikelihoodModel *mod) const
float64_t m_min_coeff_kernel
Definition: KLInference.h:241
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)
The KL approximation inference method class.
Definition: KLInference.h:75
virtual SGMatrix< float64_t > get_posterior_covariance()
virtual void set_noise_factor(float64_t noise_factor)
virtual SGVector< float64_t > get_posterior_mean()
virtual float64_t get_derivative_related_cov(SGMatrix< float64_t > dK)=0
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)=0
double float64_t
Definition: common.h:50
float64_t m_exp_factor
Definition: KLInference.h:247
virtual bool supports_regression() const
EInferenceType
Definition: Inference.h:53
virtual bool supports_binary() const
SGVector< float64_t > m_mu
Definition: KLInference.h:367
virtual SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)
Matrix< float64_t,-1,-1, 0,-1,-1 > MatrixXd
Definition: KLInference.h:52
virtual const char * get_name() const
Definition: KLInference.h:103
SGMatrix< float64_t > m_Sigma
Definition: KLInference.h:370
virtual void update_init()
virtual SGMatrix< float64_t > get_cholesky()
SGVector< float64_t > m_s2
Definition: KLInference.h:375
virtual EInferenceType get_inference_type() const
Definition: KLInference.h:97
virtual bool precompute()=0
virtual float64_t get_nlml_wrt_parameters()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The Inference Method base class.
Definition: Inference.h:81
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Kernel base class.
Definition: Kernel.h:159
virtual float64_t get_negative_log_marginal_likelihood()
virtual void update_approx_cov()=0
The minimizer base class.
Definition: Minimizer.h:43
virtual void set_exp_factor(float64_t exp_factor)
CLikelihoodModel * m_model
Definition: Inference.h:475
virtual void compute_gradient()
The Likelihood model base class.
virtual void check_members() const
Definition: Inference.cpp:322

SHOGUN Machine Learning Toolbox - Documentation