Commit 2dd48c33 authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Adding SGD function, up to the Jacobian which is missing.

parent 8d973601
...@@ -34,40 +34,72 @@ vec shifted_gamma_function::value(const vec& x) const ...@@ -34,40 +34,72 @@ vec shifted_gamma_function::value(const vec& x) const
if (n_l < 0.0) inLight = 0.0; if (n_l < 0.0) inLight = 0.0;
double n_v = dot(n, ev); double n_v = dot(n, ev);
return one_pi * inLight * (n_l * rho_d + rho_s * return one_pi * inLight * (n_l * rho_d + rho_s.cwiseProduct(D(alpha, p, n_h, K_ap)).cwiseProduct(G1(n_l)).cwiseProduct(G1 (n_v)).cwiseProduct(Fresnel(F_0, F_1, v_h)));
D(alpha, p, n_h, K_ap) * G1(n_l) * G1 (n_v) *
Fresnel(F_0, F_1, v_h));
}
//! Load function specific files
void shifted_gamma_function::load(const std::string& filename)
{
}
//! Save the current function to a specific file type
void shifted_gamma_function::save(const std::string& filename, const arguments& args) const
{
} }
//! Number of parameters to this non-linear function //! Number of parameters to this non-linear function
int shifted_gamma_function::nbParameters() const int shifted_gamma_function::nbParameters() const
{ {
return 11*dimY();
} }
//! Get the vector of parameters for the function //! Get the vector of parameters for the function
vec shifted_gamma_function::parameters() const vec shifted_gamma_function::parameters() const
{ {
const int n = dimY();
vec res(nbParameters());
for(int i=0; i<n; ++i) {
res[i + 0*n] = sh_c[i];
res[i + 1*n] = sh_theta0[i];
res[i + 2*n] = sh_k[i];
res[i + 3*n] = sh_lambda[i];
res[i + 4*n] = p[i];
res[i + 5*n] = F_0[i];
res[i + 6*n] = F_1[i];
res[i + 7*n] = K_ap[i];
res[i + 8*n] = rho_d[i];
res[i + 9*n] = rho_s[i];
res[i + 10*n] = alpha[i];
}
return res;
} }
//! Update the vector of parameters for the function //! Update the vector of parameters for the function
void shifted_gamma_function::setParameters(const vec& p) void shifted_gamma_function::setParameters(const vec& pi)
{ {
const int n = dimY();
for(int i=0; i<n; ++i) {
sh_c[i] = pi[i + 0*n];
sh_theta0[i] = pi[i + 1*n];
sh_k[i] = pi[i + 2*n];
sh_lambda[i] = pi[i + 3*n];
p[i] = pi[i + 4*n];
F_0[i] = pi[i + 5*n];
F_1[i] = pi[i + 6*n];
K_ap[i] = pi[i + 7*n];
rho_d[i] = pi[i + 8*n];
rho_s[i] = pi[i + 9*n];
alpha[i] = pi[i + 10*n];
}
} }
//! Obtain the derivatives of the function with respect to the //! Obtain the derivatives of the function with respect to the
//! parameters. //! parameters. \TODO
vec shifted_gamma_function::parametersJacobian(const vec& x) const vec shifted_gamma_function::parametersJacobian(const vec& x) const {
{
const int n = dimY();
vec jac(n*nbParameters());
for(int i=0; i<n; ++i) {
for(int j=0; j<nbParameters(); ++j) {
jac[i + j*n] = 0.0;
}
}
return jac;
} }
...@@ -100,11 +132,11 @@ vec shifted_gamma_function::D(const vec& _alpha, const vec& _p, ...@@ -100,11 +132,11 @@ vec shifted_gamma_function::D(const vec& _alpha, const vec& _p,
vec shifted_gamma_function::G1(double theta) const vec shifted_gamma_function::G1(double theta) const
{ {
vec exp_shc(3);
vec G1(dimY()); vec G1(dimY());
for(int i=0; i<dimY(); ++i) for(int i=0; i<dimY(); ++i)
{ {
const double exp_shc = exp(sh_c[i] * pow(std::max<double>(acos(theta) - sh_theta0[i],0.), sh_k[i])); const double exp_shc = exp(sh_c[i] * pow(std::max<double>(acos(theta) - sh_theta0[i],0.), sh_k[i]));
G1[i] = 1.0 + sh_lambda[i] * (1.0 - exp_shc); G1[i] = 1.0 + sh_lambda[i] * (1.0 - exp_shc);
} }
return G1;
} }
...@@ -16,16 +16,16 @@ class shifted_gamma_function : public nonlinear_function ...@@ -16,16 +16,16 @@ class shifted_gamma_function : public nonlinear_function
{ {
public: // methods public: // methods
shifted_gamma_function()
{
setParametrization(params::CARTESIAN);
setDimX(6);
}
// Overload the function operator // Overload the function operator
virtual vec operator()(const vec& x) const ; virtual vec operator()(const vec& x) const ;
virtual vec value(const vec& x) const ; virtual vec value(const vec& x) const ;
//! Load function specific files
virtual void load(const std::string& filename) ;
//! Save the current function to a specific file type
virtual void save(const std::string& filename, const arguments& args) const ;
//! \brief Export function //! \brief Export function
virtual void save_call(std::ostream& out, const arguments& args) const { virtual void save_call(std::ostream& out, const arguments& args) const {
NOT_IMPLEMENTED(); NOT_IMPLEMENTED();
...@@ -47,6 +47,24 @@ class shifted_gamma_function : public nonlinear_function ...@@ -47,6 +47,24 @@ class shifted_gamma_function : public nonlinear_function
//! parameters. //! parameters.
virtual vec parametersJacobian(const vec& x) const ; virtual vec parametersJacobian(const vec& x) const ;
//! Update the parameter vectors
void setDimY(int nY) {
nonlinear_function::setDimY(nY);
// Update the length of the vectors
sh_c = vec::Zero(nY);
sh_theta0 = vec::Zero(nY);
sh_k = vec::Zero(nY);
sh_lambda = vec::Zero(nY);
p = vec::Zero(nY);
F_0 = vec::Zero(nY);
F_1 = vec::Zero(nY);
K_ap = vec::Zero(nY);
rho_d = vec::Zero(nY);
rho_s = vec::Zero(nY);
alpha = vec::Zero(nY); alpha.fill(1.0);
}
private: private:
//! Fresnel term of the microfacet distribution //! Fresnel term of the microfacet distribution
vec Fresnel(const vec& F0, const vec& F1, double V_H) const; vec Fresnel(const vec& F0, const vec& F1, double V_H) const;
......
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