24 #ifndef SOM_SOMTRAINER_H
25 #define SOM_SOMTRAINER_H
41 template <
typename DistFunc,
typename InputIter,
typename InputToWeightFunc>
50 if (learn_factor == 0) {
55 for (
auto it = sampling_policy.start(begin, end); it != end; it = sampling_policy.next(it)) {
58 auto input_weights = weight_func(*it);
63 std::tie(bmu_x, bmu_y, nd_distance) = som.findBMU(*it, weight_func);
67 std::tie(size_x, size_y) = som.getSize();
69 for (
std::size_t cell_y = 0; cell_y < size_y; ++cell_y) {
70 for (
std::size_t cell_x = 0; cell_x < size_x; ++cell_x) {
71 auto cell = som(cell_x, cell_y);
74 auto neighborhood_factor =
m_neighborhood_func({bmu_x, bmu_y}, {cell_x, cell_y}, i, iter_no);
77 if (neighborhood_factor != 0) {
78 for (
std::size_t wi = 0; wi < som.getDimensions(); ++wi) {
79 cell[wi] = cell[wi] + neighborhood_factor * learn_factor * (input_weights[wi] - cell[wi]);
LearningRestraintFunc::Signature m_learning_restraint_func
SOMTrainer(NeighborhoodFunc::Signature neighborhood_func, LearningRestraintFunc::Signature learning_restraint_func)
NeighborhoodFunc::Signature m_neighborhood_func
void train(SOM< DistFunc > &som, std::size_t iter_no, InputIter begin, InputIter end, InputToWeightFunc weight_func, const SamplingPolicy::Interface< InputIter > &sampling_policy=SamplingPolicy::FullSet< InputIter >{})