Line data Source code
1 : #include "SmoothMixedL21Norm.h" 2 : #include "BlockDescriptor.h" 3 : #include "BlockLinearOperator.h" 4 : #include "Identity.h" 5 : 6 : using namespace std; 7 : 8 : namespace elsa 9 : { 10 : template <typename data_t> 11 : SmoothMixedL21Norm<data_t>::SmoothMixedL21Norm(const DataDescriptor& domainDescriptor, 12 : data_t epsilon) 13 : : Functional<data_t>(domainDescriptor), epsilon{epsilon} 14 8 : { 15 8 : } 16 : 17 : template <typename data_t> 18 : data_t SmoothMixedL21Norm<data_t>::evaluateImpl(const DataContainer<data_t>& Rx) const 19 2 : { 20 2 : return Rx.l21SmoothMixedNorm(epsilon); 21 2 : } 22 : 23 : template <typename data_t> 24 : void SmoothMixedL21Norm<data_t>::getGradientImpl(const DataContainer<data_t>& Rx, 25 : DataContainer<data_t>& out) const 26 2 : { 27 : 28 2 : auto tmp = DataContainer<data_t>(Rx.getBlock(0).getDataDescriptor()); 29 2 : tmp = 0; 30 : 31 8 : for (index_t i = 0; i < Rx.getNumberOfBlocks(); ++i) { 32 6 : tmp += (square(Rx.getBlock(i))); 33 6 : } 34 : 35 2 : tmp += (epsilon * epsilon); 36 2 : tmp = sqrt(tmp); 37 : 38 8 : for (index_t i = 0; i < Rx.getNumberOfBlocks(); ++i) { 39 6 : out.getBlock(i) = Rx.getBlock(i) / tmp; 40 6 : } 41 2 : } 42 : template <typename data_t> 43 : LinearOperator<data_t> 44 : SmoothMixedL21Norm<data_t>::getHessianImpl(const DataContainer<data_t>&) const 45 2 : { 46 : 47 2 : throw LogicError("SmoothMixedL21Norm: not differentiable, so no hessian! (busted!)"); 48 2 : } 49 : template <typename data_t> 50 : SmoothMixedL21Norm<data_t>* SmoothMixedL21Norm<data_t>::cloneImpl() const 51 2 : { 52 2 : return new SmoothMixedL21Norm(this->getDomainDescriptor(), epsilon); 53 2 : } 54 : template <typename data_t> 55 : bool SmoothMixedL21Norm<data_t>::isEqual(const Functional<data_t>& other) const 56 2 : { 57 2 : if (!Functional<data_t>::isEqual(other)) 58 0 : return false; 59 : 60 2 : return is<SmoothMixedL21Norm>(other); 61 2 : } 62 : 63 : // ------------------------------------------ 64 : // explicit template instantiation 65 : template class SmoothMixedL21Norm<float>; 66 : template class SmoothMixedL21Norm<double>; 67 : template class SmoothMixedL21Norm<complex<float>>; 68 : template class SmoothMixedL21Norm<complex<double>>; 69 : 70 : } // namespace elsa