aboutsummaryrefslogtreecommitdiffstats
path: root/pre_estimaters/vdualgauss1d_estimater.hpp
blob: 2be4cfbcdee8376cc40100f6d6dfc6c855d8ae2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef VDUALGAUSS1D_ESTIMATER
#define VDUALGAUSS1D_ESTIMATER
#include <core/pre_estimater.hpp>
#include <misc/optvec.hpp>
#include <vmodels/dualgauss1d.hpp>
#include <vector>

namespace opt_utilities
{
  template <typename T>
  class dualgauss1d_estimater
    :public pre_estimater<optvec<T>,optvec<T>,optvec<T>,std::string>
  {
  public:
    dualgauss1d_estimater()
    {
      this->set_model_id("1d dualgaussian");
    }

    dualgauss1d_estimater<T>* do_clone()const
    {
      return new dualgauss1d_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 xp1st=0;
      T xp2nd=0;
      T yp1st=d.get_data(0).get_y()[0];
      T yp2nd=d.get_data(0).get_y()[0];

      for(int i=0;i<n;++i)
	{
	  if(d.get_data(i).get_y()[0]>yp1st)
	    {
	      yp1st=d.get_data(i).get_y()[0];
	      xp1st=d.get_data(i).get_x()[0];
	    }
	}
      
      for(int i=0;i<n;++i)
	{
	  
	}
      

      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