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 double& operator[](
const UINT index){
51 return weights[ index ];
54 bool init(
const UINT numInputs,
const double 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 double getWeightDistance(
const VectorDouble &x )
const {
91 for(UINT i=0; i<numInputs; i++){
92 dist += x[i]- weights[i];
98 double getSquaredWeightDistance(
const VectorDouble &x )
const {
102 for(UINT i=0; i<numInputs; i++){
103 dist += SQR( x[i]- weights[i] );
109 double fire(
const VectorDouble &x )
const {
112 for(UINT i=0; i<numInputs; i++){
113 y += SQR( x[i]- weights[i] );
116 return exp( - (y/(2*SQR(sigma))) );
119 bool saveNeuronToFile(fstream &file)
const {
121 if( !file.is_open() ){
129 file <<
"GAUSS_NEURON\n";
130 file <<
"NumInputs: " << numInputs << endl;
132 for(UINT i=0; i<numInputs; i++){
134 if( i < numInputs-1 ) file <<
"\t";
137 file <<
"Sigma: " << sigma << endl;
142 bool loadNeuronFromFile(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:" ){
192 VectorDouble weights;
203 SelfOrganizingMap(
const UINT networkSize = 20,
const UINT networkTypology = RANDOM_NETWORK,
const UINT maxNumEpochs = 1000,
const double alphaStart = 0.8,
const double alphaEnd = 0.1);
241 virtual bool reset();
248 virtual bool clear();
285 virtual bool map_( VectorDouble &x );
321 double getAlphaStart()
const;
323 double getAlphaEnd()
const;
325 VectorDouble getMappedData()
const;
327 vector< GaussNeuron > getNeurons()
const;
329 const vector< GaussNeuron > &getNeuronsRef()
const;
333 bool setNetworkSize(
const UINT networkSize );
335 bool setNetworkTypology(
const UINT networkTypology );
337 bool setAlphaStart(
const double alphaStart );
339 bool setAlphaEnd(
const double alphaEnd );
346 UINT networkTypology;
349 VectorDouble mappedData;
350 vector< GaussNeuron > neurons;
358 enum NetworkTypology{RANDOM_NETWORK=0};
364 #endif //GRT_SELF_ORGANIZING_MAP_HEADER
virtual bool saveModelToFile(string filename) const
virtual bool train_(MatrixDouble &data)
virtual bool loadModelFromFile(fstream &file)
virtual bool loadModelFromFile(string filename)
virtual bool map_(VectorDouble &x)
SelfOrganizingMap(const UINT networkSize=20, const UINT networkTypology=RANDOM_NETWORK, const UINT maxNumEpochs=1000, const double alphaStart=0.8, const double alphaEnd=0.1)
UINT getNetworkSize() const
void setSeed(unsigned long long seed=0)
virtual bool saveModelToFile(fstream &file) const
double getRandomNumberUniform(double minRange=0.0, double maxRange=1.0)
virtual bool deepCopyFrom(const Clusterer *clusterer)
bool validateNetworkTypology(const UINT networkTypology)
SelfOrganizingMap & operator=(const SelfOrganizingMap &rhs)
virtual ~SelfOrganizingMap()