Loading...
Searching...
No Matches
funcmin::GprCostFunction< ClassName, FuncName > Class Template Reference
Inheritance diagram for funcmin::GprCostFunction< ClassName, FuncName >:

Public Member Functions

 GprCostFunction (const gpr::EigenMatrix &x_data, const Eigen::VectorXd &x_ind_data, const Eigen::VectorXd &y_data, FuncName func, ClassName &gpr_instance)
virtual ~GprCostFunction ()
virtual bool Evaluate (double const *const *parameters, double *residuals, double **jacobians) const override

Detailed Description

template<typename ClassName, typename FuncName>
class funcmin::GprCostFunction< ClassName, FuncName >

Definition at line 13 of file Ceres.inl.

Constructor & Destructor Documentation

◆ GprCostFunction()

template<typename ClassName, typename FuncName>
funcmin::GprCostFunction< ClassName, FuncName >::GprCostFunction ( const gpr::EigenMatrix & x_data,
const Eigen::VectorXd & x_ind_data,
const Eigen::VectorXd & y_data,
FuncName func,
ClassName & gpr_instance )
inline

Definition at line 15 of file Ceres.inl.

19 : x_(x_data),
20 x_ind_(x_ind_data),
21 y_(y_data),
22 func_to_min_(func),
23 holder_(gpr_instance),
24 normalization_factor_(-1.0)
25 {
26 const int n_vars = holder_.sexpat_cov_func->combineParameters().size();
29 }

◆ ~GprCostFunction()

template<typename ClassName, typename FuncName>
virtual funcmin::GprCostFunction< ClassName, FuncName >::~GprCostFunction ( )
inlinevirtual

Definition at line 31 of file Ceres.inl.

31{ }

Member Function Documentation

◆ Evaluate()

template<typename ClassName, typename FuncName>
virtual bool funcmin::GprCostFunction< ClassName, FuncName >::Evaluate ( double const *const * parameters,
double * residuals,
double ** jacobians ) const
inlineoverridevirtual

Definition at line 33 of file Ceres.inl.

35 {
36 const int n_vars = parameter_block_sizes()[0];
38
39 double raw_energy;
40
41 if (jacobians != nullptr && jacobians[0] != nullptr) {
44
45 // 1. Call your function to get the raw, unscaled energy and
46 // gradient.
47 (holder_.*func_to_min_)(w_current, x_, x_ind_, y_, eg);
48
49 // 2. On the first evaluation, compute the normalization factor.
50 if (normalization_factor_ < 0.0) {
51 normalization_factor_ = raw_gradient.norm();
52 if (normalization_factor_ < DBL_EPSILON) {
53 normalization_factor_ = 1.0;
54 }
55 }
56
57 // 3. Scale BOTH the energy (residual) and the gradient (Jacobian).
58 residuals[0] = raw_energy / normalization_factor_;
60 jacobian_map = raw_gradient / normalization_factor_;
61
62 // --- THE HACK HAS BEEN REMOVED ---
63 // const double sign_correction = (residuals[0] < 0.0) ? -1.0 : 1.0;
64 // jacobian_map *= sign_correction;
65
66 } else {
67 // Gradient is not requested.
70 (holder_.*func_to_min_)(w_current, x_, x_ind_, y_, eg);
71
72 // Still scale the residual even if jacobian is not requested.
73 if (normalization_factor_ > 0.0) {
74 residuals[0] = raw_energy / normalization_factor_;
75 } else {
76 residuals[0] = raw_energy; // Not initialized yet
77 }
78 }
79
80 return std::isfinite(residuals[0]);
81 }

The documentation for this class was generated from the following file: