diff options
Diffstat (limited to 'pre_estimater')
-rw-r--r-- | pre_estimater/lin1d_estimater.hpp | 52 | ||||
-rw-r--r-- | pre_estimater/pre_estimater.hpp | 120 |
2 files changed, 0 insertions, 172 deletions
diff --git a/pre_estimater/lin1d_estimater.hpp b/pre_estimater/lin1d_estimater.hpp deleted file mode 100644 index 0a76df3..0000000 --- a/pre_estimater/lin1d_estimater.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef LIN1D_ESTIMATER -#define LIN1D_ESTIMATER -#include "pre_estimater.hpp" -#include <misc/optvec.hpp> -#include <models/lin1d.hpp> -#include <vector> - -namespace opt_utilities -{ - template <typename T> - class lin1d_estimater - :public pre_estimater<T,T,std::vector<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<T,T>& d,model<T,T,std::vector<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(); - sxx+=d.get_data(i).get_x()*d.get_data(i).get_x(); - sx+=d.get_data(i).get_x(); - sxy+=d.get_data(i).get_x()*d.get_data(i).get_y(); - } - 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 diff --git a/pre_estimater/pre_estimater.hpp b/pre_estimater/pre_estimater.hpp deleted file mode 100644 index 859c5ca..0000000 --- a/pre_estimater/pre_estimater.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef PRE_ESTIMATER_HPP -#define PRE_ESTIMATER_HPP - -#include <core/fitter.hpp> - - -namespace opt_utilities -{ - - - template <typename Ty,typename Tx,typename Tp,typename Tstr=std::string> - class pre_estimater - { - private: - std::string model_id; - private: - virtual void do_estimate(const data_set<Ty,Tx>& d,model<Ty,Tx,Tp,Tstr>& m)const=0; - virtual pre_estimater* do_clone()const=0; - virtual void do_destroy() - { - delete this; - } - public: - void estimate(const data_set<Ty,Tx>& d,model<Ty,Tx,Tp,Tstr>& m)const - { - do_estimate(d,m); - } - - pre_estimater* clone()const - { - return this->do_clone(); - } - - void destroy() - { - do_destroy(); - } - public: - std::string get_model_id()const - { - return model_id; - } - - void set_model_id(const std::string& s) - { - model_id=s; - } - }; - - template <typename Ty,typename Tx,typename Tp,typename Tstr=std::string> - class pre_estimatable - { - private: - pre_estimater<Ty,Tx,Tp,Tstr>* ppe; - public: - pre_estimatable() - :ppe(0) - {} - - pre_estimatable(const pre_estimatable<Ty,Tx,Tp,Tstr>& rhs) - { - if(rhs.ppe) - { - ppe=rhs.ppe->clone(); - } - } - - pre_estimatable& operator=(const pre_estimatable<Ty,Tx,Tp,Tstr>& rhs) - { - if(this==&rhs) - { - return *this; - } - if(ppe) - { - ppe->destroy(); - } - ppe=rhs.ppe->clone(); - } - - void set_pre_estimater(const pre_estimater<Ty,Tx,Tp,Tstr>& pe) - { - if(dynamic_cast<model<Ty,Tx,Tp,Tstr>&>(*this).get_type_name()!=pe.get_model_id()) - { - return; - } - if(ppe) - { - ppe->destroy(); - } - ppe=pe.clone(); - } - - virtual ~pre_estimatable() - { - if(ppe) - { - ppe->destroy(); - } - } - - public: - void estimate(const data_set<Ty,Tx>& d) - { - if(ppe) - { - ppe->estimate(d,dynamic_cast<model<Ty,Tx,Tp,Tstr>&>(*this)); - } - } - }; - - template <typename Ty,typename Tx,typename Tp,typename Ts,typename Tstr> - void pre_estimate(fitter<Ty,Tx,Tp,Ts,Tstr>& fit) - { - dynamic_cast<pre_estimatable<Ty,Tx,Tp,Tstr>&>(fit.get_model()).estimate(fit.get_data_set()); - } -} - - -#endif |