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 bool init(
const UINT numInputs,
const Float sigma = 2.0){
56 this->numInputs = numInputs;
58 weights.
resize( numInputs );
62 random.
setSeed( (
unsigned long long)time(NULL) );
65 for(
unsigned int i=0; i<numInputs; i++){
83 bool getInitialized()
const {
87 Float getWeightDistance(
const VectorFloat &x )
const {
91 for(UINT i=0; i<numInputs; i++){
92 dist += x[i]- weights[i];
98 Float getSquaredWeightDistance(
const VectorFloat &x )
const {
102 for(UINT i=0; i<numInputs; i++){
103 dist += grt_sqr( x[i]- weights[i] );
112 for(UINT i=0; i<numInputs; i++){
113 y += grt_sqr( x[i]- weights[i] );
116 return exp( - (y/(2*grt_sqr(sigma))) );
119 bool saveNeuronToFile( std::fstream &file )
const {
121 if( !file.is_open() ){
129 file <<
"GAUSS_NEURON\n";
130 file <<
"NumInputs: " << numInputs << std::endl;
132 for(UINT i=0; i<numInputs; i++){
134 if( i < numInputs-1 ) file <<
"\t";
137 file <<
"Sigma: " << sigma << std::endl;
142 bool loadNeuronFromFile( std::fstream &file ){
144 if( !file.is_open() ){
154 if( word !=
"GAUSS_NEURON" ){
160 if( word !=
"NumInputs:" ){
166 weights.
resize( numInputs );
170 if( word !=
"Weights:" ){
175 for(UINT i=0; i<numInputs; i++){
181 if( word !=
"Sigma:" ){
203 SelfOrganizingMap(
const UINT networkSize = 20,
const UINT networkTypology = RANDOM_NETWORK,
const UINT maxNumEpochs = 1000,
const Float alphaStart = 0.8,
const Float alphaEnd = 0.1);
241 virtual bool reset();
248 virtual bool clear();
321 Float getAlphaStart()
const;
323 Float getAlphaEnd()
const;
333 bool setNetworkSize(
const UINT networkSize );
335 bool setNetworkTypology(
const UINT networkTypology );
337 bool setAlphaStart(
const Float alphaStart );
339 bool setAlphaEnd(
const Float alphaEnd );
346 UINT networkTypology;
358 enum NetworkTypology{RANDOM_NETWORK=0};
364 #endif //GRT_SELF_ORGANIZING_MAP_HEADER
virtual bool deepCopyFrom(const Clusterer *clusterer)
virtual bool resize(const unsigned int size)
virtual bool train_(MatrixFloat &trainingData)
UINT getNetworkSize() const
bool validateNetworkTypology(const UINT networkTypology)
virtual bool map_(VectorFloat &x)
SelfOrganizingMap(const UINT networkSize=20, const UINT networkTypology=RANDOM_NETWORK, const UINT maxNumEpochs=1000, const Float alphaStart=0.8, const Float alphaEnd=0.1)
virtual bool saveModelToFile(std::string filename) const
virtual bool loadModelFromFile(std::string filename)
virtual bool saveModelToFile(std::fstream &file) const
virtual bool loadModelFromFile(std::fstream &file)
Float getRandomNumberUniform(Float minRange=0.0, Float maxRange=1.0)
virtual ~SelfOrganizingMap()
void setSeed(unsigned long long seed=0)
SelfOrganizingMap & operator=(const SelfOrganizingMap &rhs)