23 #ifndef otbPeriodicSOM_hxx
24 #define otbPeriodicSOM_hxx
26 #include "itkNumericTraits.h"
27 #include "itkNeighborhoodIterator.h"
40 template <
class TListSample,
class TMap,
class TSOMLearningBehaviorFunctor,
class TSOMNeighborhoodBehaviorFunctor>
50 IndexType position = map->GetWinner(sample);
54 typedef typename MapType::Superclass ImageMapType;
55 typedef itk::NeighborhoodIterator<ImageMapType> NeighborhoodIteratorType;
56 typename MapType::RegionType mapRegion = map->GetLargestPossibleRegion();
57 NeighborhoodIteratorType it(radius, map, mapRegion);
62 SizeType mapSize = mapRegion.GetSize();
66 it.SetLocation(position);
68 for (i = 0; i < it.Size(); ++i)
70 typename NeighborhoodIteratorType::OffsetType offset = it.GetOffset(i);
73 double theDistance = itk::NumericTraits<double>::Zero;
74 for (j = 0; j < MapType::ImageDimension; ++j)
75 theDistance += pow(
static_cast<double>(offset[j]), 2.0) / pow(
static_cast<double>(radius[j]), 2.0);
77 if (theDistance <= 1.0)
79 for (j = 0; j < MapType::ImageDimension; ++j)
81 int pos = offset[j] + position[j];
82 positionToUpdate[j] = (pos >= 0) ? pos % mapSize[j] : (mapSize[j] - ((-pos) % mapSize[j])) % mapSize[j];
90 double tempBeta = beta / (1.0 + theDistance);
91 for (j = 0; j < newNeuron.Size(); ++j)
93 newNeuron[j] +=
static_cast<typename NeuronType::ValueType
>((sample[j] - tempNeuron[j]) * tempBeta);
95 map->SetPixel(positionToUpdate, newNeuron);