2 * Copyright (C) 2012-2022 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
24#include "SOM/ImplTools.h"
30namespace SOMProjector_impl {
32template <typename T, typename DistFunc, typename InputIter, typename AdderFunc, typename BmuFunc>
33SOMProjector::ProjectGrid<T> project_impl(const SOM<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);
62} // namespace SOMProjector_impl
64template <typename T, typename DistFunc, typename InputIter, typename WeightFunc, typename AdderFunc>
65SOMProjector::ProjectGrid<T> SOMProjector::project(const SOM<DistFunc>& som, InputIter begin, InputIter end,
66 WeightFunc weight_func, 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);
75template <typename T, typename DistFunc, typename InputIter, typename WeightFunc, typename UncertaintyFunc,
77SOMProjector::ProjectGrid<T> SOMProjector::project(const SOM<DistFunc>& som, InputIter begin, InputIter end,
78 WeightFunc weight_func, UncertaintyFunc uncertainty_func,
79 AdderFunc adder_func, const T& init_cell) {
81 auto bmu_func = [&som, &weight_func,
82 &uncertainty_func](const typename std::iterator_traits<InputIter>::value_type& input) {
83 return som.findBMU(input, weight_func, uncertainty_func);
86 return SOMProjector_impl::project_impl(som, begin, end, adder_func, bmu_func, init_cell);