Xmipp  v3.23.11-Nereus
fuzzy_som.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Alberto Pascual Montano (pascual@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 //-----------------------------------------------------------------------------
27 // FuzzySOM.hh
28 // Implements Smoothly Distributed Fuzzy c-means Self-Organizing Map
29 //-----------------------------------------------------------------------------
30 
31 #ifndef XMIPPFUZZYSOM_H
32 #define XMIPPFUZZYSOM_H
33 
34 #include "base_algorithm.h"
35 #include "map.h"
36 
43 class FuzzySOM : public ClassificationAlgorithm<FuzzyMap>
44 {
45 public:
46 
56  FuzzySOM(double _m0, double _m1, unsigned long _annSteps,
57  double _reg, double _epsilon, unsigned long _nSteps)
58  : ClassificationAlgorithm<FuzzyMap>(), m0(_m0), m1(_m1), annSteps(_annSteps),
59  reg(_reg), epsilon(_epsilon), somNSteps(_nSteps)
60  {};
61 
65  virtual ~FuzzySOM()
66  {};
67 
68 #ifdef UNUSED // detected as unused 29.6.2018
69 
73  void nSteps(const unsigned long& _nSteps);
74 
79  void initialFuzzyMembership(const double& _m0);
80 
81 
86  void finalFuzzyMembership(const double& _m1);
87 
88 
93  void setAnnSteps(const unsigned long& _annSteps);
94 
95 
96 
101  void regularization(const double& _reg);
102 #endif
103 
109  virtual void train(FuzzyMap& _som, const TS& _examples);
110 
116  virtual double test(const FuzzyMap& _som, const TS& _examples) const;
117 
122  virtual double functional(const TS& _examples, const FuzzyMap& _som, double _m, double _reg, double& _fidelity, double& _penalty);
123 
124 
125 
126 private:
127  double m0; // Initial Fuzzy Membership
128  double m1; // Final Fuzzy Membership
129  unsigned long annSteps; // number of deterministic annealing steps
130  double reg; // Regularization constant
131  double epsilon; // Stopping criterion Error < epsilon
132  unsigned long somNSteps; // number of steps
133 
135  virtual void train(FuzzyMap& _som, const TS& _examples) const
136  {};
137 
138  double updateU(FuzzyMap& _som, const TS& _examples, const double& _m);
139 
140  // Update Fuzzy Code vectors
141  void updateV(FuzzyMap& _som, const TS& _examples, const double& _m);
142 
143  // Local Average of the code vectors
144  void LocalAve(FuzzyMap& _som, FeatureVector& tmpV, int tmpi, int tmpj);
145 
146  // Internal Scratch
147 
148  unsigned numNeurons;
149  unsigned numVectors;
150  unsigned dim;
151  std::vector<double> tmpV;
152  std::vector<double> tmpD;
153  std::vector<double> tmpDens;
154  std::vector < std::vector<double> > tmpMap;
155 #ifdef UNUSED // detected as unused 29.6.2018
156  void showX(const TS& _ts);
157 
158  void showV(FuzzyMap& _som);
159 
160  void showU(FuzzyMap& _som, const TS& _ts);
161 #endif
162 
163 };
165 #endif
Definition: map.h:308
virtual double test(const FuzzyMap &_som, const TS &_examples) const
Definition: fuzzy_som.cpp:198
FuzzySOM(double _m0, double _m1, unsigned long _annSteps, double _reg, double _epsilon, unsigned long _nSteps)
Definition: fuzzy_som.h:56
virtual void train(FuzzyMap &_som, const TS &_examples)
Definition: fuzzy_som.cpp:97
virtual ~FuzzySOM()
Definition: fuzzy_som.h:65
std::vector< floatFeature > FeatureVector
Definition: data_types.h:86
virtual double functional(const TS &_examples, const FuzzyMap &_som, double _m, double _reg, double &_fidelity, double &_penalty)
Definition: fuzzy_som.cpp:344