Line data Source code
1 : #pragma once 2 : 3 : #include "Functional.h" 4 : 5 : namespace elsa 6 : { 7 : /** 8 : * @brief Class representing the Pseudohuber norm. 9 : * 10 : * @author Matthias Wieczorek - initial code 11 : * @author Maximilian Hornung - modularization 12 : * @author Tobias Lasser - modernization, fixes 13 : * 14 : * @tparam data_t data type for the domain of the residual of the functional, defaulting to 15 : * real_t 16 : * 17 : * The Pseudohuber norm evaluates to \f$ \sum_{i=1}^n \delta \left( \sqrt{1 + (x_i / \delta)^2} 18 : * - 1 \right) \f$ for \f$ x=(x_i)_{i=1}^n \f$ and a slope parameter \f$ \delta \f$. 19 : * 20 : * Reference: https://doi.org/10.1109%2F83.551699 21 : */ 22 : template <typename data_t = real_t> 23 : class PseudoHuber : public Functional<data_t> 24 : { 25 : public: 26 : /** 27 : * @brief Constructor for the Pseudohuber functional, mapping domain vector to scalar 28 : * (without a residual) 29 : * 30 : * @param[in] domainDescriptor describing the domain of the functional 31 : * @param[in] delta parameter for linear slope (defaults to 1) 32 : */ 33 : explicit PseudoHuber(const DataDescriptor& domainDescriptor, 34 : real_t delta = static_cast<real_t>(1)); 35 : 36 : /** 37 : * @brief Constructor for the Pseudohuber functional, using a residual as input to map to a 38 : * scalar 39 : * 40 : * @param[in] residual to be used when evaluating the functional (or its derivative) 41 : * @param[in] delta parameter for linear slope (defaults to 1) 42 : */ 43 : explicit PseudoHuber(const Residual<data_t>& residual, 44 : real_t delta = static_cast<real_t>(1)); 45 : 46 : /// make copy constructor deletion explicit 47 : PseudoHuber(const PseudoHuber<data_t>&) = delete; 48 : 49 : /// default destructor 50 16 : ~PseudoHuber() override = default; 51 : 52 : protected: 53 : /// the evaluation of the Huber norm 54 : data_t evaluateImpl(const DataContainer<data_t>& Rx) override; 55 : 56 : /// the computation of the gradient (in place) 57 : void getGradientInPlaceImpl(DataContainer<data_t>& Rx) override; 58 : 59 : /// the computation of the Hessian 60 : LinearOperator<data_t> getHessianImpl(const DataContainer<data_t>& Rx) override; 61 : 62 : /// implement the polymorphic clone operation 63 : PseudoHuber<data_t>* cloneImpl() const override; 64 : 65 : /// implement the polymorphic comparison operation 66 : bool isEqual(const Functional<data_t>& other) const override; 67 : 68 : private: 69 : /// the slope delta 70 : const real_t _delta; 71 : }; 72 : 73 : } // namespace elsa