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

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