diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-05-08 15:19:40 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-05-08 15:19:40 -0400 |
commit | 4ecae3b2e34a45dfdf22f4f244fbbcd66c8635b0 (patch) | |
tree | 2bdbb243cede55e2277b497aaa97f1f707d2989e /training/liblbfgs/ll_test.cc | |
parent | ce9a18da4516f53ecf23fb7522562aef2d470397 (diff) |
add liblbfgs, which is much less crappy than the current one
Diffstat (limited to 'training/liblbfgs/ll_test.cc')
-rw-r--r-- | training/liblbfgs/ll_test.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/training/liblbfgs/ll_test.cc b/training/liblbfgs/ll_test.cc new file mode 100644 index 00000000..058db716 --- /dev/null +++ b/training/liblbfgs/ll_test.cc @@ -0,0 +1,32 @@ +#include <iostream> +#include <liblbfgs/lbfgs++.h> + +using namespace std; + +// Function must be lbfgsfloatval_t f(x.begin, x.end, g.begin) +lbfgsfloatval_t func(const lbfgsfloatval_t* x, lbfgsfloatval_t* g) { + int i; + lbfgsfloatval_t fx = 0.0; + int n = 4; + + for (i = 0;i < n;i += 2) { + lbfgsfloatval_t t1 = 1.0 - x[i]; + lbfgsfloatval_t t2 = 10.0 * (x[i+1] - x[i] * x[i]); + g[i+1] = 20.0 * t2; + g[i] = -2.0 * (x[i] * g[i+1] + t1); + fx += t1 * t1 + t2 * t2; + } + return fx; +} + +template<typename F> +void Opt(F& f) { + LBFGS<F> lbfgs(4, f, 1.0); + lbfgs.Optimize(); +} + +int main(int argc, char** argv) { + Opt(func); + return 0; +} + |