diff options
| author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2011-04-13 16:42:47 +0000 | 
|---|---|---|
| committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2011-04-13 16:42:47 +0000 | 
| commit | 412f4f074e758b4889a41a32af571e6f6b0a3701 (patch) | |
| tree | 8e2192ccd96f0df0fb5933d86bf7849ebfba5525 | |
| parent | dc12a14bc56072a711c82215d5c8213c2dcd5907 (diff) | |
| download | opt-utilities-412f4f074e758b4889a41a32af571e6f6b0a3701.tar.bz2 | |
git-svn-id: file:///home/svn/opt_utilities@187 ed2142bd-67ad-457f-ba7c-d818d4011675
| -rw-r--r-- | statistics/leastsq.hpp | 64 | 
1 files changed, 64 insertions, 0 deletions
| diff --git a/statistics/leastsq.hpp b/statistics/leastsq.hpp index 3b5ab37..f23f0d1 100644 --- a/statistics/leastsq.hpp +++ b/statistics/leastsq.hpp @@ -8,6 +8,7 @@  #define LEAST_SQ_HPP
  #define OPT_HEADER
  #include <core/fitter.hpp>
 +#include <misc/optvec.hpp>
  #include <iostream>
  #include <vector>
  #include <cmath>
 @@ -84,9 +85,72 @@ namespace opt_utilities        return result;
      }
    };
 +
 +  template<typename T,typename Ts,typename Tstr>
 +  class leastsq<optvec<T>,optvec<T>,optvec<T>,Ts,Tstr>
 +    :public statistic<optvec<T>,optvec<T>,optvec<T>,Ts,Tstr>
 +  {
 +  private:
 +    bool verb;
 +    int n;
 +    
 +    typedef optvec<T> Tx;
 +    typedef optvec<T> Ty;
 +    typedef optvec<T> Tp;
 +    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);
 +    }
 +
 +    const char* do_get_type_name()const
 +    {
 +      return "least square statistic";
 +    }
 +    
 +  public:
 +    void verbose(bool v)
 +    {
 +      verb=v;
 +    }
 +  public:
 +    leastsq()
 +      :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(0).get_y().size());
 +	  for(int j=0;j<chi.size();++j)
 +	    {
 +	      Ty model_y(eval_model(this->get_data_set().get_data(i).get_x(),p));
 +	      if(model_y[j]>this->get_data_set().get_data(i).get_y()[j])
 +		{
 +		  chi[j]=(this->get_data_set().get_data(i).get_y()[j]-model_y[j]);
 +		}
 +	      else
 +		{
 +		  chi[j]=(this->get_data_set().get_data(i).get_y()[j]-model_y[j]);
 +		}
 +	    }
 +	  result+=sum(chi*chi);
 +	  
 +	}
 +      return result;
 +    }
 +  };
 +  
 +
  }
 +
 +
  #endif
  //EOF
 | 
