aboutsummaryrefslogtreecommitdiffstats
path: root/pre_estimaters/vlin1d_estimater.hpp
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2011-02-19 13:12:59 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2011-02-19 13:12:59 +0000
commit70a767c1a81de38d019b804cfcfd3b8255868723 (patch)
tree269f967f8aa9726237855b9103dce12de8202e36 /pre_estimaters/vlin1d_estimater.hpp
parent784f745b792b45d1cce283fac3d5b0fcc6946adf (diff)
downloadopt-utilities-70a767c1a81de38d019b804cfcfd3b8255868723.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@178 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'pre_estimaters/vlin1d_estimater.hpp')
-rw-r--r--pre_estimaters/vlin1d_estimater.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/pre_estimaters/vlin1d_estimater.hpp b/pre_estimaters/vlin1d_estimater.hpp
new file mode 100644
index 0000000..7f37b3c
--- /dev/null
+++ b/pre_estimaters/vlin1d_estimater.hpp
@@ -0,0 +1,52 @@
+#ifndef VLIN1D_ESTIMATER
+#define VLIN1D_ESTIMATER
+#include <core/pre_estimater.hpp>
+#include <misc/optvec.hpp>
+#include <vmodels/lin1d.hpp>
+#include <vector>
+
+namespace opt_utilities
+{
+ template <typename T>
+ class lin1d_estimater
+ :public pre_estimater<optvec<T>,optvec<T>,optvec<T>,std::string>
+ {
+ public:
+ lin1d_estimater()
+ {
+ this->set_model_id("1d linear model");
+ }
+
+ lin1d_estimater<T>* do_clone()const
+ {
+ return new lin1d_estimater<T>(*this);
+ }
+
+ void do_estimate(const data_set<optvec<T>,optvec<T> >& d,model<optvec<T>,optvec<T>,optvec<T>,std::string>& m)const
+ {
+ T n=d.size();
+ T sy=0;
+ T sxx=0;
+ T sx=0;
+ T sxy=0;
+
+ for(int i=0;i<d.size();++i)
+ {
+ sy+=d.get_data(i).get_y()[0];
+ sxx+=d.get_data(i).get_x()[0]*d.get_data(i).get_x()[0];
+ sx+=d.get_data(i).get_x()[0];
+ sxy+=d.get_data(i).get_x()[0]*d.get_data(i).get_y()[0];
+ }
+ T b=(sy*sxx-sx*sxy)/(n*sxx-sx*sx);
+ T k=(n*sxy-sx*sy)/(n*sxx-sx*sx);
+
+ m.set_param_value("k",k);
+ m.set_param_value("b",b);
+
+ }
+ };
+}
+
+
+
+#endif