2 * Copyright (C) 2012-2020 Euclid Science Ground Segment
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * @file SOMProjector.icpp
25 #include "SOM/ImplTools.h"
30 namespace SOMProjector_impl {
32 template <typename T, std::size_t ND, typename DistFunc, typename InputIter, typename AdderFunc, typename BmuFunc>
33 SOMProjector::ProjectGrid<T> project_impl(const SOM<ND, DistFunc>& som, InputIter begin, InputIter end,
34 AdderFunc adder_func, BmuFunc bmu_func, const T& init_cell) {
36 // Create the grid to return
37 auto size = som.getSize();
38 SOMProjector::ProjectGrid<T> result {ImplTools::indexAxis("X", size.first), ImplTools::indexAxis("Y", size.second)};
40 // Set all the cells to the default value
41 for (auto& cell : result) {
45 // Iterate through all the inputs and project them to the result
46 for (auto it = begin; it != end; ++it) {
49 // Get the BMU coordinates
53 std::tie(x, y, dist) = bmu_func(input);
55 // Project the input to the result cell
56 adder_func(result(x, y), input);
64 template <typename T, std::size_t ND, typename DistFunc, typename InputIter, typename WeightFunc, typename AdderFunc>
65 SOMProjector::ProjectGrid<T> SOMProjector::project(const SOM<ND, DistFunc>& som, InputIter begin, InputIter end, WeightFunc weight_func,
66 AdderFunc adder_func, const T& init_cell) {
68 auto bmu_func = [&som, &weight_func](const typename std::iterator_traits<InputIter>::value_type & input) {
69 return som.findBMU(input, weight_func);
72 return SOMProjector_impl::project_impl(som, begin, end, adder_func, bmu_func, init_cell);
75 template <typename T, std::size_t ND, typename DistFunc, typename InputIter, typename WeightFunc, typename UncertaintyFunc, typename AdderFunc>
76 SOMProjector::ProjectGrid<T> SOMProjector::project(const SOM<ND, DistFunc>& som, InputIter begin, InputIter end, WeightFunc weight_func,
77 UncertaintyFunc uncertainty_func, AdderFunc adder_func, const T& init_cell) {
79 auto bmu_func = [&som, &weight_func, &uncertainty_func](const typename std::iterator_traits<InputIter>::value_type & input) {
80 return som.findBMU(input, weight_func, uncertainty_func);
83 return SOMProjector_impl::project_impl(som, begin, end, adder_func, bmu_func, init_cell);