LCOV - code coverage report
Current view: top level - elsa/functionals - LeastSquares.h (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 1 1 100.0 %
Date: 2024-05-16 04:22:26 Functions: 2 2 100.0 %

          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 The least squares functional / loss functional.
      12             :      *
      13             :      * The least squares loss is given by:
      14             :      * \[
      15             :      * \frac{1}{2} || A(x) - b ||_2^2
      16             :      * \]
      17             :      * i.e. the squared \f$\ell^2\f$ of the linear residual.
      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 LeastSquares : public Functional<data_t>
      24             :     {
      25             :     public:
      26             :         /**
      27             :          * @brief Constructor the l2 norm (squared) functional with a LinearResidual
      28             :          *
      29             :          * @param[in] A LinearOperator to use in the residual
      30             :          * @param[in] b data to use in the linear residual
      31             :          */
      32             :         LeastSquares(const LinearOperator<data_t>& A, const DataContainer<data_t>& b);
      33             : 
      34             :         /// make copy constructor deletion explicit
      35             :         LeastSquares(const LeastSquares<data_t>&) = delete;
      36             : 
      37             :         /// default destructor
      38         358 :         ~LeastSquares() 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 l2 norm (squared)
      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             :         LeastSquares<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

Generated by: LCOV version 1.14