Commit aff6b29a authored by Laurent Belcour's avatar Laurent Belcour

Adding the load of files for bootstrap

parents c360c8e2 94a6cfff
......@@ -124,23 +124,23 @@ class data_params : public data
save(std::string("cluster.gnuplot"));
}
virtual vec value(vec in, vec out) const
virtual vec value(vec, vec) const
{
NOT_IMPLEMENTED();
}
virtual vec value(vec in) const
virtual vec value(vec) const
{
NOT_IMPLEMENTED();
}
// Load data from a file
virtual void load(const std::string& filename)
virtual void load(const std::string&)
{
std::cerr << "<<ERROR>> this data type cannot load data" << std::endl;
throw;
}
virtual void load(const std::string& filename, const arguments& args)
virtual void load(const std::string&, const arguments&)
{
std::cerr << "<<ERROR>> this data type cannot load data" << std::endl;
throw;
......
#include "function.h"
#include "common.h"
#include "plugins_manager.h"
void function::bootstrap(const data*, const arguments& args)
{
// If the bootstrap option contains a filename, load it
if(args.is_defined("bootstrap") && !args["bootstrap"].empty())
{
std::ifstream in(args["bootstrap"].c_str());
if(in.is_open())
{
load(in);
}
}
}
// Acces to the domain of definition of the function
void function::setMin(const vec& min)
{
#ifdef DEBUG
assert(min.size() == _nX) ;
#endif
_min = min ;
}
void function::setMax(const vec& max)
{
#ifdef DEBUG
assert(max.size() == _nX) ;
#endif
_max = max ;
}
vec function::getMin() const
{
return _min ;
}
vec function::getMax() const
{
return _max ;
}
void function::save(const std::string& filename, const arguments& args) const
{
......@@ -97,7 +135,7 @@ void function::save_header(std::ostream& out, const arguments& args) const
//! \brief save function specific data. This has no use for ALTA export
//! but allows to factorize the code in the C++ or matlab export by
//! defining function calls that are common to all the plugins.
void function::save_body(std::ostream& out, const arguments& args) const
void function::save_body(std::ostream&, const arguments&) const
{
......@@ -106,7 +144,7 @@ void function::save_body(std::ostream& out, const arguments& args) const
//! \brief save object specific information. For an ALTA export the
//! coefficients will be exported. For a C++ or matlab export, the call
//! to the associated function will be done.
void function::save_call(std::ostream& out, const arguments& args) const
void function::save_call(std::ostream&, const arguments&) const
{
}
......@@ -172,3 +210,49 @@ vec nonlinear_function::getParametersMin() const
}
return m;
}
void compound_function::bootstrap(const ::data* d, const arguments& args)
{
const bool global_bootstrap = args.is_defined("bootstrap");
// Check if the bootstrap is global
if(global_bootstrap)
{
if(args.is_vec("bootstrap"))
{
vec p = args.get_vec("bootstrap", nbParameters());
setParameters(p);
}
else
{
std::ifstream file;
file.open(args["bootstrap"].c_str()) ;
if(file.is_open())
{
// Skip the header
std::string line ;
do
{
std::getline(file, line) ;
}
while(line != "#ALTA HEADER END");
// Load the file
this->load(file);
}
else
{
std::cerr << "<<ERROR>> you must provide a vector of parameters or a file to load with the bootstrap" << std::endl;
}
}
}
// Per function bootstrap
for(unsigned int i=0; i<fs.size(); ++i)
{
if(!global_bootstrap)
{
fs[i]->bootstrap(d, fs_args[i]);
}
}
}
......@@ -37,8 +37,8 @@ class function : public parametrized
//!
//! \details
//! Can be used to set the diffuse component of the function for
//! example.
virtual void bootstrap(const data* d, const arguments& args) {}
//! example. The default behaviour is to load a function file.
virtual void bootstrap(const data*, const arguments& args);
//! Provide the dimension of the input space of the function
virtual int dimX() const { return _nX ; }
......@@ -50,23 +50,20 @@ class function : public parametrized
//! Set the dimension of the output space of the function
virtual void setDimY(int nY) { _nY = nY ; }
// 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 ; }
virtual vec getMax() const { return _max ; }
/* DEFINITION DOMAIN OF THE FUNCTION */
//! \brief Set the minimum value the input can take
virtual void setMin(const vec& min) ;
//! \brief Set the maximum value the input can take
virtual void setMax(const vec& max) ;
//! \brief Get the minimum value the input can take
virtual vec getMin() const ;
//! \brief Get the maximum value the input can take
virtual vec getMax() const ;
/* EXPORT FUNCTIONS */
......@@ -260,7 +257,10 @@ class compound_function: public nonlinear_function
}
//! Provide a vector like interface
virtual void push_back(nonlinear_function* f)
//! This function allows to put a new nonlinear function \a f in the
//! compound object. This function will be processed for nonlinear
//! optimisation only if \a fixed equals true.
virtual void push_back(nonlinear_function* f, const arguments& f_args)
{
// Update the input param
if(input_parametrization() == params::UNKNOWN_INPUT)
......@@ -284,6 +284,8 @@ class compound_function: public nonlinear_function
}
fs.push_back(f);
fs_args.push_back(f_args);
is_fixed.push_back(f_args.is_defined("fixed"));
}
//! \brief Access to the i-th function of the compound
......@@ -311,13 +313,26 @@ class compound_function: public nonlinear_function
}
//! \brief Provide a first rough fit of the function.
virtual void bootstrap(const ::data* d, const arguments& args)
{
for(unsigned int i=0; i<fs.size(); ++i)
{
fs[i]->bootstrap(d, args);
}
}
//! For compound object, you can define the first guess using the
//! either the global function or using the individual command per
//! function. <br />
//!
//! <u>Examples:</u><br />
//! \verbatim
//! --func [libfunc1.so, libfunc2.so] --bootstrap first_guess.brdf
//! \endverbatim
//! Will load the file <em>first_guess.brdf</em> as the initial value
//! <br />
//! \verbatim
//! --func [libfunc1.so --boostrap [val1, val2], libfunc2.so --bootstrap first_guess1.brdf]
//! \endverbatim
//! Will load the vector of parameters <em>[val1, val2]</em> for the
//! first function and the file <em>first_guess1.brdf</em> for the
//! second one. <br />
//!
//! <u>Local/Global policy:</u></br />
//! Local bootstrap can not overload the global bootstrap.
virtual void bootstrap(const ::data* d, const arguments& args);
//! Set the dimension of the input space of the function
virtual void setDimX(int nX)
......@@ -362,7 +377,9 @@ class compound_function: public nonlinear_function
int nb_params = 0;
for(unsigned int i=0; i<fs.size(); ++i)
{
nb_params += fs[i]->nbParameters();
if(!is_fixed[i]) {
nb_params += fs[i]->nbParameters();
}
}
return nb_params;
}
......@@ -377,7 +394,7 @@ class compound_function: public nonlinear_function
int f_size = fs[f]->nbParameters();
// Handle when there is no parameters to include
if(f_size > 0)
if(f_size > 0 && !is_fixed[f])
{
vec f_params = fs[f]->parameters();
for(int i=0; i<f_size; ++i)
......@@ -402,7 +419,7 @@ class compound_function: public nonlinear_function
int f_size = fs[f]->nbParameters();
// Handle when there is no parameters to include
if(f_size > 0)
if(f_size > 0 && !is_fixed[f])
{
vec f_params = fs[f]->getParametersMin();
for(int i=0; i<f_size; ++i)
......@@ -427,7 +444,7 @@ class compound_function: public nonlinear_function
int f_size = fs[f]->nbParameters();
// Handle when there is no parameters to include
if(f_size > 0)
if(f_size > 0 && !is_fixed[f])
{
vec f_params = fs[f]->getParametersMax();
for(int i=0; i<f_size; ++i)
......@@ -451,7 +468,7 @@ class compound_function: public nonlinear_function
int f_size = fs[f]->nbParameters();
// Handle when there is no parameters to include
if(f_size > 0)
if(f_size > 0 && !is_fixed[f])
{
vec f_params(f_size);
for(int i=0; i<f_params.size(); ++i)
......@@ -489,7 +506,7 @@ class compound_function: public nonlinear_function
int nb_f_params = func->nbParameters();
// Only export Jacobian if there are non-linear parameters
if(nb_f_params > 0)
if(nb_f_params > 0 && !is_fixed[f])
{
vec temp_x(func->dimX());
......@@ -503,9 +520,9 @@ class compound_function: public nonlinear_function
jac[y*nb_params + (i+start_i)] = func_jac[y*nb_f_params + i];
}
}
}
start_i += nb_f_params;
start_i += nb_f_params;
}
}
return jac;
......@@ -589,6 +606,8 @@ class compound_function: public nonlinear_function
protected:
std::vector<nonlinear_function*> fs;
std::vector<arguments> fs_args;
std::vector<bool> is_fixed;
};
......
......@@ -69,7 +69,7 @@ template<typename T> T open_library(const std::string& filename, const char* fun
// Create the object, parse the argument and load all the plugins
plugins_manager::plugins_manager(const arguments& args)
plugins_manager::plugins_manager(const arguments&)
{
/*
QDir pluginsDir;
......@@ -299,7 +299,7 @@ function* plugins_manager::get_function(const arguments& args)
}
else
{
compound->push_back(dynamic_cast<nonlinear_function*>(f));
compound->push_back(dynamic_cast<nonlinear_function*>(f), temp_args);
}
}
......@@ -417,7 +417,7 @@ fitter* plugins_manager::get_fitter(const std::string& n)
}
void plugins_manager::check_compatibility(data*& d, function*& f,
const arguments& args)
const arguments&)
{
if(d->input_parametrization() == params::UNKNOWN_INPUT &&
f->input_parametrization() == params::UNKNOWN_INPUT)
......
......@@ -24,7 +24,7 @@ rational_function_1d::rational_function_1d(const vec& a,
{
}
void rational_function_1d::load(std::istream& in)
void rational_function_1d::load(std::istream&)
{
}
......@@ -443,7 +443,7 @@ void rational_function::load(std::istream& in)
}
//! \todo it should handle parametrization
void rational_function::save_matlab(const std::string& filename, const arguments& args) const
void rational_function::save_matlab(const std::string& filename, const arguments&) const
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
......@@ -538,7 +538,7 @@ void rational_function::save_matlab(const std::string& filename, const arguments
}
//! \todo it should handle parametrization
void rational_function::save_cpp(const std::string& filename, const arguments& args) const
void rational_function::save_cpp(const std::string& filename, const arguments&) const
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
......@@ -651,7 +651,7 @@ void rational_function::save_cpp(const std::string& filename, const arguments& a
}
void rational_function::save_gnuplot(const std::string& filename, const data* d, const arguments& args) const
void rational_function::save_gnuplot(const std::string& filename, const data* d, const arguments&) const
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
......@@ -672,7 +672,7 @@ void rational_function::save_gnuplot(const std::string& filename, const data* d,
file.close();
}
void rational_function::save_call(std::ostream& out, const arguments& args) const
void rational_function::save_call(std::ostream& out, const arguments&) const
{
out << "#FUNC rational_function" << std::endl;
out << "#NP " << np << std::endl ;
......
......@@ -33,11 +33,11 @@ class vertical_segment : public data
// Acces to data
virtual vec get(int i) const ;
virtual vec operator[](int i) const ;
virtual vec value(vec in, vec out) const
virtual vec value(vec, vec) const
{
NOT_IMPLEMENTED();
}
virtual vec value(vec in) const
virtual vec value(vec) const
{
NOT_IMPLEMENTED();
}
......
......@@ -43,10 +43,22 @@ void blinn_function::load(std::istream& in)
// Checking for the comment line #FUNC nonlinear_function_blinn
std::string token;
in >> token;
if(token != "#FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
if(token != "#FUNC")
{
std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl;
#ifndef DEBUG
std::cerr << "<<ERROR>> got \"" << token << "\"" << std::endl;
#endif
}
in >> token;
if(token != "nonlinear_function_blinn") { std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl; }
if(token != "nonlinear_function_blinn")
{
std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl;
#ifndef DEBUG
std::cerr << "<<ERROR>> got \"" << token << "\"" << std::endl;
#endif
}
// ks [double]
// N [double]
......
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