aboutsummaryrefslogtreecommitdiffstats
path: root/pre_estimaters
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2011-03-03 17:36:55 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2011-03-03 17:36:55 +0000
commit4f4daacdfd12965d0044a7fec04b45672b5fe780 (patch)
tree690974c6f5aa0a7f3d05d8386fb402b8d6444011 /pre_estimaters
parent8c7d03aa146347d3d6cd1a34bfed90a4de60c920 (diff)
downloadopt-utilities-4f4daacdfd12965d0044a7fec04b45672b5fe780.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@181 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'pre_estimaters')
-rw-r--r--pre_estimaters/vgauss1d_estimater.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/pre_estimaters/vgauss1d_estimater.hpp b/pre_estimaters/vgauss1d_estimater.hpp
new file mode 100644
index 0000000..e3d1526
--- /dev/null
+++ b/pre_estimaters/vgauss1d_estimater.hpp
@@ -0,0 +1,52 @@
+#ifndef VGAUSS1D_ESTIMATER
+#define VGAUSS1D_ESTIMATER
+#include <core/pre_estimater.hpp>
+#include <misc/optvec.hpp>
+#include <vmodels/gauss1d.hpp>
+#include <vector>
+
+namespace opt_utilities
+{
+ template <typename T>
+ class gauss1d_estimater
+ :public pre_estimater<optvec<T>,optvec<T>,optvec<T>,std::string>
+ {
+ public:
+ gauss1d_estimater()
+ {
+ this->set_model_id("1d gaussian");
+ }
+
+ gauss1d_estimater<T>* do_clone()const
+ {
+ return new gauss1d_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
+ {
+ int n=d.size();
+ T xmean=0;
+ T x2mean=0;
+ T wgt=0;
+ T wgt2=0;
+ for(int i=0;i<n;++i)
+ {
+ T x=d.get_data(i).get_x()[0];
+ T y=d.get_data(i).get_y()[0];
+ xmean+=x*y;
+ x2mean+=x*x*y;
+ wgt+=y;
+ }
+ xmean/=wgt;
+ x2mean/=wgt;
+ T sigma=std::sqrt(x2mean-xmean*xmean);
+ m.set_param_value("x0",xmean);
+ m.set_param_value("sigma",sigma);
+
+ }
+ };
+}
+
+
+
+#endif