Commit fe046f36 authored by Laurent Belcour's avatar Laurent Belcour

Fixing some bugs in the product function

parent 93b8e937
......@@ -372,7 +372,16 @@ void compound_function::bootstrap(const ::data* d, const arguments& args)
if(args.is_vec("bootstrap"))
{
vec p = args.get_vec("bootstrap", nbParameters());
std::cout << "<<INFO>> Will use " << p << " as a bootstrap for the non-linear function" << std::endl;
setParameters(p);
for(unsigned int i=0; i<fs.size(); ++i)
{
if(fs[i]->nbParameters() == 0)
{
fs[i]->bootstrap(d, fs_args[i]);
}
}
}
else
{
......@@ -657,7 +666,7 @@ void product_function::setParameters(const vec& p)
vec f2_params(nb_f2_params);
for(int i=0; i<nb_f2_params; ++i)
{
f2_params[i] = p[i+nb_f2_params];
f2_params[i] = p[i+nb_f1_params];
}
f2->setParameters(f2_params);
}
......@@ -720,8 +729,8 @@ vec product_function::parametersJacobian(const vec& x) const
vec xf(f2->dimX());
params::convert(&x[0], f1->input_parametrization(), f2->input_parametrization(), &xf[0]);
vec f1_jacobian = f1->parametersJacobian(xf);
vec f2_jacobian = f2->parametersJacobian(x);
vec f1_jacobian = f1->parametersJacobian(x);
vec f2_jacobian = f2->parametersJacobian(xf);
vec f1_value = f1->value(x);
vec f2_value = f2->value(xf);
......
......@@ -324,6 +324,7 @@ std::string params::get_name(const params::input param)
return it->second.name;
}
std::cerr << "<<ERROR>> Unknown parametrization, " << get_name(param) << " " << __FILE__ << ":" << __LINE__ << std::endl;
return std::string("UNKNOWN_INPUT");
}
......
......@@ -150,39 +150,47 @@ bool nonlinear_fitter_nlopt::fit_data(const data* d, function* fit, const argume
nlopt_algorithm algorithm;
nlopt_result res;
std::string optimizerName = args["nlopt-optimizer"];
if(optimizerName == "COBYLA")
if(optimizerName == "local-COBYLA")
{
algorithm = NLOPT_LN_COBYLA;
}
else if(optimizerName == "BOBYQA")
else if(optimizerName == "local-BOBYQA")
{
algorithm = NLOPT_LN_BOBYQA;
}
else if(optimizerName == "NEWUOA")
else if(optimizerName == "local-NEWUOA")
{
algorithm = NLOPT_LN_NEWUOA_BOUND;
}
else if(optimizerName == "PRAXIS")
else if(optimizerName == "local-PRAXIS")
{
algorithm = NLOPT_LN_PRAXIS;
}
else if(optimizerName == "Nelder-Mead")
else if(optimizerName == "local-Nelder-Mead")
{
algorithm = NLOPT_LN_NELDERMEAD;
}
else if(optimizerName == "Sbplx")
else if(optimizerName == "local-spblx")
{
algorithm = NLOPT_LN_SBPLX;
}
else if(optimizerName == "controlled-random-search")
else if(optimizerName == "global-crs")
{
algorithm = NLOPT_GN_CRS2_LM;
}
else if(optimizerName == "MMA")
else if(optimizerName == "global-stogo")
{
algorithm = NLOPT_GD_STOGO;
}
else if(optimizerName == "global-isres")
{
algorithm = NLOPT_GN_ISRES;
}
else if(optimizerName == "local-mma")
{
algorithm = NLOPT_LD_MMA;
}
else if(optimizerName == "SQP")
else if(optimizerName == "local-sqp")
{
algorithm = NLOPT_LD_SLSQP;
}
......
......@@ -14,11 +14,14 @@ ALTA_DLL_EXPORT function* provide_function()
return new schlick();
}
schlick::schlick()
{
setParametrization(params::CARTESIAN);
}
//! Load function specific files
bool schlick::load(std::istream& in)
{
fresnel::load(in);
// Parse line until the next comment
while(in.peek() != '#')
{
......@@ -59,15 +62,6 @@ void schlick::save_call(std::ostream& out, const arguments& args) const
{
bool is_alta = !args.is_defined("export") || args["export"] == "alta";
if(is_alta)
{
f->save_call(out, args);
}
else
{
out << "("; f->save_call(out, args); out << ")";
}
if(is_alta)
{
out << "#FUNC nonlinear_fresnel_normalized_schlick" << std::endl ;
......@@ -79,7 +73,7 @@ void schlick::save_call(std::ostream& out, const arguments& args) const
}
else
{
out << " * normalized_schlick_fresnel(L, V, N, X, Y, vec3(";
out << "normalized_schlick_fresnel(L, V, N, X, Y, vec3(";
for(int i=0; i<dimY(); ++i)
{
out << R[i];
......@@ -91,7 +85,6 @@ void schlick::save_call(std::ostream& out, const arguments& args) const
void schlick::save_body(std::ostream& out, const arguments& args) const
{
f->save_body(out, args);
bool is_shader = args["export"] == "shader" || args["export"] == "explorer";
if(is_shader)
......@@ -107,7 +100,7 @@ void schlick::save_body(std::ostream& out, const arguments& args) const
}
vec schlick::fresnelValue(const vec& x) const
vec schlick::value(const vec& x) const
{
double xp[3], cart[6];
params::convert(&x[0], input_parametrization(), params::RUSIN_VH, xp);
......@@ -125,12 +118,12 @@ vec schlick::fresnelValue(const vec& x) const
}
//! \brief Number of parameters to this non-linear function
int schlick::nbFresnelParameters() const
int schlick::nbParameters() const
{
return dimY();
}
vec schlick::getFresnelParametersMin() const
vec schlick::parametersMin() const
{
vec m(dimY());
for(int i=0; i<dimY(); ++i) { m[i] = 1.0; }
......@@ -138,7 +131,7 @@ vec schlick::getFresnelParametersMin() const
}
//! \brief Get the vector of parameters for the function
vec schlick::getFresnelParameters() const
vec schlick::parameters() const
{
vec p(dimY());
for(int i=0; i<dimY(); ++i) { p[i] = R[i]; }
......@@ -146,14 +139,14 @@ vec schlick::getFresnelParameters() const
}
//! \brief Update the vector of parameters for the function
void schlick::setFresnelParameters(const vec& p)
void schlick::setParameters(const vec& p)
{
for(int i=0; i<dimY(); ++i) { R[i] = p[i]; }
}
//! \brief Obtain the derivatives of the function with respect to the
//! parameters.
vec schlick::getFresnelParametersJacobian(const vec& x) const
vec schlick::parametersJacobian(const vec& x) const
{
const int nY = dimY();
double xp[3], cart[6];
......@@ -179,7 +172,7 @@ vec schlick::getFresnelParametersJacobian(const vec& x) const
}
void schlick::fresnelBootstrap(const data* d, const arguments& args)
void schlick::bootstrap(const data* d, const arguments& args)
{
for(int i=0; i<dimY(); ++i) { R[i] = 1.0; }
}
......@@ -12,50 +12,54 @@
#include <core/common.h>
class schlick : public fresnel
class schlick : public nonlinear_function
{
public: // methods
// Constructor
schlick();
//! \brief Load function specific files
virtual bool load(std::istream& in) ;
virtual bool load(std::istream& in) ;
virtual void save_call(std::ostream& out, const arguments& args) const;
virtual void save_body(std::ostream& out, const arguments& args) const;
protected: // methods
virtual vec fresnelValue(const vec& x) const;
virtual vec operator()(const vec& x) const { return value(x); }
virtual vec value(const vec& x) const;
//! \brief Number of parameters to this non-linear function
virtual int nbFresnelParameters() const ;
virtual int nbParameters() const ;
//! \brief Get the vector of parameters for the function
virtual vec getFresnelParameters() const ;
virtual vec parameters() const ;
//! \brief Update the vector of parameters for the function
virtual void setFresnelParameters(const vec& p) ;
virtual void setParameters(const vec& p) ;
//! Get the vector of min parameters for the function
virtual vec getFresnelParametersMin() const;
virtual vec parametersMin() const;
//! \brief Obtain the derivatives of the function with respect to the
//! parameters.
virtual vec getFresnelParametersJacobian(const vec& x) const ;
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Boostrap the function by defining the diffuse term
virtual void fresnelBootstrap(const data* d, const arguments& args);
virtual void bootstrap(const data* d, const arguments& args);
//! \brief resize the parameter vector
virtual void setDimY(int nY)
{
fresnel::setDimY(nY);
R.resize(nY);
}
//! \brief resize the parameter vector
virtual void setDimY(int nY)
{
nonlinear_function::setDimY(nY);
R.resize(nY);
}
private: // data
//! Unidimensional Fresnel reflectance at theta = 0
vec R;
vec R;
} ;
......@@ -11,11 +11,11 @@ SUBDIRS = \
rational_function_chebychev \
rational_function_legendre \
nonlinear_fitter_eigen \
# nonlinear_fitter_ceres \
# nonlinear_fitter_ipopt \
# nonlinear_fitter_nlopt \
nonlinear_fitter_ceres \
nonlinear_fitter_ipopt \
nonlinear_fitter_nlopt \
nonlinear_fresnel_schlick \
# nonlinear_fresnel_normalized_schlick \
nonlinear_fresnel_normalized_schlick \
nonlinear_fresnel_retroschlick \
nonlinear_function_diffuse \
nonlinear_function_blinn \
......
......@@ -11,10 +11,18 @@
#include <limits>
#include <cstdlib>
#ifdef __linux__
#include <fenv.h>
#endif
int main(int argc, char** argv)
{
arguments args(argc, argv) ;
#ifdef __linux__
//feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
#endif
fitter* fit = plugins_manager::get_fitter(args["fitter"]) ;
if(fit == NULL)
{
......
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