rational_1d_fitter.h 1.91 KB
Newer Older
1 2 3 4 5 6 7 8
#pragma once

// Include STL
#include <functional>
#include <vector>
#include <string>
#include <tuple>

9
class rational_1d : public std::function<double(double)> 
10 11 12 13
{
	public: // methods

		rational_1d() ;
14
		rational_1d(const std::vector<double>& a, const std::vector<double>& b) ;
15 16 17
		virtual ~rational_1d() ;

		// Overload the function operator
18
		virtual double operator()(double x) const ;
19 20

		// Get the p_i and q_j function
21 22
		virtual double p(double x, int i) const ;
		virtual double q(double x, int j) const ;
23 24 25 26 27 28 29 30 31 32 33 34

		// IO function to text files
		void load(const std::string& filename) ;
		void save() const ;

		// STL stream ouput
		friend std::ostream& operator<< (std::ostream& out, const rational_1d& r) ;

	private: // data

		// Store the coefficients for the moment, I assume
		// the functions to be polynomials.
35 36
		std::vector<double> a ;
		std::vector<double> b ;
37 38 39 40 41 42 43 44
} ;

class rational_1d_data // : public fitting_data
{
	public: // methods

		// Load data from a file
		void load(const std::string& filename) ;
45
		void load(const std::string& filename, double min, double max) ;
46 47

		// Acces to data
48 49
		bool get(int i, double& x, double& yl, double& yu) const ;
		const std::vector<double>& operator[](int i) const ;
50 51 52 53 54

		// Get data size
		int size() const ;

		// Get min and max input parameters
55 56
		double min() const ;
		double max() const ; 
57 58 59 60 61

	private: // data

		// Store for each point of data, the upper
		// and lower value
62
		std::vector<std::vector<double> > _data ;
63 64 65

		// Store the min and max value on the input
		// domain
66
		double _min, _max ;
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
} ;

class rational_1d_fitter // : public fitting_algorithm
{
	public: // methods

		// Fitting a data object
		virtual bool fit_data(const rational_1d_data& data, rational_1d& fit) = 0;

		// Fitting a data object using np elements
		// in the numerator and nq elements in the
		// denominator
		virtual bool fit_data(const rational_1d_data& data, int np, int nq, rational_1d& fit) = 0;
} ;