Line data Source code
1 : #pragma once 2 : 3 : #include "DataDescriptor.h" 4 : #include "Functional.h" 5 : #include "DataContainer.h" 6 : #include "LinearOperator.h" 7 : 8 : namespace elsa 9 : { 10 : /** 11 : * @brief L1 loss functional modeling a laplacian noise distribution 12 : * 13 : * The least squares loss is given by: 14 : * \[ 15 : * || A(x) - b ||_1 16 : * \] 17 : * i.e. the \f$\ell^1\f$ norm of the linear residual / error. 18 : * 19 : * @tparam data_t data type for the domain of the residual of the functional, defaulting to 20 : * real_t 21 : */ 22 : template <typename data_t = real_t> 23 : class L1Loss : public Functional<data_t> 24 : { 25 : public: 26 : /** 27 : * @brief Constructor the l1 loss functional 28 : * 29 : * @param[in] A LinearOperator to use in the residual 30 : * @param[in] b data to use in the linear residual 31 : */ 32 : L1Loss(const LinearOperator<data_t>& A, const DataContainer<data_t>& b); 33 : 34 : /// make copy constructor deletion explicit 35 : L1Loss(const L1Loss<data_t>&) = delete; 36 : 37 : /// default destructor 38 8 : ~L1Loss() override = default; 39 : 40 : const LinearOperator<data_t>& getOperator() const; 41 : 42 : const DataContainer<data_t>& getDataVector() const; 43 : 44 : bool isDifferentiable() const override; 45 : 46 : protected: 47 : /// the evaluation of the l1 loss 48 : data_t evaluateImpl(const DataContainer<data_t>& Rx) const override; 49 : 50 : /// the computation of the gradient (in place) 51 : void getGradientImpl(const DataContainer<data_t>& Rx, 52 : DataContainer<data_t>& out) const override; 53 : 54 : /// the computation of the Hessian 55 : LinearOperator<data_t> getHessianImpl(const DataContainer<data_t>& Rx) const override; 56 : 57 : /// implement the polymorphic clone operation 58 : L1Loss<data_t>* cloneImpl() const override; 59 : 60 : /// implement the polymorphic comparison operation 61 : bool isEqual(const Functional<data_t>& other) const override; 62 : 63 : private: 64 : std::unique_ptr<LinearOperator<data_t>> A_{}; 65 : 66 : DataContainer<data_t> b_{}; 67 : }; 68 : 69 : } // namespace elsa