Xmipp  v3.23.11-Nereus
fuzzy_code_book.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 // xmippFuzzyCodeBook.hh
27 // Implements a set of fuzzy code vectors, that is a Fuzzy code book.
28 //-----------------------------------------------------------------------------
29 
30 #ifndef XMIPPFUZZYCB_H
31 #define XMIPPFUZZYCB_H
32 
33 #include "code_book.h"
34 
44 class FuzzyCodeBook : public CodeBook
45 {
46 public:
47 
48  typedef std::vector< std::vector< floatFeature > > MM;
50  //typedef ClassificationTrainingSet<std::vector<Feature>,Label> TS; // Alias for a Training set
55 
56  // Fuzzy membership matrix
57  MM memb;
58 
63  FuzzyCodeBook(const bool& _calib = false) : CodeBook(_calib)
64  {};
65 
66 
67 
79  FuzzyCodeBook(unsigned _n, unsigned _size, unsigned _data, bool _cal = false);
80 
81 
94  FuzzyCodeBook(unsigned _n, unsigned _size, unsigned _data, double _lower = 0, double _upper = 1, bool _cal = false);
95 
106  FuzzyCodeBook(unsigned _n, const ClassicTrainingVectors& _ts, const bool _use_rand_cvs = false);
107 
108  /*
109  * Constructs a fuzzy code book given a stream
110  * Parameter: _is The input stream
111  * Parameter: _size Size of code vectors (number of data points)
112  */
113 
114  FuzzyCodeBook(std::istream& _is, const unsigned _size = 0);
115 
120  virtual ~FuzzyCodeBook()
121  {};
122 
123 
127 #ifdef UNUSED // detected as unused 29.6.2018
128 
134  floatFeature membAt(unsigned _di, unsigned _ci) const;
135 #endif
136 
143  floatFeature& membAt(unsigned _di, unsigned _ci);
144 
145 
149  unsigned membClusters() const;
150  unsigned membVectors() const;
151 
152 
160  virtual FeatureVector& fuzzyTest(unsigned _in) const;
161 
169  virtual unsigned fuzzyTestIndex(unsigned _in) const;
170 
171 #ifdef UNUSED // detected as unused 29.6.2018
172 
176  virtual Label fuzzyApply(unsigned _in) const;
177 
178 
185  virtual void fuzzyCalibrate(ClassicTrainingVectors& _ts, Label _def = Label());
186 #endif
187 
193  virtual unsigned fuzzyWinner(unsigned _in) const;
194 
200  virtual unsigned fuzzyOutput(unsigned _in) const;
201 
207  virtual void classify(const ClassicTrainingVectors* _ts);
208 
209 #ifdef UNUSED // detected as unused 29.6.2018
210 
215  virtual void hardPartition();
216 #endif
217 
225  virtual TS alphaCore(TS _ts, double _alpha, unsigned _cluster) const;
226 
231  virtual void writeMembership(std::ostream& _os) const;
232 
237  virtual void readMembership(std::istream& _is);
238 
239 
245  virtual void saveObject(std::ostream& _os) const;
246 
247 
253  virtual void loadObject(std::istream& _is);
254 
255 
262  virtual void readSelf(std::istream& _is, const unsigned _size = 0);
263 
264 #ifdef UNUSED // detected as unused 29.6.2018
265 
269  virtual void printDensity(std::ostream& _os) const;
270 #endif
271 
272 private:
273 
274  // Dimensions of the membership matrix
275  unsigned numClusters;
276  unsigned numVectors;
277 
278 };
280 
281 
282 //-----------------------------------------------------------------------------
283 
284 #endif//XMIPPFUZZYCB_H
virtual void loadObject(std::istream &_is)
floatFeature & membAt(unsigned _di, unsigned _ci)
std::string Label
Definition: data_types.h:79
std::vector< std::vector< floatFeature > > MM
virtual unsigned fuzzyTestIndex(unsigned _in) const
MM memb
Alias for Fuzzy vectors.
ClassicTrainingVectors TS
Alias for Membership Matrix.
virtual ~FuzzyCodeBook()
virtual void saveObject(std::ostream &_os) const
float floatFeature
Definition: data_types.h:72
unsigned membVectors() const
virtual void classify(const ClassicTrainingVectors *_ts)
virtual unsigned fuzzyWinner(unsigned _in) const
virtual unsigned fuzzyOutput(unsigned _in) const
virtual void readMembership(std::istream &_is)
virtual void readSelf(std::istream &_is, const unsigned _size=0)
virtual void writeMembership(std::ostream &_os) const
basic_istream< char, std::char_traits< char > > istream
Definition: utilities.cpp:815
ClassificationTrainingSet< std::vector< floatFeature >, floatFeature > FV
Alias for a Training set.
unsigned membClusters() const
virtual FeatureVector & fuzzyTest(unsigned _in) const
FuzzyCodeBook(const bool &_calib=false)
std::vector< floatFeature > FeatureVector
Definition: data_types.h:86
virtual TS alphaCore(TS _ts, double _alpha, unsigned _cluster) const