Alexandria
2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
SOM
src
lib
NeihbourhoodFunc.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2022 Euclid Science Ground Segment
3
*
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)
7
* any later version.
8
*
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
12
* details.
13
*
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
17
*/
18
19
#include "
SOM/NeighborhoodFunc.h
"
20
#include <algorithm>
// std::max
21
#include <cmath>
22
23
namespace
Euclid
{
24
namespace
SOM {
25
namespace
NeighborhoodFunc {
26
27
double
LinearUnitDisk::operator()
(
std::pair<std::size_t, std::size_t>
bmu,
std::pair<std::size_t, std::size_t>
cell,
28
std::size_t
iteration,
std::size_t
total_iterations) {
29
double
iter_factor = 1.0 *
static_cast<
double
>
(total_iterations - iteration) /
static_cast<
double
>
(total_iterations);
30
iter_factor = iter_factor * iter_factor;
// We compare the squared distances
31
auto
x =
static_cast<
double
>
(bmu.first - cell.first);
32
auto
y =
static_cast<
double
>
(bmu.second - cell.second);
33
double
dist_square = x * x + y * y;
34
if
(dist_square <
m_r_square
* iter_factor) {
35
return
1.;
36
}
else
{
37
return
0.;
38
}
39
}
40
41
Kohonen::Kohonen
(
std::size_t
x_size,
std::size_t
y_size,
double
sigma_cutoff_mult)
42
: m_init_sigma(static_cast<double>(
std
::max(x_size, y_size)) / 2.)
43
, m_sigma_log(
std
::log(m_init_sigma))
44
, m_cutoff_mult_square{sigma_cutoff_mult * sigma_cutoff_mult} {}
45
46
}
// namespace NeighborhoodFunc
47
}
// namespace SOM
48
}
// namespace Euclid
NeighborhoodFunc.h
Euclid::SOM::NeighborhoodFunc::Kohonen::Kohonen
Kohonen(std::size_t x_size, std::size_t y_size, double sigma_cutoff_mult)
Definition
NeihbourhoodFunc.cpp:41
Euclid::SOM::NeighborhoodFunc::LinearUnitDisk::m_r_square
double m_r_square
Definition
NeighborhoodFunc.h:43
Euclid::SOM::NeighborhoodFunc::LinearUnitDisk::operator()
double operator()(std::pair< std::size_t, std::size_t > bmu, std::pair< std::size_t, std::size_t > cell, std::size_t iteration, std::size_t total_iterations)
Definition
NeihbourhoodFunc.cpp:27
Euclid
Definition
index_sequence.h:27
std
STL namespace.
std::pair
std::size_t
Generated by
1.9.8