summaryrefslogtreecommitdiff
path: root/training/liblbfgs/ll_test.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-05-08 15:19:40 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-05-08 15:19:40 -0400
commite66b487c6bf4debb1326ad8c7169a44badace365 (patch)
tree1ad89e58b6df5a3632a0b4e95c6014574be273bd /training/liblbfgs/ll_test.cc
parenta3d0e4f8c8f669fd4c0dac7a193a12148253d4e2 (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.cc32
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;
+}
+