Line data Source code
1 : #include "TikhonovProblem.h" 2 : #include "L2NormPow2.h" 3 : #include "WeightedL2NormPow2.h" 4 : 5 : namespace elsa 6 : { 7 : template <typename data_t> 8 : TikhonovProblem<data_t>::TikhonovProblem(const LinearOperator<data_t>& A, 9 : const DataContainer<data_t> b, real_t weight) 10 : : Problem<data_t>{ 11 : L2NormPow2<data_t>(A, b), 12 : RegularizationTerm<data_t>(weight, L2NormPow2<data_t>(A.getDomainDescriptor()))} 13 0 : { 14 0 : } 15 : 16 : template <typename data_t> 17 : TikhonovProblem<data_t>::TikhonovProblem( 18 : const WLSProblem<data_t>& wlsProblem, 19 : const std::vector<RegularizationTerm<data_t>>& regTerms) 20 : : Problem<data_t>{wlsProblem.getDataTerm(), regTerms, wlsProblem.getCurrentSolution()} 21 34 : { 22 : // make sure that at least one regularization term exists 23 34 : if (regTerms.empty()) { 24 2 : throw InvalidArgumentError( 25 2 : "TikhonovProblem: at least one regularization term has to be supplied"); 26 2 : } 27 : 28 : // make sure that all regularization terms are linear and of type (Weighted)L2NormPow2 29 46 : for (const auto& regTerm : regTerms) { 30 46 : const auto& func = regTerm.getFunctional(); 31 46 : if (!is<L2NormPow2<data_t>>(func) && !is<WeightedL2NormPow2<data_t>>(func)) { 32 6 : throw InvalidArgumentError("TikhonovProblem: all regularization terms should be " 33 6 : "of type L2NormPow2 or WeightedL2NormPow2"); 34 6 : } 35 40 : if (!is<LinearResidual<data_t>>(func.getResidual())) { 36 0 : throw InvalidArgumentError( 37 0 : "TikhonovProblem: all regularization terms should be linear"); 38 0 : } 39 40 : } 40 32 : } 41 : 42 : template <typename data_t> 43 : TikhonovProblem<data_t>::TikhonovProblem(const WLSProblem<data_t>& wlsProblem, 44 : const RegularizationTerm<data_t>& regTerm) 45 : : TikhonovProblem{wlsProblem, std::vector<RegularizationTerm<data_t>>{regTerm}} 46 16 : { 47 16 : } 48 : 49 : template <typename data_t> 50 : TikhonovProblem<data_t>* TikhonovProblem<data_t>::cloneImpl() const 51 8 : { 52 8 : return new TikhonovProblem(*this); 53 8 : } 54 : 55 : // ------------------------------------------ 56 : // explicit template instantiation 57 : template class TikhonovProblem<float>; 58 : template class TikhonovProblem<double>; 59 : template class TikhonovProblem<complex<float>>; 60 : template class TikhonovProblem<complex<double>>; 61 : 62 : } // namespace elsa