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