[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/test simplex_test.cc simplex_view.gnuplot ...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN/test simplex_test.cc simplex_view.gnuplot ... |
Date: |
Wed, 27 May 2009 13:17:22 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/05/27 13:17:22
Added files:
test : simplex_test.cc simplex_view.gnuplot
Removed files:
test : simplex_text.cc
Log message:
Renamed and improved simplex test program.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/test/simplex_test.cc?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/test/simplex_view.gnuplot?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/test/simplex_text.cc?cvsroot=toon&r1=1.1&r2=0
Patches:
Index: simplex_test.cc
===================================================================
RCS file: simplex_test.cc
diff -N simplex_test.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ simplex_test.cc 27 May 2009 13:17:21 -0000 1.1
@@ -0,0 +1,42 @@
+#include <TooN/optimization/downhill_simplex.h>
+using namespace std;
+using namespace TooN;
+
+
+double sq(double x)
+{
+ return x*x;
+}
+
+double Rosenbrock(const Vector<2>& v)
+{
+ return sq(1 - v[0]) + 100 * sq(v[1] - sq(v[0]));
+}
+
+double Spiral(const Vector<2>& v)
+{
+ double x = v[0];
+ double y = v[1];
+ return sin(20.0*sqrt(x*x+y*y)+2.0*atan(y/x))+2.0*x*x+2.0*y*y;
+}
+
+
+int main()
+{
+ Vector<2> starting_point = makeVector(1.5, 1.5);
+
+ DownhillSimplex<2> dh_fixed(Spiral, starting_point, .001);
+
+ while(dh_fixed.iterate(Spiral))
+ {
+ // cout << dh_fixed.get_values()[dh_fixed.get_best()] <<
endl;
+ cout << dh_fixed.get_simplex()[0] <<
dh_fixed.get_values()[0] << endl;
+ cout << dh_fixed.get_simplex()[1] <<
dh_fixed.get_values()[1] << endl;
+ cout << dh_fixed.get_simplex()[2] <<
dh_fixed.get_values()[2] << endl;
+ cout << endl;
+ }
+
+ //cout << dh_fixed.get_simplex()[dh_fixed.get_best()] << endl;
+}
+
+
Index: simplex_view.gnuplot
===================================================================
RCS file: simplex_view.gnuplot
diff -N simplex_view.gnuplot
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ simplex_view.gnuplot 27 May 2009 13:17:22 -0000 1.1
@@ -0,0 +1,19 @@
+####
+#### Compile cg_test.cc to cg_test
+####
+
+set multiplot
+set nocontour
+set pm3d
+unset surface
+set view 0,0
+set isosample 100
+
+splot [-2:2] [-2:2] sin(20*sqrt(x**2 + y**2) + atan(y/x)*2) + 1*(x**2 + y**2)
+unset pm3d
+set surface
+splot [-2:2] [-2:2] '< ./simplex_test' using 1:2:3 with linespoints title
'Conjugate Gradient path'
+unset multiplot
+
+
+
Index: simplex_text.cc
===================================================================
RCS file: simplex_text.cc
diff -N simplex_text.cc
--- simplex_text.cc 26 May 2009 18:06:01 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,40 +0,0 @@
-#include <TooN/optimization/downhill_simplex.h>
-using namespace std;
-using namespace TooN;
-
-template<class C> double length(const C& v)
-{
- return sqrt(v*v);
-}
-
-double sq(double x)
-{
- return x*x;
-}
-
-template<class C> double simplex_size(const C& s)
-{
- return abs(length(s.get_simplex()[s.get_best()] -
s.get_simplex()[s.get_worst()]) / length( s.get_simplex()[s.get_best()]));
-}
-
-double Rosenbrock(const Vector<2>& v)
-{
- return sq(1 - v[0]) + 100 * sq(v[1] - sq(v[0]));
-}
-
-int main()
-{
- Vector<2> starting_point = makeVector( -1, 1);
-
- DownhillSimplex<2> dh_fixed(Rosenbrock, starting_point, 1);
- while(simplex_size(dh_fixed) > 0.0000001)
- {
- cout <<
dh_fixed.get_simplex()[dh_fixed.get_best()] << endl;
- cout <<
dh_fixed.get_values()[dh_fixed.get_best()] << endl;
- dh_fixed.iterate(Rosenbrock);
- }
-
- cout << dh_fixed.get_simplex()[dh_fixed.get_best()] << endl;
-}
-
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN/test simplex_test.cc simplex_view.gnuplot ...,
Edward Rosten <=