Line data Source code
1 : #pragma once 2 : 3 : #include "DataContainer.h" 4 : #include "Functional.h" 5 : #include "LinearResidual.h" 6 : 7 : namespace elsa 8 : { 9 : /** 10 : * @brief Class representing a quadric functional. 11 : * 12 : * The Quadric functional evaluates to \f$ \frac{1}{2} x^tAx - x^tb \f$ for a symmetric positive 13 : * definite operator A and a vector b. 14 : * 15 : * Please note: contrary to other functionals, Quadric does not allow wrapping an explicit 16 : * residual. 17 : * 18 : * @tparam data_t data type for the domain of the residual of the functional, defaulting to 19 : * real_t 20 : * 21 : * @author 22 : * * Matthias Wieczorek - initial code 23 : * * Maximilian Hornung - modularization 24 : * * Tobias Lasser - modernization 25 : * * Nikola Dinev - add functionality 26 : * 27 : */ 28 : template <typename data_t = real_t> 29 : class Quadric : public Functional<data_t> 30 : { 31 : public: 32 : /** 33 : * @brief Constructor for the Quadric functional, using operator A and vector b (no 34 : * residual). 35 : * 36 : * @param[in] A the operator (has to be symmetric positive definite) 37 : * @param[in] b the data vector 38 : */ 39 : Quadric(const LinearOperator<data_t>& A, const DataContainer<data_t>& b); 40 : 41 : /** 42 : * @brief Constructor for the Quadric functional \f$ \frac{1}{2} x^tAx \f$ (trivial data 43 : * vector) 44 : * 45 : * @param[in] A the operator (has to be symmetric positive definite) 46 : */ 47 : explicit Quadric(const LinearOperator<data_t>& A); 48 : 49 : /** 50 : * @brief Constructor for the Quadric functional \f$ \frac{1}{2} x^tx - x^tb \f$ (trivial 51 : * operator) 52 : * 53 : * @param[in] b the data vector 54 : */ 55 : explicit Quadric(const DataContainer<data_t>& b); 56 : 57 : /** 58 : * @brief Constructor for the Quadric functional \f$ \frac{1}{2} x^tx \f$ (trivial operator 59 : * and data vector) 60 : * 61 : * @param[in] domainDescriptor the descriptor of x 62 : */ 63 : explicit Quadric(const DataDescriptor& domainDescriptor); 64 : 65 : /// make copy constructor deletion explicit 66 : Quadric(const Quadric<data_t>&) = delete; 67 : 68 : /// default destructor 69 64 : ~Quadric() override = default; 70 : 71 : /// returns the residual \f$ Ax - b \f$, which also corresponds to the gradient of the 72 : /// functional 73 : const LinearResidual<data_t>& getGradientExpression() const; 74 : 75 : bool isDifferentiable() const override; 76 : 77 : protected: 78 : /// the evaluation of the Quadric functional 79 : data_t evaluateImpl(const DataContainer<data_t>& Rx) const override; 80 : 81 : /// the computation of the gradient (in place) 82 : void getGradientImpl(const DataContainer<data_t>& Rx, 83 : DataContainer<data_t>& out) const override; 84 : 85 : /// the computation of the Hessian 86 : LinearOperator<data_t> getHessianImpl(const DataContainer<data_t>& Rx) const override; 87 : 88 : /// implement the polymorphic clone operation 89 : Quadric<data_t>* cloneImpl() const override; 90 : 91 : /// implement the polymorphic comparison operation 92 : bool isEqual(const Functional<data_t>& other) const override; 93 : 94 : private: 95 : /// storing A,b in a linear residual 96 : LinearResidual<data_t> linResidual_; 97 : }; 98 : 99 : } // namespace elsa