67 bool enable_newton_if_fail,
75 int orthantwise_start,
79 m_max_linesearch = max_linesearch;
80 m_linesearch = linesearch;
81 m_max_iterations = max_iterations;
85 m_min_step = min_step;
86 m_max_step = max_step;
91 m_orthantwise_c = orthantwise_c;
92 m_orthantwise_start = orthantwise_start;
93 m_orthantwise_end = orthantwise_end;
94 m_enable_newton_if_fail = enable_newton_if_fail;
97 void CLaplacianInferenceMethodWithLBFGS::init()
102 "The number of corrections to approximate the inverse hessian matrix",
104 SG_ADD(&m_max_linesearch,
"max_linesearch",
105 "The maximum number of trials to do line search for each L-BFGS update",
107 SG_ADD(&m_linesearch,
"linesearch",
108 "The line search algorithm",
110 SG_ADD(&m_max_iterations,
"max_iterations",
111 "The maximum number of iterations for L-BFGS update",
114 "Delta for convergence test based on the change of function value",
117 "Distance for delta-based convergence test",
119 SG_ADD(&m_epsilon,
"epsilon",
120 "Epsilon for convergence test based on the change of gradient",
122 SG_ADD(&m_min_step,
"min_step",
123 "The minimum step of the line search",
125 SG_ADD(&m_max_step,
"max_step",
126 "The maximum step of the line search",
129 "A parameter used in Armijo condition",
132 "A parameter used in curvature condition",
135 "A parameter used in Morethuente linesearch to control the accuracy",
138 "The machine precision for floating-point values",
140 SG_ADD(&m_orthantwise_c,
"orthantwise_c",
141 "Coeefficient for the L1 norm of variables",
143 SG_ADD(&m_orthantwise_start,
"orthantwise_start",
144 "Start index for computing L1 norm of the variables",
146 SG_ADD(&m_orthantwise_end,
"orthantwise_end",
147 "End index for computing L1 norm of the variables",
149 SG_ADD(&m_enable_newton_if_fail,
"enable_newton_if_fail",
150 "Enable the original Newton method if the L-BFGS method fails",
158 float64_t CLaplacianInferenceMethodWithLBFGS::evaluate(
173 Eigen::Map<Eigen::VectorXd> eigen_alpha(alpha_cast, dim);
175 obj_prt->get_psi_wrt_alpha(&eigen_alpha, &psi);
176 Eigen::Map<Eigen::VectorXd> eigen_gradient(gradient, dim);
177 obj_prt->get_gradient_wrt_alpha(&eigen_alpha, &eigen_gradient);
188 Eigen::Map<Eigen::VectorXd> eigen_mean_f(mean_f.
vector, mean_f.
vlen);
206 eigen_mu = eigen_mean_f;
215 psi_new = eigen_alpha.
dot(eigen_mu - eigen_mean_f) / 2.0;
222 if (psi_def < psi_new)
225 eigen_mu = eigen_mean_f;
235 lbfgs_param.
delta = m_delta;
236 lbfgs_param.
past = m_past;
237 lbfgs_param.
epsilon = m_epsilon;
240 lbfgs_param.
ftol = m_ftol;
241 lbfgs_param.
wolfe = m_wolfe;
242 lbfgs_param.
gtol = m_gtol;
243 lbfgs_param.
xtol = m_xtol;
260 void * obj_prt =
static_cast<void *
>(
this);
263 CLaplacianInferenceMethodWithLBFGS::evaluate,
264 NULL, obj_prt, &lbfgs_param);
277 SG_WARNING(
"Error during L-BFGS optimization, using original Newton method as fallback\n");
300 if (eigen_W.minCoeff() > 0)
301 eigen_sW = eigen_W.cwiseSqrt();
306 void CLaplacianInferenceMethodWithLBFGS::get_psi_wrt_alpha(
307 Eigen::Map<Eigen::VectorXd>* alpha,
311 Eigen::Map<Eigen::VectorXd> eigen_f(f.vector, f.vlen);
315 Eigen::Map<Eigen::VectorXd> eigen_mean_f(m_mean_f->
vector,
322 *psi = alpha->dot(eigen_f - eigen_mean_f) * 0.5;
326 void CLaplacianInferenceMethodWithLBFGS::get_gradient_wrt_alpha(
327 Eigen::Map<Eigen::VectorXd>* alpha,
328 Eigen::Map<Eigen::VectorXd>* gradient)
330 SGVector<float64_t> f(alpha->rows());
331 Eigen::Map<Eigen::VectorXd> eigen_f(f.vector, f.vlen);
335 Eigen::Map<Eigen::VectorXd> eigen_mean_f(m_mean_f->
vector,
341 SGVector<float64_t> dlp_f =
344 Eigen::Map<Eigen::VectorXd> eigen_dlp_f(dlp_f.vector, dlp_f.vlen);
virtual SGVector< float64_t > get_log_probability_f(const CLabels *lab, SGVector< float64_t > func) const =0
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
SGVector< float64_t > m_alpha
int32_t lbfgs(int32_t n, float64_t *x, float64_t *ptr_fx, lbfgs_evaluate_t proc_evaluate, lbfgs_progress_t proc_progress, void *instance, lbfgs_parameter_t *_param, lbfgs_adjust_step_t proc_adjust_step)
The class Labels models labels, i.e. class assignments of objects.
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, bool enable_newton_if_fail=true, 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 int32_t get_num_labels() const =0
static T sum(T *vec, int32_t len)
return sum(vec)
virtual SGVector< float64_t > get_mean_vector(const CFeatures *features) const =0
An abstract class of the mean function.
SGVector< float64_t > d3lp
The Laplace approximation inference method with LBFGS class.
static const float64_t epsilon
void scale(T alpha)
scale vector inplace
virtual ~CLaplacianInferenceMethodWithLBFGS()
virtual void update_alpha()
SGVector< T > clone() const
The Laplace approximation inference method class.
virtual void update_alpha()
SGVector< float64_t > m_mu
The class Features is the base class of all feature objects.
CLaplacianInferenceMethodWithLBFGS()
virtual SGVector< float64_t > get_log_probability_derivative_f(const CLabels *lab, SGVector< float64_t > func, index_t i) const =0
SGVector< float64_t > dlp
SGVector< float64_t > d2lp
The Likelihood model base class.
SGMatrix< float64_t > m_ktrtr
CLikelihoodModel * m_model