29 #ifndef GRT_SELF_ORGANIZING_MAP_HEADER 30 #define GRT_SELF_ORGANIZING_MAP_HEADER 32 #include "../../Util/GRTCommon.h" 33 #include "../../CoreModules/Clusterer.h" 34 #include "../../Util/Random.h" 50 Float& operator[](
const UINT index){
51 return weights[ index ];
54 const Float& operator[](
const UINT index)
const{
55 return weights[ index ];
58 bool init(
const UINT numInputs,
const Float sigma = 2.0,
const Float minWeightRange = -1.0,
const Float maxWeightRange = 1.0){
60 this->numInputs = numInputs;
62 weights.
resize( numInputs );
66 random.
setSeed( (
unsigned long long)time(NULL) );
69 for(
unsigned int i=0; i<numInputs; i++){
87 bool getInitialized()
const {
91 Float getWeightDistance(
const VectorFloat &x )
const {
95 for(UINT i=0; i<numInputs; i++){
96 dist += x[i]- weights[i];
102 Float getSquaredWeightDistance(
const VectorFloat &x )
const {
106 for(UINT i=0; i<numInputs; i++){
107 dist += grt_sqr( x[i]- weights[i] );
116 for(UINT i=0; i<numInputs; i++){
117 y += grt_sqr( x[i]- weights[i] );
120 return exp( - (y/(2*grt_sqr(sigma))) );
123 bool save( std::fstream &file )
const {
125 if( !file.is_open() ){
133 file <<
"GAUSS_NEURON\n";
134 file <<
"NumInputs: " << numInputs << std::endl;
136 for(UINT i=0; i<numInputs; i++){
138 if( i < numInputs-1 ) file <<
"\t";
141 file <<
"Sigma: " << sigma << std::endl;
146 bool load( std::fstream &file ){
148 if( !file.is_open() ){
158 if( word !=
"GAUSS_NEURON" ){
164 if( word !=
"NumInputs:" ){
170 weights.
resize( numInputs );
174 if( word !=
"Weights:" ){
179 for(UINT i=0; i<numInputs; i++){
185 if( word !=
"Sigma:" ){
204 enum NetworkTypology{RANDOM_NETWORK=0};
209 SelfOrganizingMap(
const UINT networkSize = 5,
const UINT networkTypology = RANDOM_NETWORK,
const UINT maxNumEpochs = 1000,
const Float sigmaWeight = 0.2,
const Float alphaStart = 0.3,
const Float alphaEnd = 0.1);
239 virtual bool deepCopyFrom(
const Clusterer *clusterer);
247 virtual bool reset();
254 virtual bool clear();
300 virtual bool save( std::fstream &file )
const;
309 virtual bool load( std::fstream &file );
317 bool validateNetworkTypology(
const UINT networkTypology );
325 UINT getNetworkSize()
const;
327 Float getAlphaStart()
const;
329 Float getAlphaEnd()
const;
339 bool setNetworkSize(
const UINT networkSize );
341 bool setNetworkTypology(
const UINT networkTypology );
343 bool setAlphaStart(
const Float alphaStart );
345 bool setAlphaEnd(
const Float alphaEnd );
347 bool setSigmaWeight(
const Float sigmaWeight );
358 static std::string getId();
361 UINT networkTypology;
370 static const std::string id;
375 #endif //GRT_SELF_ORGANIZING_MAP_HEADER
This file contains the Random class, a useful wrapper for generating cross platform random functions...
virtual bool resize(const unsigned int size)
virtual bool save(const std::string &filename) const
bool setSeed(const unsigned long long seed=0)
Float getRandomNumberUniform(Float minRange=0.0, Float maxRange=1.0)
virtual bool load(const std::string &filename)