Line data Source code
1 : #pragma once 2 : 3 : #include "Problem.h" 4 : #include "Scaling.h" 5 : #include "LinearResidual.h" 6 : 7 : namespace elsa 8 : { 9 : /** 10 : * @brief Class representing a generic Problem that can be split into ordered subsets. 11 : * 12 : * @author Michael Loipführer - initial code 13 : * 14 : * @tparam data_t data type for the domain and range of the problem, defaulting to real_t 15 : * 16 : * This class represents a problem that can be split into smaller, ordered subsets for use in 17 : * ordered subset solvers like SQS. 18 : */ 19 : template <typename data_t = real_t> 20 : class SubsetProblem : public Problem<data_t> 21 : { 22 : public: 23 : /** 24 : * @brief Constructor for a subset problem 25 : * 26 : * @param[in] fullProblem the generic problem 27 : * @param[in] subsetProblems the problem instances corresponding to each ordered subset 28 : * 29 : * NOTE: we also need to store the full problem as otherwise we would not be able to 30 : * easily compute the hessian of the problem. 31 : */ 32 : SubsetProblem(const Problem<data_t>& fullProblem, 33 : const std::vector<std::unique_ptr<Problem<data_t>>>& subsetProblems); 34 : 35 : /// default destructor 36 6 : ~SubsetProblem() override = default; 37 : 38 : /** 39 : * @brief return the gradient of the problem at the current estimated solution for the given 40 : * subset 41 : * 42 : * @param[in] subset is index of the subset the gradient is evaluated for 43 : * 44 : * @returns DataContainer (in the domain of the problem) containing the result of the 45 : * gradient at the current solution for the given subset 46 : * 47 : */ 48 : DataContainer<data_t> getSubsetGradient(index_t subset); 49 : 50 : /** 51 : * @brief compute the gradient of the problem at the current estimated solution 52 : * 53 : * @param[in] subset is index of the subset the gradient is evaluated for 54 : * @param[out] result output DataContainer containing the gradient (in the domain of the 55 : * problem) evaluated for the given subset 56 : * 57 : */ 58 : void getSubsetGradient(DataContainer<data_t>& result, index_t subset); 59 : 60 : /** 61 : * @brief return the number of ordered subsets this problem is divided into 62 : */ 63 : index_t getNumberOfSubsets() const; 64 : 65 : protected: 66 : /// copy constructor for use in cloning 67 : SubsetProblem<data_t>(const SubsetProblem<data_t>& subsetProblem); 68 : 69 : /// implement the polymorphic clone operation 70 : SubsetProblem<data_t>* cloneImpl() const override; 71 : 72 : /// the subset-problems 73 : std::vector<std::unique_ptr<Problem<data_t>>> _subsetProblems; 74 : }; 75 : } // namespace elsa