summaryrefslogtreecommitdiff
path: root/training
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-14 17:00:45 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-14 17:00:45 +0200
commit7c344de97edac0aa2a6a90c2de9bcf60f15ac000 (patch)
treef61bf6ca09d1d0ec6398dd0e8ec7c8e85a5598e7 /training
parentd94373453c69c6cfec952a0f7b427cacc78654d8 (diff)
parent824c96f038b0447ce83ae92cad112a5be49e3330 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'training')
-rw-r--r--training/liblbfgs/lbfgs++.h30
-rw-r--r--training/liblbfgs/ll_test.cc4
2 files changed, 21 insertions, 13 deletions
diff --git a/training/liblbfgs/lbfgs++.h b/training/liblbfgs/lbfgs++.h
index 342f9b0e..2b40c19b 100644
--- a/training/liblbfgs/lbfgs++.h
+++ b/training/liblbfgs/lbfgs++.h
@@ -16,28 +16,33 @@
template <typename Function>
class LBFGS {
public:
- LBFGS(size_t n, // number of variables
- const Function& f, // function to optimize
- double l1_c = 0.0, // l1 penalty strength
- size_t m = 10 // number of memory buffers
- // TODO should use custom allocator here:
+ LBFGS(size_t n, // number of variables
+ const Function& f, // function to optimize
+ size_t m = 10, // number of memory buffers
+ double l1_c = 0.0, // l1 penalty strength
+ unsigned l1_start = 0, // l1 penalty starting index
+ double eps = 1e-5 // convergence epsilon
+ // TODO should use custom allocator here:
) : p_x(new std::vector<lbfgsfloatval_t>(n, 0.0)),
owned(true),
m_x(*p_x),
func(f) {
- Init(m, l1_c);
+ Init(m, l1_c, l1_start, eps);
}
// constructor where external vector storage for variables is used
LBFGS(std::vector<lbfgsfloatval_t>* px,
const Function& f,
- double l1_c = 0.0, // l1 penalty strength
- size_t m = 10
+ size_t m = 10, // number of memory buffers
+ double l1_c = 0.0, // l1 penalty strength
+ unsigned l1_start = 0, // l1 penalty starting index
+ double eps = 1e-5 // convergence epsilon
+ // TODO should use custom allocator here:
) : p_x(px),
owned(false),
m_x(*p_x),
func(f) {
- Init(m, l1_c);
+ Init(m, l1_c, l1_start, eps);
}
~LBFGS() {
@@ -60,12 +65,14 @@ class LBFGS {
}
private:
- void Init(size_t m, double l1_c) {
+ void Init(size_t m, double l1_c, unsigned l1_start, double eps) {
lbfgs_parameter_init(&param);
param.m = m;
+ param.epsilon = eps;
if (l1_c > 0.0) {
param.linesearch = LBFGS_LINESEARCH_BACKTRACKING;
- param.orthantwise_c = 1.0;
+ param.orthantwise_c = l1_c;
+ param.orthantwise_start = l1_start;
}
silence = false;
}
@@ -83,6 +90,7 @@ class LBFGS {
lbfgsfloatval_t *g,
const int n,
const lbfgsfloatval_t step) {
+ (void) x;
(void) n;
(void) step;
if (!silence) { ec++; std::cerr << '.'; }
diff --git a/training/liblbfgs/ll_test.cc b/training/liblbfgs/ll_test.cc
index 43c0f214..48bc0366 100644
--- a/training/liblbfgs/ll_test.cc
+++ b/training/liblbfgs/ll_test.cc
@@ -5,7 +5,7 @@ using namespace std;
// Function must be lbfgsfloatval_t f(x.begin, x.end, g.begin)
lbfgsfloatval_t func(const vector<lbfgsfloatval_t>& x, lbfgsfloatval_t* g) {
- int i;
+ unsigned i;
lbfgsfloatval_t fx = 0.0;
for (i = 0;i < x.size();i += 2) {
@@ -24,7 +24,7 @@ void Opt(F& f) {
lbfgs.MinimizeFunction();
}
-int main(int argc, char** argv) {
+int main() {
Opt(func);
return 0;
}