Xmipp
v3.23.11-Nereus
|
#include <code_book.h>
Public Member Functions | |
CodeBook (const bool &_calib=false) | |
CodeBook (unsigned _n, unsigned _size, bool _cal=false) | |
CodeBook (unsigned _n, unsigned _size, floatFeature _lower=0, floatFeature _upper=1, bool _cal=false) | |
CodeBook (unsigned _n, const ClassicTrainingVectors &_ts, const bool _use_rand_cvs) | |
CodeBook (std::istream &_is) | |
virtual | ~CodeBook () |
virtual FeatureVector & | test (const FeatureVector &_in) const |
virtual unsigned | testIndex (const FeatureVector &_in) const |
virtual void | classify (const ClassicTrainingVectors *_ts) |
virtual const std::vector< unsigned > & | classifAt (const unsigned &_index) const |
virtual unsigned | classifSizeAt (const unsigned &_index) const |
virtual Label | apply (const FeatureVector &_in) const |
virtual void | calibrate (ClassicTrainingVectors &_ts, Label _def="") |
virtual unsigned | output (const FeatureVector &_in) const |
virtual void | printSelf (std::ostream &_os) const |
virtual void | readSelf (std::istream &_is, long _dim=-1, long _size=-1) |
virtual void | saveObject (std::ostream &_os) const |
virtual void | loadObject (std::istream &_is) |
virtual void | Normalize (const std::vector< ClassicTrainingVectors::statsStruct > &_varStats) |
virtual void | unNormalize (const std::vector< ClassicTrainingVectors::statsStruct > &_varStats) |
virtual void | printHistogram (std::ostream &_os) const |
virtual void | printQuantError (std::ostream &_os) const |
Public Member Functions inherited from ClassificationDataSet< FeatureVector, Label > | |
ClassificationDataSet () | |
virtual | ~ClassificationDataSet () |
Public Member Functions inherited from ClassificationTrainingSet< FeatureVector, Label > | |
ClassificationTrainingSet (const bool &_calib=true, unsigned _n=0) | |
ClassificationTrainingSet (std::istream &_is) | |
virtual | ~ClassificationTrainingSet () |
void | setSplit (float _tp, float _vp) |
splitIt | beginSubset (unsigned _um) |
splitIt | endSubset (unsigned _um) |
Returns an iterator to the end of the subset. More... | |
virtual void | add (const FeatureVector &_i, const Label &_tg) |
virtual void | add (const FeatureVector &_i) |
virtual bool | remove (unsigned int _idx) |
size_t | size () const |
const Label & | targetAt (unsigned _i) const |
Label & | targetAt (unsigned _i) |
const FeatureVector & | itemAt (unsigned _i) const |
FeatureVector & | itemAt (unsigned _i) |
bool | calibrated () const |
void | calibrated (const bool &_calib) |
void | clear () |
virtual void | readSelf (std::istream &_is) |
unsigned | numTargets () const |
virtual bool | swapItems (unsigned _i, unsigned _j) |
Public Attributes | |
std::vector< std::vector< unsigned > > | classifVectors |
std::vector< double > | aveDistances |
Public Attributes inherited from ClassificationTrainingSet< FeatureVector, Label > | |
std::vector< FeatureVector > | theItems |
std::vector< Label > | theTargets |
Protected Member Functions | |
void | readClassifVectors (std::istream &_is) |
void | writeClassifVectors (std::ostream &_os) const |
Protected Member Functions inherited from ClassificationTrainingSet< FeatureVector, Label > | |
void | computeNumTargets () |
void | checkCalibrated (std::istream &_is) |
void | readItems (std::istream &_is) |
void | writeCalibrated (std::ostream &_os) const |
void | writeItems (std::ostream &_os, bool _delim=false) const |
void | skipComments (std::istream &_is) const |
std::vector< FeatureVector >::const_iterator | itemsBegin () const |
std::vector< FeatureVector >::const_iterator | itemsEnd () const |
std::vector< Label >::const_iterator | targetsBegin () const |
std::vector< Label >::const_iterator | targetsEnd () const |
Additional Inherited Members | |
Public Types inherited from ClassificationDataSet< FeatureVector, Label > | |
typedef FeatureVector | In |
Class of input vectors. Usually a FeatureVector (vector of Feature) More... | |
typedef Label | Out |
Class of the target. Can be a double, string, unsigned, even a vector ... More... | |
typedef ClassificationTrainingSet< In, Out > | TS |
Training set. Set of vectors (training vectors), probably classified. More... | |
Public Types inherited from ClassificationTrainingSet< FeatureVector, Label > | |
enum | splitMode |
Ways the training set can be used. More... | |
enum | useMode |
use of samples More... | |
typedef std::multimap< unsigned, unsigned, std::less< unsigned > > | splitTS |
Training sets mode. More... | |
typedef splitTS::iterator | splitIt |
iterator More... | |
Protected Attributes inherited from ClassificationTrainingSet< FeatureVector, Label > | |
bool | isCalibrated |
splitTS | splitTrainingSet |
unsigned | nTargets |
This class implements a codebook. A codebook is a set of examples (each of them being a vector). These examples are usually labeled, ie, classified (the codebook is calibrated), but it is not necessary (the codebook is NOT calibrated). A codebook is the result obtained after one has trained some kind of algorithms. The way to classify a data once the algorithm has been trained is to look for the example in the code book that best matches the data to classify. Then, the same label of the example in the codebook is associated to the data wanted to be classified (if it is a calibrated codebook), or the example itself is returned (if it is a NO calibrated codebook) indicating with this that the data belongs to the same 'class' that the returned example.
Definition at line 57 of file code_book.h.
|
inline |
Default constructor Parameter: _calib Calibrated or not, that is, a CB with class labels or not
Definition at line 69 of file code_book.h.
CodeBook::CodeBook | ( | unsigned | _n, |
unsigned | _size, | ||
bool | _cal = false |
||
) |
Constructor. Constructs a codebook with initial code vectors at zero. from an unsigned integer to instantiate the template Parameter: _n Number of vectors Parameter: _size Size of code vectors Parameter: _cal Calibrated or not, that is, a CB with class labels or not
This class implements a codebook. A codebook is a set of examples (each of them being a vector). These examples are usually labeled, ie, classified (the codebook is calibrated), but it is not necessary (the codebook is NOT calibrated). A codebook is the result obtained after one has trained some kind of algorithms. The way to classify a data once the algorithm has been trained is to look for the example in the code book that best matches the data to classify. Then, the same label of the example in the codebook is associated to the data wanted to be classified (if it is a calibrated codebook), or the example itself is returned (if it is a NO calibrated codebook) indicating with this that the data belongs to the same 'class' that the returned example. Constructor. Constructs a codebook with initial code vectors at zero. from an unsigned integer to instantiate the template Parameter: _n Number of vectors Parameter: _size Size of code vectors Parameter: _lower Lower value for random elements Parameter: _upper Upper value for random elements Parameter: _cal Calibrated or not, that is, a CB with class labels or not
Definition at line 59 of file code_book.cpp.
CodeBook::CodeBook | ( | unsigned | _n, |
unsigned | _size, | ||
floatFeature | _lower = 0 , |
||
floatFeature | _upper = 1 , |
||
bool | _cal = false |
||
) |
Constructor. Constructs a codebook with random initial code vectors. from an unsigned integer to instantiate the template Parameter: _n Number of vectors Parameter: _size Size of code vectors Parameter: _lower Lower value for random elements Parameter: _upper Upper value for random elements Parameter: _cal Calibrated or not, that is, a CB with class labels or not
Definition at line 87 of file code_book.cpp.
CodeBook::CodeBook | ( | unsigned | _n, |
const ClassicTrainingVectors & | _ts, | ||
const bool | _use_rand_cvs | ||
) |
Constructor. Constructs a codebook with initial code vectors taken randomly from the training file. from an unsigned integer to instantiate the template Parameter: _n Number of vectors Parameter: _ts Training set; will be used to get initial values Parameter: _use_rand_cvs Use random code vector values
Definition at line 119 of file code_book.cpp.
CodeBook::CodeBook | ( | std::istream & | _is | ) |
Constructs a code book given a stream Parameter: _is The input stream
runtime_error | If there are problems with the stream |
Definition at line 162 of file code_book.cpp.
|
inlinevirtual |
|
virtual |
Returns the label associated to an input Parameter: _in Sample to classify
Implements ClassificationDataSet< FeatureVector, Label >.
Definition at line 316 of file code_book.cpp.
|
virtual |
Calibrates the code book Parameter: _ts The calibrated training set Parameter: _def Default target for non-calibrated vectors
runtime_error | If the training set is not calibrated |
Definition at line 328 of file code_book.cpp.
|
virtual |
Returns the list of input vectors associated to this code vector.
Definition at line 286 of file code_book.cpp.
|
virtual |
Returns the number of input vectors associated to this code vector.
Definition at line 300 of file code_book.cpp.
|
virtual |
Fills the classifVectors with the list of the best input vectors associated to it. Parameter: _ts Sample list to classify
Reimplemented in FuzzyCodeBook.
Definition at line 238 of file code_book.cpp.
|
virtual |
Loads the xmippCodeBook class from a stream. this method can be used to load the status of the class. Parameter: _is The output stream
Loads the CodeBook class from a stream. this method can be used to load the status of the class. Parameter: _is The output stream
Reimplemented from ClassificationTrainingSet< FeatureVector, Label >.
Reimplemented in FuzzyMap, ClassificationMap, and FuzzyCodeBook.
Definition at line 478 of file code_book.cpp.
|
virtual |
Normalize all features in the codebook Parameter: _varStats The normalization information
Definition at line 516 of file code_book.cpp.
|
virtual |
Returns the index of the codevector closest to an input. This is the method used to classify inputs Parameter: _in Sample to classify.
Implements ClassificationDataSet< FeatureVector, Label >.
Definition at line 350 of file code_book.cpp.
|
virtual |
Prints the histogram values of each codevector. Parameter: _os The the output stream
Prints the histogram values of each Fuzzy codevector. Parameter: _os The the output stream
Definition at line 264 of file code_book.cpp.
|
virtual |
Prints the Average Quantization Error of each codevector. Parameter: _os The the output stream
Definition at line 276 of file code_book.cpp.
|
virtual |
Standard output for a code book Parameter: _os The output stream
Standard output for a codebook Parameter: _os The output stream
Reimplemented from ClassificationTrainingSet< FeatureVector, Label >.
Reimplemented in FuzzyMap, and ClassificationMap.
Definition at line 361 of file code_book.cpp.
|
protected |
Reads the classif vectors from a stream. Parameter: _is The input stream
Definition at line 439 of file code_book.cpp.
|
virtual |
Standard input for a code book Parameter: _is The input stream
Standard input for a codebook Parameter: _is The input stream
Definition at line 370 of file code_book.cpp.
|
virtual |
Saves the xmippCodeBook class into a stream. this method can be used to save the status of the class. Parameter: _os The output stream
Saves the CodeBook class into a stream. this method can be used to save the status of the class. Parameter: _os The output stream
Reimplemented from ClassificationTrainingSet< FeatureVector, Label >.
Reimplemented in FuzzyMap, ClassificationMap, and FuzzyCodeBook.
Definition at line 466 of file code_book.cpp.
|
virtual |
Returns the code vector that represents the input in the codebook Parameter: _in Sample to classify
Definition at line 172 of file code_book.cpp.
|
virtual |
Returns the index to the code vector that represents the input in the codebook Parameter: _in Sample to classify
Definition at line 197 of file code_book.cpp.
|
virtual |
UnNormalize all features in the codebook Parameter: _varStats The normalization information
Definition at line 491 of file code_book.cpp.
|
protected |
Writes the classif vectors to a stream Parameter: _os The output stream
Definition at line 453 of file code_book.cpp.
std::vector< double > CodeBook::aveDistances |
Definition at line 62 of file code_book.h.
std::vector< std::vector <unsigned> > CodeBook::classifVectors |
Definition at line 61 of file code_book.h.