TikhonovProblem.cpp 2.42 KB
Newer Older
1
2
3
4
5
6
#include "TikhonovProblem.h"
#include "L2NormPow2.h"
#include "WeightedL2NormPow2.h"

namespace elsa
{
7
8
9
10
11
12
13
14
15
    template <typename data_t>
    TikhonovProblem<data_t>::TikhonovProblem(const LinearOperator<data_t>& A,
                                             const DataContainer<data_t> b, real_t weight)
        : Problem<data_t>{
            L2NormPow2<data_t>(A, b),
            RegularizationTerm<data_t>(weight, L2NormPow2<data_t>(A.getDomainDescriptor()))}
    {
    }

16
17
18
19
20
21
22
23
    template <typename data_t>
    TikhonovProblem<data_t>::TikhonovProblem(
        const WLSProblem<data_t>& wlsProblem,
        const std::vector<RegularizationTerm<data_t>>& regTerms)
        : Problem<data_t>{wlsProblem.getDataTerm(), regTerms, wlsProblem.getCurrentSolution()}
    {
        // make sure that at least one regularization term exists
        if (regTerms.empty()) {
24
            throw InvalidArgumentError(
25
26
27
28
29
30
                "TikhonovProblem: at least one regularization term has to be supplied");
        }

        // make sure that all regularization terms are linear and of type (Weighted)L2NormPow2
        for (const auto& regTerm : regTerms) {
            const auto& func = regTerm.getFunctional();
31
            if (!is<L2NormPow2<data_t>>(func) && !is<WeightedL2NormPow2<data_t>>(func)) {
32
33
                throw InvalidArgumentError("TikhonovProblem: all regularization terms should be "
                                           "of type L2NormPow2 or WeightedL2NormPow2");
34
            }
35
            if (!is<LinearResidual<data_t>>(func.getResidual())) {
36
                throw InvalidArgumentError(
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
                    "TikhonovProblem: all regularization terms should be linear");
            }
        }
    }

    template <typename data_t>
    TikhonovProblem<data_t>::TikhonovProblem(const WLSProblem<data_t>& wlsProblem,
                                             const RegularizationTerm<data_t>& regTerm)
        : TikhonovProblem{wlsProblem, std::vector<RegularizationTerm<data_t>>{regTerm}}
    {
    }

    template <typename data_t>
    TikhonovProblem<data_t>* TikhonovProblem<data_t>::cloneImpl() const
    {
        return new TikhonovProblem(*this);
    }

    // ------------------------------------------
    // explicit template instantiation
    template class TikhonovProblem<float>;
    template class TikhonovProblem<double>;
59
60
    template class TikhonovProblem<complex<float>>;
    template class TikhonovProblem<complex<double>>;
61
62

} // namespace elsa