diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2012-04-01 18:17:41 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2012-04-01 18:17:41 +0000 |
commit | 3a8b1ca89c9b62e35e24d414d7a79f4c325dfd09 (patch) | |
tree | 6f87c5ee405c128007254055a88732f93b780a9e /test | |
parent | 87ede9b87ebb7323d167d09f0c7b8efde03c736c (diff) | |
download | opt-utilities-3a8b1ca89c9b62e35e24d414d7a79f4c325dfd09.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@230 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'test')
-rw-r--r-- | test/test_cg.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/test_cg.cpp b/test/test_cg.cpp new file mode 100644 index 0000000..a080cc5 --- /dev/null +++ b/test/test_cg.cpp @@ -0,0 +1,55 @@ +#include <methods/conjugate_gradient/conjugate_gradient.hpp> +#include <methods/powell/powell_method.hpp> +#include <vector> +using namespace std; + +using namespace opt_utilities; + +class foo + :public diff_func_obj<double,vector<double> > +{ + foo* do_clone()const + { + return new foo(*this); + } + + double do_eval(const vector<double>& p) + { + static int call_cnt=0; + ++call_cnt; + cerr<<call_cnt<<endl; + double result=0; + for(int i=0;i<p.size();++i) + { + result+=p[i]*p[i]; + } + return result; + } + + vector<double> do_gradient(const vector<double>& p) + { + static int call_cnt=0; + ++call_cnt; + cerr<<call_cnt<<endl; + vector<double> result(p.size()); + for(int i=0;i<p.size();++i) + { + result[i]=2*p[i]; + } + return p; + } +}; + + +int main() +{ + optimizer<double,vector<double> > opt; + //opt.set_opt_method(conjugate_gradient<double,vector<double> >()); + opt.set_opt_method(powell_method<double,vector<double> >()); + opt.set_func_obj(foo()); + std::vector<double> p(2); + p[0]=p[1]=4; + opt.set_start_point(p); + p=opt.optimize(); + cout<<p[0]<<"\t"<<p[1]<<endl; +} |