SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
SingleFITCLaplacianInferenceMethodWithLBFGS.h
浏览该文件的文档.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2015 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 Gaussian Process Machine Learning Toolbox
31  * http://www.gaussianprocess.org/gpml/code/matlab/doc/
32  */
33 #ifndef CSINGLEFITCLAPLACIANINFERENCEMETHODWITHLBFGS_H
34 #define CSINGLEFITCLAPLACIANINFERENCEMETHODWITHLBFGS_H
35 
36 #include <shogun/lib/config.h>
37 
38 #ifdef HAVE_EIGEN3
39 
42 
43 
44 namespace shogun
45 {
46 
59 {
60 public:
61  /* default constructor */
63 
64  /* constructor
65  *
66  * @param kernel covariance function
67  * @param features features to use in inference
68  * @param mean mean function
69  * @param labels labels of the features
70  * @param model Likelihood model to use
71  * @param inducing_features features to use
72  */
74  CFeatures* features,
75  CMeanFunction* mean,
76  CLabels* labels,
77  CLikelihoodModel* model,
78  CFeatures* inducing_features
79  );
80 
82 
83  /* returns the name of the inference method
84  *
85  * @return name SingleFITCLaplacianWithLBFGS
86  */
87  virtual const char* get_name() const
88  {return "SingleFITCLaplacianInferenceMethodWithLBFGS";}
89 
90  /* set L-BFGS parameters
91  * For details please see shogun/optimization/lbfgs/lbfgs.h
92  * @param m The number of corrections to approximate the inverse hessian matrix.
93  * Default value is 100.
94  * @param max_linesearch The maximum number of trials to do line search for each L-BFGS update.
95  * Default value is 1000.
96  * @param linesearch The line search algorithm.
97  * Default value is using the backtracking with the strong Wolfe condition line search
98  * @param max_iterations The maximum number of iterations for L-BFGS update.
99  * Default value is 1000.
100  * @param delta Delta for convergence test based on the change of function value.
101  * Default value is 0.
102  * @param past Distance for delta-based convergence test.
103  * Default value is 0.
104  * @param epsilon Epsilon for convergence test based on the change of gradient.
105  * Default value is 1e-5
106  * @param min_step The minimum step of the line search.
107  * The default value is 1e-20
108  * @param max_step The maximum step of the line search.
109  * The default value is 1e+20
110  * @param ftol A parameter used in Armijo condition.
111  * Default value is 1e-4
112  * @param wolfe A parameter used in curvature condition.
113  * Default value is 0.9
114  * @param gtol A parameter used in Morethuente linesearch to control the accuracy.
115  * Default value is 0.9
116  * @param xtol The machine precision for floating-point values.
117  * Default value is 1e-16.
118  * @param orthantwise_c Coeefficient for the L1 norm of variables.
119  * This parameter should be set to zero for standard minimization problems.
120  * Setting this parameter to a positive value activates
121  * Orthant-Wise Limited-memory Quasi-Newton (OWL-QN) method. Default value is 0.
122  * @param orthantwise_start Start index for computing L1 norm of the variables.
123  * This parameter is valid only for OWL-QN method. Default value is 0.
124  * @param orthantwise_end End index for computing L1 norm of the variables.
125  * Default value is 1.
126  */
127  virtual void set_lbfgs_parameters(int m = 100,
128  int max_linesearch = 1000,
130  int max_iterations = 1000,
131  float64_t delta = 0.0,
132  int past = 0,
133  float64_t epsilon = 1e-5,
134  float64_t min_step = 1e-20,
135  float64_t max_step = 1e+20,
136  float64_t ftol = 1e-4,
137  float64_t wolfe = 0.9,
138  float64_t gtol = 0.9,
139  float64_t xtol = 1e-16,
140  float64_t orthantwise_c = 0.0,
141  int orthantwise_start = 0,
142  int orthantwise_end = 1);
143 
144  /* wheter we use Newton method as rollbak if LBFGS optimizer fails
145  *
146  * @param enable_newton_if_fail if LBFGS optimizer fails, should we use Newton method.
147  */
148  virtual void set_newton_method(bool enable_newton_if_fail);
149 protected:
150  /* update alpha using the LBFGS method*/
151  virtual void update_alpha();
152 
153 private:
154  /* a parameter used to compute function value and gradient for LBFGS update*/
155  SGVector<float64_t> * m_mean_f;
156 
157  /* should we enable the original Newton method
158  * if the L-BFGS method fails
159  * */
160  bool m_enable_newton_if_fail;
161 
162  /* The number of corrections to approximate the inverse hessian matrix.*/
163  int m_m;
164 
165  /* The maximum number of trials to do line search for each L-BFGS update.*/
166  int m_max_linesearch;
167 
168  /* The line search algorithm.*/
169  int m_linesearch;
170 
171  /* The maximum number of iterations for L-BFGS update.*/
172  int m_max_iterations;
173 
174  /* Delta for convergence test based on the change of function value.*/
175  float64_t m_delta;
176 
177  /* Distance for delta-based convergence test.*/
178  int m_past;
179 
180  /* Epsilon for convergence test based on the change of gradient.*/
181  float64_t m_epsilon;
182 
183  /* The minimum step of the line search.*/
184  float64_t m_min_step;
185 
186  /* The maximum step of the line search.*/
187  float64_t m_max_step;
188 
189  /* A parameter used in Armijo condition.*/
190  float64_t m_ftol;
191 
192  /* A parameter used in curvature condition.*/
193  float64_t m_wolfe;
194 
195  /* A parameter used in Morethuente linesearch to control the accuracy.*/
196  float64_t m_gtol;
197 
198  /* The machine precision for floating-point values.*/
199  float64_t m_xtol;
200 
201  /* Coeefficient for the L1 norm of variables.*/
202  float64_t m_orthantwise_c;
203 
204  /* Start index for computing L1 norm of the variables.*/
205  int m_orthantwise_start;
206 
207  /* End index for computing L1 norm of the variables.*/
208  int m_orthantwise_end;
209 
210  void init();
211 
212  /* helper function is passed to the LBFGS API
213  * Note that this function should be static and
214  * private.
215  * */
216  static float64_t evaluate(void *obj,
217  const float64_t *alpha,
218  float64_t *gradient,
219  const int dim,
220  const float64_t step);
221 
222  /* compute the gradient given the current alpha*/
223  void get_gradient_wrt_alpha(float64_t *alpha,
224  float64_t *gradient, const int dim);
225 
226  /* compute the function value given the current alpha*/
227  void get_psi_wrt_alpha(float64_t *alpha,
228  const int dim, float64_t &psi);
229 };
230 
231 } /* namespace shogun */
232 #endif /* HAVE_EIGEN3 */
233 #endif /* CSINGLEFITCLAPLACIANINFERENCEMETHODWITHLBFGS_H */
The Laplace approximation FITC inference method with LBFGS class for regression and binary classifica...
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
The SingleFITCLaplace approximation inference method class for regression and binary Classification...
An abstract class of the mean function.
Definition: MeanFunction.h:49
static const float64_t epsilon
Definition: libbmrm.cpp:25
virtual void set_lbfgs_parameters(int m=100, int max_linesearch=1000, int linesearch=LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE, 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)
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Kernel base class.
Definition: Kernel.h:158
#define delta
Definition: sfa.cpp:23
The Likelihood model base class.

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