LCOV - code coverage report
Current view: top level - elsa/functionals - ExpLeastSquares.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 23 33 69.7 %
Date: 2024-05-16 04:22:26 Functions: 12 18 66.7 %

          Line data    Source code
       1             : #include "ExpLeastSquares.h"
       2             : 
       3             : #include "DataContainer.h"
       4             : #include "DataDescriptor.h"
       5             : #include "LinearOperator.h"
       6             : #include "TypeCasts.hpp"
       7             : #include "Scaling.h"
       8             : 
       9             : namespace elsa
      10             : {
      11             :     template <typename data_t>
      12             :     ExpLeastSquares<data_t>::ExpLeastSquares(const LinearOperator<data_t>& A,
      13             :                                              const DataContainer<data_t>& b)
      14             :         : Functional<data_t>(A.getDomainDescriptor()), A_(A.clone()), b_(b)
      15          12 :     {
      16          12 :     }
      17             : 
      18             :     template <typename data_t>
      19             :     bool ExpLeastSquares<data_t>::isDifferentiable() const
      20           0 :     {
      21           0 :         return true;
      22           0 :     }
      23             : 
      24             :     template <typename data_t>
      25             :     const LinearOperator<data_t>& ExpLeastSquares<data_t>::getOperator() const
      26           0 :     {
      27           0 :         return *A_;
      28           0 :     }
      29             : 
      30             :     template <typename data_t>
      31             :     const DataContainer<data_t>& ExpLeastSquares<data_t>::getDataVector() const
      32           0 :     {
      33           0 :         return b_;
      34           0 :     }
      35             : 
      36             :     template <typename data_t>
      37             :     data_t ExpLeastSquares<data_t>::evaluateImpl(const DataContainer<data_t>& x) const
      38           2 :     {
      39           2 :         auto d = exp(-A_->apply(x));
      40           2 :         d -= b_;
      41           2 :         return 0.5 * d.squaredL2Norm();
      42           2 :     }
      43             : 
      44             :     template <typename data_t>
      45             :     void ExpLeastSquares<data_t>::getGradientImpl(const DataContainer<data_t>& x,
      46             :                                                   DataContainer<data_t>& out) const
      47           2 :     {
      48           2 :         auto d = exp(-A_->apply(x));
      49           2 :         out = -A_->applyAdjoint((d - b_) * d);
      50           2 :     }
      51             : 
      52             :     template <typename data_t>
      53             :     LinearOperator<data_t>
      54             :         ExpLeastSquares<data_t>::getHessianImpl(const DataContainer<data_t>& x) const
      55           2 :     {
      56           2 :         auto d = exp(-A_->apply(x));
      57           2 :         return adjoint(*A_) * (d * (2.f * d - b_)) * *A_;
      58           2 :     }
      59             : 
      60             :     template <typename data_t>
      61             :     ExpLeastSquares<data_t>* ExpLeastSquares<data_t>::cloneImpl() const
      62           2 :     {
      63           2 :         return new ExpLeastSquares(*A_, b_);
      64           2 :     }
      65             : 
      66             :     template <typename data_t>
      67             :     bool ExpLeastSquares<data_t>::isEqual(const Functional<data_t>& other) const
      68           2 :     {
      69           2 :         if (!Functional<data_t>::isEqual(other))
      70           0 :             return false;
      71             : 
      72           2 :         auto fn = downcast_safe<ExpLeastSquares<data_t>>(&other);
      73           2 :         return fn && *A_ == *fn->A_ && b_ == fn->b_;
      74           2 :     }
      75             : 
      76             :     // ------------------------------------------
      77             :     // explicit template instantiation
      78             :     template class ExpLeastSquares<float>;
      79             :     template class ExpLeastSquares<double>;
      80             : } // namespace elsa

Generated by: LCOV version 1.14