SHOGUN  3.2.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
KLInferenceMethod.h
浏览该文件的文档.
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 _KLINFERENCEMETHOD_H_
42 #define _KLINFERENCEMETHOD_H_
43 
44 #include <shogun/lib/config.h>
45 
46 #ifdef HAVE_EIGEN3
51 
52 namespace shogun
53 {
54 
72 {
73 public:
76 
85  CKLInferenceMethod(CKernel* kernel, CFeatures* features,
86  CMeanFunction* mean, CLabels* labels, CLikelihoodModel* model);
87 
88  virtual ~CKLInferenceMethod();
89 
92  virtual EInferenceType get_inference_type() const { return INF_KL; }
93 
98  virtual const char* get_name() const { return "KLInferenceMethod"; }
99 
112 
125 
145 
150  virtual bool supports_regression() const
151  {
152  check_members();
153  return m_model->supports_regression();
154  }
155 
160  virtual bool supports_binary() const
161  {
162  check_members();
163  return m_model->supports_binary();
164  }
165 
170  virtual void set_model(CLikelihoodModel* mod);
171 
173  virtual void update();
174 
175  /* set L-BFGS parameters
176  * For details please see shogun/optimization/lbfgs/lbfgs.h
177  * @param m The number of corrections to approximate the inverse hessian matrix.
178  * Default value is 100.
179  * @param max_linesearch The maximum number of trials to do line search for each L-BFGS update.
180  * Default value is 1000.
181  * @param linesearch The line search algorithm.
182  * Default value is using the Morethuente line search
183  * @param max_iterations The maximum number of iterations for L-BFGS update.
184  * Default value is 1000.
185  * @param delta Delta for convergence test based on the change of function value.
186  * Default value is 0.
187  * @param past Distance for delta-based convergence test.
188  * Default value is 0.
189  * @param epsilon Epsilon for convergence test based on the change of gradient.
190  * Default value is 1e-5
191  * @param min_step The minimum step of the line search.
192  * The default value is 1e-20
193  * @param max_step The maximum step of the line search.
194  * The default value is 1e+20
195  * @param ftol A parameter used in Armijo condition.
196  * Default value is 1e-4
197  * @param wolfe A parameter used in curvature condition.
198  * Default value is 0.9
199  * @param gtol A parameter used in Morethuente linesearch to control the accuracy.
200  * Default value is 0.9
201  * @param xtol The machine precision for floating-point values.
202  * Default value is 1e-16.
203  * @param orthantwise_c Coeefficient for the L1 norm of variables.
204  * This parameter should be set to zero for standard minimization problems.
205  * Setting this parameter to a positive value activates
206  * Orthant-Wise Limited-memory Quasi-Newton (OWL-QN) method. Default value is 0.
207  * @param orthantwise_start Start index for computing L1 norm of the variables.
208  * This parameter is valid only for OWL-QN method. Default value is 0.
209  * @param orthantwise_end End index for computing L1 norm of the variables.
210  * Default value is 1.
211  */
212  virtual void set_lbfgs_parameters(int m = 100,
213  int max_linesearch = 1000,
214  int linesearch = LBFGS_LINESEARCH_DEFAULT,
215  int max_iterations = 1000,
216  float64_t delta = 0.0,
217  int past = 0,
218  float64_t epsilon = 1e-5,
219  float64_t min_step = 1e-20,
220  float64_t max_step = 1e+20,
221  float64_t ftol = 1e-4,
222  float64_t wolfe = 0.9,
223  float64_t gtol = 0.9,
224  float64_t xtol = 1e-16,
225  float64_t orthantwise_c = 0.0,
226  int orthantwise_start = 0,
227  int orthantwise_end = 1);
228 
245 
253  virtual void set_noise_factor(float64_t noise_factor);
254 
261  virtual void set_max_attempt(index_t max_attempt);
262 
269  virtual void set_exp_factor(float64_t exp_factor);
270 
277  virtual void set_min_coeff_kernel(float64_t min_coeff_kernel);
278 protected:
279 
282 
285 
288 
291 
295  virtual void update_init();
296 
301  virtual Eigen::LDLT<Eigen::MatrixXd> update_init_helper();
302 
307 
313  virtual void check_variational_likelihood(CLikelihoodModel* mod) const;
314 
316  virtual void update_approx_cov()=0;
317 
328  virtual float64_t get_derivative_related_cov(Eigen::MatrixXd eigen_dK)=0;
329 
331  virtual float64_t lbfgs_optimization();
332 
341  const TParameter* param);
342 
351  const TParameter* param);
352 
361  const TParameter* param);
362 
371  const TParameter* param);
372 
379 
386 
393 
401  virtual void lbfgs_precompute()=0;
402 
407 
410 
415 
416  /* The number of corrections to approximate the inverse hessian matrix.*/
417  int m_m;
418 
419  /* The maximum number of trials to do line search for each L-BFGS update.*/
421 
422  /* The line search algorithm.*/
424 
425  /* The maximum number of iterations for L-BFGS update.*/
427 
428  /* Delta for convergence test based on the change of function value.*/
430 
431  /* Distance for delta-based convergence test.*/
432  int m_past;
433 
434  /* Epsilon for convergence test based on the change of gradient.*/
436 
437  /* The minimum step of the line search.*/
439 
440  /* The maximum step of the line search.*/
442 
443  /* A parameter used in Armijo condition.*/
445 
446  /* A parameter used in curvature condition.*/
448 
449  /* A parameter used in Morethuente linesearch to control the accuracy.*/
451 
452  /* The machine precision for floating-point values.*/
454 
455  /* Coeefficient for the L1 norm of variables.*/
457 
458  /* Start index for computing L1 norm of the variables.*/
460 
461  /* End index for computing L1 norm of the variables.*/
463 
464 private:
465  void init();
466 
470  static float64_t evaluate(void *obj,
471  const float64_t *parameters,
472  float64_t *gradient,
473  const int dim,
474  const float64_t step);
475 
476 };
477 }
478 #endif /* HAVE_EIGEN3 */
479 #endif /* _KLINFERENCEMETHOD_H_ */
virtual bool supports_regression() const
virtual SGVector< float64_t > get_derivative_wrt_likelihood_model(const TParameter *param)
virtual SGMatrix< float64_t > get_cholesky()
The Inference Method base class.
virtual void set_exp_factor(float64_t exp_factor)
int32_t index_t
Definition: common.h:62
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.
parameter struct
Definition: Parameter.h:32
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.
Definition: MeanFunction.h:28
virtual const char * get_name() const
static const float64_t epsilon
Definition: libbmrm.cpp:24
SGMatrix< float64_t > m_Sigma
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()
double float64_t
Definition: common.h:50
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)
virtual bool supports_regression() const
virtual void set_max_attempt(index_t max_attempt)
virtual SGVector< float64_t > get_posterior_mean()
virtual bool supports_binary() const
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 void set_noise_factor(float64_t noise_factor)
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)
virtual bool supports_binary() const
The class Features is the base class of all feature objects.
Definition: Features.h:68
SGVector< float64_t > m_mu
SGVector< float64_t > m_s2
virtual void check_members() const
The Kernel base class.
Definition: Kernel.h:153
virtual void get_gradient_of_nlml_wrt_parameters(SGVector< float64_t > gradient)=0
virtual CVariationalGaussianLikelihood * get_variational_likelihood() const
virtual void set_model(CLikelihoodModel *mod)
#define delta
Definition: sfa.cpp:23
The Likelihood model base class.
virtual float64_t get_negative_log_marginal_likelihood_helper()=0
CLikelihoodModel * m_model
virtual EInferenceType get_inference_type() const

SHOGUN 机器学习工具包 - 项目文档