Line data Source code
1 : #pragma once 2 : 3 : #include "DataContainer.h" 4 : #include "StrongTypes.h" 5 : #include "elsaDefines.h" 6 : 7 : namespace elsa 8 : { 9 : /** 10 : * @brief Class representing the proximal operator of the l1 norm 11 : * 12 : * @author Andi Braimllari - initial code 13 : * 14 : * @tparam data_t data type for the values of the operator, defaulting to real_t 15 : * 16 : * This class represents the soft thresholding operator, expressed by its apply method through 17 : * the function i.e. @f$ prox(v) = sign(v)ยท(|v| - t)_+. @f$ 18 : * 19 : * References: 20 : * http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/xlghtmlnode93.html 21 : */ 22 : template <typename data_t = real_t> 23 : class ProximalL1 24 : { 25 : public: 26 26 : ProximalL1() = default; 27 : 28 : explicit ProximalL1(data_t sigma); 29 : 30 : explicit ProximalL1(const DataContainer<data_t>& b); 31 : 32 : ProximalL1(const DataContainer<data_t>& b, SelfType_t<data_t> sigma); 33 : 34 : // default copy constructor 35 30 : ProximalL1(const ProximalL1<data_t>&) = default; 36 : 37 : // default copy assignment 38 : ProximalL1& operator=(const ProximalL1<data_t>&) = default; 39 : 40 : // move constructor 41 : ProximalL1(ProximalL1<data_t>&&) noexcept; 42 : 43 : // move assignment 44 : ProximalL1& operator=(ProximalL1<data_t>&&) noexcept; 45 : 46 : /// default destructor 47 110 : ~ProximalL1() = default; 48 : 49 : /** 50 : * @brief apply the proximal operator of the l1 norm to an element in the operator's domain 51 : * 52 : * @param[in] v input DataContainer 53 : * @param[in] t input Threshold 54 : * @param[out] prox output DataContainer 55 : */ 56 : void apply(const DataContainer<data_t>& v, SelfType_t<data_t> t, 57 : DataContainer<data_t>& prox) const; 58 : 59 : DataContainer<data_t> apply(const DataContainer<data_t>& v, SelfType_t<data_t> t) const; 60 : 61 : private: 62 : data_t sigma_{1}; 63 : 64 : std::optional<DataContainer<data_t>> b_ = {}; 65 : }; 66 : 67 : template <class data_t> 68 : using SoftThresholding = ProximalL1<data_t>; 69 : } // namespace elsa