aboutsummaryrefslogtreecommitdiffstats
path: root/statistics
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-11-17 17:08:23 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-11-17 17:08:23 +0000
commit36076e63361d7c3d010f673d267793797de122b8 (patch)
tree70a0df4cdfca1d1a4fb0d9f1d67c981aad12ed86 /statistics
parentaa2167fb6ab9ea40278757964d2f00d4b24b8362 (diff)
downloadopt-utilities-36076e63361d7c3d010f673d267793797de122b8.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@96 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'statistics')
-rw-r--r--statistics/chisq.hpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/statistics/chisq.hpp b/statistics/chisq.hpp
index 54826d5..f9c2c22 100644
--- a/statistics/chisq.hpp
+++ b/statistics/chisq.hpp
@@ -8,6 +8,7 @@
#include <core/fitter.hpp>
#include <iostream>
#include <vector>
+#include <misc/optvec.hpp>
#include <cmath>
using std::cerr;using std::endl;
@@ -205,7 +206,55 @@ namespace opt_utilities
return result;
}
};
-#endif
+#endif
+
+ template<typename T,typename Tp,typename Ts,typename Tstr>
+ class chisq
+ :public statistic<optvec<T>,optvec<T>,Tp,Ts,Tstr>
+ {
+ private:
+ bool verb;
+ int n;
+
+ typedef optvec<T> Tx;
+ typedef optvec<T> Ty;
+ statistic<Ty,Tx,Tp,Ts,Tstr>* do_clone()const
+ {
+ // return const_cast<statistic<Ty,Tx,Tp>*>(this);
+ return new chisq<Ty,Tx,Tp,Ts,Tstr>(*this);
+ }
+
+ const char* do_get_type_name()const
+ {
+ return "chi^2 statistic";
+ }
+
+ public:
+ void verbose(bool v)
+ {
+ verb=v;
+ }
+ public:
+ chisq()
+ :verb(false)
+ {}
+
+
+
+ Ts do_eval(const Tp& p)
+ {
+ Ts result(0);
+ for(int i=(this->get_data_set()).size()-1;i>=0;--i)
+ {
+ Ty chi=(this->get_data_set().get_data(i).get_y()-eval_model(this->get_data_set().get_data(i).get_x(),p))/this->get_data_set().get_data(i).get_y_upper_err();
+ result+=sum(chi*chi);
+
+ }
+ return result;
+ }
+ };
+
+
}
#endif