SHOGUN  6.1.3
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 {
77 friend class KLInferenceCostFunction;
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 
116  virtual float64_t get_negative_log_marginal_likelihood();
117 
129  virtual SGVector<float64_t> get_posterior_mean();
130 
149  virtual SGMatrix<float64_t> get_posterior_covariance();
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 
195  virtual SGMatrix<float64_t> get_cholesky();
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 
261  virtual Eigen::LDLT<Eigen::MatrixXd,0x1> update_init_helper();
262 
266  virtual CVariationalGaussianLikelihood* get_variational_likelihood() const;
267 
273  virtual void check_variational_likelihood(CLikelihoodModel* mod) const;
274 
276  virtual void update_approx_cov()=0;
277 
288  virtual float64_t get_derivative_related_cov(SGMatrix<float64_t> dK)=0;
289 
291  virtual float64_t optimization();
292 
300  virtual SGVector<float64_t> get_derivative_wrt_inference_method(
301  const TParameter* param);
302 
310  virtual SGVector<float64_t> get_derivative_wrt_likelihood_model(
311  const TParameter* param);
312 
320  virtual SGVector<float64_t> get_derivative_wrt_kernel(
321  const TParameter* param);
322 
330  virtual SGVector<float64_t> get_derivative_wrt_mean(
331  const TParameter* param);
332 
338  virtual float64_t get_negative_log_marginal_likelihood_helper()=0;
339 
345  virtual float64_t get_nlml_wrt_parameters();
346 
352  virtual void get_gradient_of_nlml_wrt_parameters(SGVector<float64_t> gradient)=0;
353 
362  virtual bool precompute()=0;
363 
368 
371 
376 private:
377  void init();
378 };
379 }
380 #endif /* _KLINFERENCE_H_ */
virtual bool supports_regression() const
Definition: KLInference.h:155
virtual bool supports_binary() const
Definition: KLInference.h:165
int32_t index_t
Definition: common.h:72
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
The variational Gaussian Likelihood base class. The variational distribution is Gaussian.
Definition: SGMatrix.h:25
parameter struct
An abstract class of the mean function.
Definition: MeanFunction.h:49
std::enable_if<!std::is_same< T, complex128_t >::value, float64_t >::type mean(const Container< T > &a)
float64_t m_noise_factor
Definition: KLInference.h:244
float64_t m_min_coeff_kernel
Definition: KLInference.h:241
The KL approximation inference method class.
Definition: KLInference.h:75
double float64_t
Definition: common.h:60
float64_t m_exp_factor
Definition: KLInference.h:247
EInferenceType
Definition: Inference.h:53
SGVector< float64_t > m_mu
Definition: KLInference.h:367
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
SGVector< float64_t > m_s2
Definition: KLInference.h:375
virtual EInferenceType get_inference_type() const
Definition: KLInference.h:97
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:69
void(* update)(float *foo, float bar)
Definition: JLCoverTree.h:533
The Kernel base class.
The minimizer base class.
Definition: Minimizer.h:43
The Likelihood model base class.

SHOGUN Machine Learning Toolbox - Documentation