aboutsummaryrefslogtreecommitdiffstats
path: root/statistics
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-04-01 16:09:42 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-04-01 16:09:42 +0000
commit4954b5638ced13c2f9d2f0ec4dca77b03f7e89d0 (patch)
tree142353657c1858f02f9f121c564538257a7da26e /statistics
parent22e026dac6c0a2225e3adb3c9ee336fafaa2e366 (diff)
downloadopt-utilities-4954b5638ced13c2f9d2f0ec4dca77b03f7e89d0.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@11 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'statistics')
-rw-r--r--statistics/leastsq.hpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/statistics/leastsq.hpp b/statistics/leastsq.hpp
new file mode 100644
index 0000000..fa76fa2
--- /dev/null
+++ b/statistics/leastsq.hpp
@@ -0,0 +1,71 @@
+#ifndef LEAST_SQ_HPP
+#define LeAST_SQ_HPP
+#include <core/fitter.hpp>
+#include <iostream>
+#include <vector>
+#include <cmath>
+using std::cerr;using std::endl;
+
+namespace opt_utilities
+{
+ template<typename Ty,typename Tx,typename Tp,typename Ts,typename Tstr>
+ class leastsq
+ :public statistic<Ty,Tx,Tp,Ts,Tstr>
+ {
+ private:
+ bool verb;
+ int n;
+
+
+ statistic<Ty,Tx,Tp,Ts,Tstr>* do_clone()const
+ {
+ // return const_cast<statistic<Ty,Tx,Tp>*>(this);
+ return new leastsq<Ty,Tx,Tp,Ts,Tstr>(*this);
+ }
+ public:
+ void verbose(bool v)
+ {
+ verb=v;
+ }
+ public:
+ leastsq()
+ :verb(false)
+ {}
+
+
+
+ Ts do_eval(const Tp& p)
+ {
+ Ts result(0);
+ for(int i=(this->datas()).size()-1;i>=0;--i)
+ {
+ Ty chi=(this->datas().get_data(i).get_y()-eval_model(this->datas().get_data(i).get_x(),p));
+ result+=chi*chi;
+
+ }
+ if(verb)
+ {
+ n++;
+ if(n%10==0)
+ {
+
+ cerr<<result<<"\t";
+ for(size_t i=0;i<get_size(p);++i)
+ {
+ cerr<<get_element(p,i)<<",";
+ }
+ cerr<<endl;
+ }
+
+ }
+
+ return result;
+ }
+ };
+
+}
+
+#endif
+//EOF
+
+