Line data Source code
1 : #pragma once 2 : 3 : #include "Functional.h" 4 : 5 : namespace elsa 6 : { 7 : /** 8 : * @brief Class representing the l1 norm functional. 9 : * 10 : * @author Matthias Wieczorek - initial code 11 : * @author Maximilian Hornung - modularization 12 : * @author Tobias Lasser - modernization 13 : * 14 : * @tparam data_t data type for the domain of the residual of the functional, defaulting to 15 : * real_t 16 : * 17 : * The l1 norm functional evaluates to \f$ \sum_{i=1}^n |x_i| \f$ for \f$ x=(x_i)_{i=1}^n \f$. 18 : * Please note that it is not differentiable, hence getGradient and getHessian will throw 19 : * exceptions. 20 : */ 21 : template <typename data_t = real_t> 22 : class L1Norm : public Functional<data_t> 23 : { 24 : public: 25 : /** 26 : * @brief Constructor for the l1 norm functional, mapping domain vector to a scalar (without 27 : * a residual) 28 : * 29 : * @param[in] domainDescriptor describing the domain of the functional 30 : */ 31 : explicit L1Norm(const DataDescriptor& domainDescriptor); 32 : 33 : /** 34 : * @brief Constructor for the l1 norm functional, using a residual as input to map to a 35 : * scalar 36 : * 37 : * @param[in] residual to be used when evaluating the functional (or its derivatives) 38 : */ 39 : explicit L1Norm(const Residual<data_t>& residual); 40 : 41 : /// make copy constructor deletion explicit 42 : L1Norm(const L1Norm<data_t>&) = delete; 43 : 44 : /// default destructor 45 0 : ~L1Norm() override = default; 46 : 47 : protected: 48 : /// the evaluation of the l1 norm 49 : data_t evaluateImpl(const DataContainer<data_t>& Rx) override; 50 : 51 : /// the computation of the gradient (in place) 52 : void getGradientInPlaceImpl(DataContainer<data_t>& Rx) override; 53 : 54 : /// the computation of the Hessian 55 : LinearOperator<data_t> getHessianImpl(const DataContainer<data_t>& Rx) override; 56 : 57 : /// implement the polymorphic clone operation 58 : L1Norm<data_t>* cloneImpl() const override; 59 : 60 : /// implement the polymorphic comparison operation 61 : bool isEqual(const Functional<data_t>& other) const override; 62 : }; 63 : 64 : } // namespace elsa