Commit fe29c616 authored by PACANOWSKI Romain's avatar PACANOWSKI Romain
Browse files

Merging three branches

parents f62d7b68 4ae204f6
......@@ -9,6 +9,8 @@
/*! \brief A useful class for storing the high-level arguments of a program
* or a function.
* \ingroup core
* \internal
*
* The set of parameters are parsed from the command line using the
* constructor. They are stored as std::string in a std::map.
......@@ -75,7 +77,7 @@ class arguments
}
else
{
std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
//std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
return std::string() ;
}
} ;
......
......@@ -5,12 +5,14 @@
#include <cassert>
#include <cmath>
/*! \brief A core implementation of a vector of double.
/*! \brief A core implementation of a vector of double.
* \ingroup core
* \internal
*
* \details
* This type is used for any transmission of vector data with unfixed
* dimension. It allows to have a generic fitter working for
* n-Dimensional data.
* \details
* This type is used for any transmission of vector data with unfixed
* dimension. It allows to have a generic fitter working for
* n-Dimensional data.
*/
class vec : public std::vector<double>
{
......@@ -22,11 +24,23 @@ class vec : public std::vector<double>
}
vec(int dim) : std::vector<double>(dim)
{
assign(dim, 0.0) ;
} ;
assign(dim, 0.0) ;
}
virtual ~vec()
{
} ;
}
//! \brief copy operator. It resize the left operand to the size of the
//! right operand.
vec operator=(const vec& a)
{
this->resize(a.size());
for(unsigned int i=0; i<a.size(); ++i)
{
this->at(i) = a[i];
}
return *this ;
}
// Mathematical operators
//
......
......@@ -11,7 +11,8 @@ HEADERS = args.h \
function.h \
plugins_manager.h \
vertical_segment.h \
rational_function.h
rational_function.h \
params.h
SOURCES = plugins_manager.cpp \
vertical_segment.cpp \
......
......@@ -7,7 +7,9 @@
#include "common.h"
#include "args.h"
/*!
#include "params.h"
/*! \brief A data object. Allows to load data from files.
* \ingroup core
*/
class data
......@@ -42,3 +44,54 @@ class data
} ;
Q_DECLARE_INTERFACE(data, "Fitter.Data")
/*! \brief Change the parametrization of data to fit the parametrization of the
* function to be fitted.
*
* \ingroup core
* \internal
*/
class data_params : public data
{
public:
// Load data from a file
virtual void load(const std::string& filename)
{
_d->load(filename);
}
virtual void load(const std::string& filename, const arguments& args)
{
_d->load(filename, args);
}
// Acces to data
virtual vec get(int i) const
{
return _d->get(i);
}
virtual vec operator[](int i) const
{
return (*_d)[i];
}
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
return _d->size();
}
// Get min and max input space values
virtual vec min() const
{
return _d->min();
}
virtual vec max() const
{
return _d->max();
}
protected:
// data object to interface
data* _d;
};
......@@ -15,19 +15,19 @@ class fitter
{
public:
// Static function to fit a data set d with the
// underling function class. Return the best
// fit (along with fitting information ?)
//
virtual bool fit_data(const data* d, function* f) = 0 ;
//! \brief static function to fit a data set d with the underling
//! function class. Return the best fit (along with fitting
//! information ?)
virtual bool fit_data(const data* d, function* f, const arguments& args) = 0 ;
virtual void set_parameters(const arguments& args) = 0 ;
/*
// Provide a function class and a data class
//
virtual data* provide_data() const = 0 ;
virtual function* provide_function() const = 0 ;
*/
} ;
Q_DECLARE_INTERFACE(fitter, "Fitter.Fitter")
......@@ -49,12 +49,16 @@ class function
// Acces to the domain of definition of the function
virtual void setMin(const vec& min)
{
#ifdef DEBUG
assert(min.size() == _nX) ;
#endif
_min = min ;
}
virtual void setMax(const vec& max)
{
#ifdef DEBUG
assert(max.size() == _nX) ;
#endif
_max = max ;
}
virtual vec getMin() const { return _min ; }
......
#pragma once
#include "data.h"
/*! \brief a static class allowing to change from one parametrization
* to another.
* \ingroup core
*
* \details
* Any \typedef function object or \typedef data object should have
* an associated parametrization.
*/
class params
{
//! \brief list of all supported parametrization. An unsupported
//! parametrization will go under the name <em>unknown</em>.
enum type
{
unknown
};
//! \brief static function for input type convertion.
static vec convert(const vec& invec, params::type intype, params::type outtype)
{
return invec;
}
};
......@@ -5,6 +5,7 @@
#include <QCoreApplication>
#include <QPluginLoader>
#include <QtPlugin>
#include <QLibrary>
#include <QDir>
// Create the object, parse the argument and load
......@@ -78,12 +79,22 @@ plugins_manager::plugins_manager(const arguments& args)
}
}
#define USING_STATIC
#ifdef USING_STATIC
typedef function* (*FunctionPrototype)();
typedef fitter* (*FitterPrototype)();
typedef data* (*DataPrototype)();
#endif
// Get instances of the function, the data and the
// fitter
//
function* plugins_manager::get_function() const
function* plugins_manager::get_function()
{
if(_functions.empty())
#ifdef USING_STATIC
return new rational_function() ;
#else
if(_functions.empty())
{
return new rational_function() ;
}
......@@ -91,17 +102,23 @@ function* plugins_manager::get_function() const
{
return _functions.begin()->second ;
}
#endif
}
data* plugins_manager::get_data() const
{
//if(_datas.empty())
{
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
#ifdef DEBUG
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
#endif
return new vertical_segment() ;
}/*
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << _datas.begin()->first << "\" data loader" << std::endl ;
#endif
return _datas.begin()->second ;
}*/
}
......@@ -113,17 +130,45 @@ fitter* plugins_manager::get_fitter() const
}
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << _fitters.begin()->first << "\"" << std::endl ;
#endif
return _fitters.begin()->second ;
}
}
// Get instances of the function, the data and the
// fitter, select one based on the name. Return null
// if no one exist.
//
function* plugins_manager::get_function(const std::string& n) const
function* plugins_manager::get_function(const std::string& n)
{
if(n.empty())
{
#ifdef DEBUG
std::cout << "<<DEBUG>> no function plugin specified, returning a rational function" << std::endl;
#endif
return new rational_function();
}
#ifdef USING_STATIC
FunctionPrototype myFunction = (FunctionPrototype) QLibrary::resolve(QString(n.c_str()), "_Z16provide_functionv");
if(myFunction != NULL)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using function provider in file \"" << n << "\"" << std::endl;
#endif
return myFunction();
}
else
{
std::cerr << "<<ERROR>> no function provider found in file \"" << n << "\"" << std::endl;
return new rational_function() ;
}
#else
if(_functions.count(n) == 0)
{
return new rational_function() ;
......@@ -132,19 +177,44 @@ function* plugins_manager::get_function(const std::string& n) const
{
return _functions.find(n)->second ;
}
#endif
}
data* plugins_manager::get_data(const std::string& n) const
data* plugins_manager::get_data(const std::string& n)
{
if(_datas.count(n) == 0)
{
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
return new vertical_segment() ;
}
else
{
std::cout << "<<DEBUG>> using \"" << n << "\" data loader" << std::endl ;
return _datas.find(n)->second ;
}
if(n.empty())
{
#ifdef DEBUG
std::cout << "<<DEBUG>> no data plugin specified, returning a vertial_segment loader" << std::endl;
#endif
return new vertical_segment();
}
#ifdef USING_STATIC
DataPrototype myData = (DataPrototype) QLibrary::resolve(QString(n.c_str()), "_Z16provide_datav");
if(myData != NULL)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using function provider in file \"" << n << "\"" << std::endl;
#endif
return myData();
}
else
{
std::cerr << "<<ERROR>> no data provider found in file \"" << n << "\"" << std::endl;
return new vertical_segment() ;
}
#else
if(_functions.count(n) == 0)
{
return new vertical_segment() ;
}
else
{
return _datas.find(n)->second ;
}
#endif
}
fitter* plugins_manager::get_fitter(const std::string& n) const
{
......@@ -154,7 +224,9 @@ fitter* plugins_manager::get_fitter(const std::string& n) const
}
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << n << "\"" << std::endl ;
#endif
return _fitters.find(n)->second ;
}
}
......
......@@ -25,14 +25,14 @@ class plugins_manager
//! \brief Get instances of the function, the data and the fitter. Select
//! the first in the map,
function* get_function() const ;
static function* get_function() ;
data* get_data() const ;
fitter* get_fitter() const ;
//! \brief Get instances of the function, the data and the fitter, select one
//! based on the name. Return null if no one exist.
function* get_function(const std::string& n) const ;
data* get_data(const std::string& n) const ;
static function* get_function(const std::string& n) ;
static data* get_data(const std::string& n) ;
fitter* get_fitter(const std::string& n) const ;
//! \brief Provide a measure of how much memory there is on the system.
......
......@@ -8,10 +8,15 @@
#include <algorithm>
#include <cmath>
rational_function::rational_function() : a(), b()
{
}
rational_function::rational_function(int np, int nq) : a(np), b(nq)
{
}
rational_function::rational_function(const std::vector<double>& a,
const std::vector<double>& b) :
a(a), b(b)
......
......@@ -20,6 +20,7 @@ class rational_function : public QObject, public function
public: // methods
rational_function() ;
rational_function(int np, int nq) ;
rational_function(const std::vector<double>& a, const std::vector<double>& b) ;
virtual ~rational_function() ;
......@@ -72,4 +73,3 @@ class rational_function : public QObject, public function
std::vector<double> a ;
std::vector<double> b ;
} ;
......@@ -56,7 +56,7 @@ void vertical_segment::load(const std::string& filename, const arguments& args)
_min.resize(dimX()) ;
_max.resize(dimX()) ;
min = args.get_vec("min", _nX, -std::numeric_limits<double>::max()) ;
max = args.get_vec("max", _nX, std::numeric_limits<double>::max()) ;
......@@ -79,8 +79,7 @@ void vertical_segment::load(const std::string& filename, const arguments& args)
continue ;
}
vec v ;
v.resize(dimX() + 3*dimY()) ;
vec v(dimX() + 3*dimY()) ;
for(int i=0; i<dimX(); ++i)
linestream >> v[i] ;
......
......@@ -59,7 +59,7 @@ nonlinear_fitter_eigen::~nonlinear_fitter_eigen()
{
}
bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit)
bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit, const arguments &args)
{
// I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem
......
......@@ -28,7 +28,7 @@ class nonlinear_fitter_eigen: public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -38,7 +38,7 @@ rational_fitter_cgal::~rational_fitter_cgal()
{
}
bool rational_fitter_cgal::fit_data(const data* dat, function* fit)
bool rational_fitter_cgal::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -26,7 +26,7 @@ class rational_fitter_cgal : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -31,7 +31,7 @@ rational_fitter_dca::~rational_fitter_dca()
{
}
bool rational_fitter_dca::fit_data(const data* dat, function* fit)
bool rational_fitter_dca::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -26,7 +26,7 @@ class rational_fitter_dca : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -29,7 +29,7 @@ rational_fitter_eigen::~rational_fitter_eigen()
{
}
bool rational_fitter_eigen::fit_data(const data* dat, function* fit)
bool rational_fitter_eigen::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -25,7 +25,7 @@ class rational_fitter_eigen : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment