Commit 45d4cb58 authored by Laurent Belcour's avatar Laurent Belcour

Cleaned code of data2brdf & Export of L2 and Linf norm when fitting

parent 1e32f793
...@@ -130,6 +130,11 @@ class arguments ...@@ -130,6 +130,11 @@ class arguments
//std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ; //std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
return std::string() ; return std::string() ;
} }
}
//! \brief update the value \a val stored under key \a key
bool update(const std::string& key, const std::string& val)
{
_map[key] = val;
} }
//! \brief acces to the string value associated with the parameter //! \brief acces to the string value associated with the parameter
//! \a key. //! \a key.
......
...@@ -85,7 +85,10 @@ void function::save_header(std::ostream& out, const arguments& args) const ...@@ -85,7 +85,10 @@ void function::save_header(std::ostream& out, const arguments& args) const
out << "#CMD " << args.get_cmd() << std::endl; out << "#CMD " << args.get_cmd() << std::endl;
out << "#DIM " << _nX << " " << _nY << std::endl; out << "#DIM " << _nX << " " << _nY << std::endl;
out << "#PARAM_IN " << params::get_name(input_parametrization()) << std::endl; out << "#PARAM_IN " << params::get_name(input_parametrization()) << std::endl;
//out << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl; //out << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl;*
if(args.is_defined("export-append")) {
out << args["export-append"] << std::endl;
}
out << "#ALTA HEADER END" << std::endl; out << "#ALTA HEADER END" << std::endl;
out << std::endl; out << std::endl;
} }
......
...@@ -20,167 +20,95 @@ ...@@ -20,167 +20,95 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
arguments args(argc, argv) ; arguments args(argc, argv) ;
plugins_manager manager(args) ; plugins_manager manager(args) ;
fitter* fit = manager.get_fitter(args["fitter"]) ; fitter* fit = manager.get_fitter(args["fitter"]) ;
if(fit == NULL) if(fit == NULL)
{ {
fit = manager.get_fitter() ; fit = manager.get_fitter() ;
} }
if(args.is_defined("available_params")) if(args.is_defined("available_params"))
{ {
params::print_input_params(); params::print_input_params();
return 0; return 0;
} }
if(! args.is_defined("input")) { if(! args.is_defined("input")) {
std::cerr << "<<ERROR>> the input filename is not defined" << std::endl ; std::cerr << "<<ERROR>> the input filename is not defined" << std::endl ;
return 1 ; return 1 ;
} }
if(! args.is_defined("output")) { if(! args.is_defined("output")) {
std::cerr << "<<ERROR>> the output filename is not defined" << std::endl ; std::cerr << "<<ERROR>> the output filename is not defined" << std::endl ;
return 1 ; return 1 ;
} }
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0) // if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
if(fit != NULL) if(fit != NULL)
{ {
fit->set_parameters(args) ; fit->set_parameters(args) ;
function* f = plugins_manager::get_function(args); function* f = plugins_manager::get_function(args);
data* d = plugins_manager::get_data(args["data"]); data* d = plugins_manager::get_data(args["data"]);
d->load(args["input"], args); d->load(args["input"], args);
if(f == NULL || d == NULL) if(f == NULL || d == NULL)
{ {
std::cerr << "<<ERROR>> no function or data object correctly defined" << std::endl; std::cerr << "<<ERROR>> no function or data object correctly defined" << std::endl;
return 1; return 1;
} }
// Check the compatibility between the data and the function // Check the compatibility between the data and the function
plugins_manager::check_compatibility(d, f, args); plugins_manager::check_compatibility(d, f, args);
// Start a timer // Start a timer
QTime time ; QTime time ;
time.start() ; time.start() ;
// Fit the data // Fit the data
bool is_fitted = fit->fit_data(d, f, args) ; bool is_fitted = fit->fit_data(d, f, args) ;
// Get the fitting duration // Get the fitting duration
int msec = time.elapsed() ; int msec = time.elapsed() ;
int sec = (msec / 1000) % 60 ; int sec = (msec / 1000) % 60 ;
int min = (msec / 60000) % 60 ; int min = (msec / 60000) % 60 ;
int hour = (msec / 3600000) ; int hour = (msec / 3600000) ;
// Display the result // Display the result
if(is_fitted) if(is_fitted)
{ {
std::cout << "<<INFO>> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ; std::cout << "<<INFO>> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ;
/*
vec min, max ; double L2 = f->L2_distance(d);
min.assign(2, args.get_float("min", 0.0f)) ; double Linf = f->Linf_distance(d);
max.assign(2, args.get_float("max", 1.5f)) ; std::cout << "<<INFO>> L2 distance to data = " << L2 << std::endl;
std::cout << "<<INFO>> Linf distance to data = " << Linf << std::endl;
int nb_samples = args.get_int("nb_samples", 100) ;
double dt = (max[0]-min[0]) / nb_samples ; std::stringstream append; // Append informations to the export
if(args.is_defined("export-append")) {
std::ofstream file(args["output"].c_str(), std::ios_base::trunc); append << args["export-append"];
for(double x=min[0]; x<=max[0]; x+=dt) }
{ append << "#L2 " << L2 << std::endl;
vec vx ; for(int i=0;i<2; ++i) { vx.push_back(x) ; } append << "#LINF " << Linf ;
file << x << "\t" << f->value(vx)[0] << std::endl ; args.update("export-append", append.str());
std::cout << x << "\t" << f->value(vx)[0] << std::endl ;
} f->save(args["output"], args) ;
/*/ return 0;
double L2 = f->L2_distance(d); }
double Linf = f->Linf_distance(d); else
std::cout << "<<INFO>> L2 distance to data = " << L2 << std::endl; {
std::cout << "<<INFO>> Linf distance to data = " << Linf << std::endl; std::cout << "<<ERROR>> unable to fit the data" << std::endl ;
return 1;
f->save(args["output"], args) ; }
#ifdef OLD // use brdf2gnuplot
size_t n = args["output"].find('.') ; }
std::string gnuplot_filename = args["output"].substr(0,n); else
gnuplot_filename.append(".gnuplot") ; {
/* std::cout << "<<ERROR>> no fitter loaded, please check your command line arguments" << std::endl ;
f->save_gnuplot(gnuplot_filename, d, args); }
/*/
std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc); return 0 ;
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
// vec y1(d->dimY()) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = f->value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u] << "\t" ;
file << std::endl ;
}
file.close();
//*/
std::string error_filename = args["output"].substr(0,n);
error_filename.append(".errorplot") ;
file.open(error_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = f->value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
}
file.close();
std::string linerror_filename = args["output"].substr(0,n);
linerror_filename.append(".linearerrorplot") ;
file.open(linerror_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = 0.5*(v[d->dimX() + k] +v[d->dimX()+d->dimY() + k]); }
vec y2 = f->value(v) ;
file << i << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
}
file.close();
//*/
#endif
return 0;
}
else
{
std::cout << "<<ERROR>> unable to fit the data" << std::endl ;
return 1;
}
}
else
{
std::cout << "<<ERROR>> no fitter loaded, please check your command line arguments" << std::endl ;
}
return 0 ;
} }
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