Xmipp  v3.23.11-Nereus
Public Member Functions | Protected Attributes | Friends | List of all members

#include <map.h>

Inheritance diagram for FuzzyMap:
Inheritance graph
[legend]
Collaboration diagram for FuzzyMap:
Collaboration graph
[legend]

Public Member Functions

 FuzzyMap (const std::string &_layout, unsigned _width, const unsigned &_height, const unsigned &_size, const double &_lower, const double &_upper)
 
 FuzzyMap (const std::string &_layout, unsigned _width, const unsigned &_height, const ClassicTrainingVectors &_ts, const bool _use_rand_cvs=false)
 
 FuzzyMap (std::istream &_is, const unsigned _size=0, bool _cv=true)
 
 FuzzyMap (const FuzzyMap &other)
 
virtual ~FuzzyMap ()
 
virtual void add (const FeatureVector &_v, const Label &_l=Label())
 
const std::string & layout () const
 
std::vector< unsigned > neighborhood (const SomPos &_center, double _radius) const
 
void neighborhood (const SomPos &_center, double _radius, std::vector< unsigned > &_neig) const
 
void localAve (const SomPos &_center, std::vector< double > &_aveVector) const
 
double neighDist (const SomPos &_center, const SomPos &_v) const
 
unsigned width () const
 
unsigned height () const
 
SomInitemAtPos (const SomPos &_pos)
 
const SomInitemAtPos (const SomPos &_pos) const
 
LabeltargetAtPos (const SomPos &_pos)
 
const LabeltargetAtPos (const SomPos &_pos) const
 
void clear ()
 
SomPos indexToPos (const unsigned &_i) const
 
unsigned PosToIndex (const SomPos &_pos) const
 
SomPos codVecPos (SomIn &_v)
 
SomPos applyPos (const unsigned &_in)
 
FuzzyMapoperator= (const FuzzyMap &op1)
 
virtual void printSelf (std::ostream &_os) const
 
virtual void readSelf (std::istream &_is, const unsigned _size=0)
 
virtual void saveObject (std::ostream &_os) const
 
virtual void loadObject (std::istream &_is)
 
virtual const LayoutgetLayout () const
 
- Public Member Functions inherited from FuzzyCodeBook
 FuzzyCodeBook (const bool &_calib=false)
 
 FuzzyCodeBook (unsigned _n, unsigned _size, unsigned _data, bool _cal=false)
 
 FuzzyCodeBook (unsigned _n, unsigned _size, unsigned _data, double _lower=0, double _upper=1, bool _cal=false)
 
 FuzzyCodeBook (unsigned _n, const ClassicTrainingVectors &_ts, const bool _use_rand_cvs=false)
 
 FuzzyCodeBook (std::istream &_is, const unsigned _size=0)
 
virtual ~FuzzyCodeBook ()
 
floatFeaturemembAt (unsigned _di, unsigned _ci)
 
unsigned membClusters () const
 
unsigned membVectors () const
 
virtual FeatureVectorfuzzyTest (unsigned _in) const
 
virtual unsigned fuzzyTestIndex (unsigned _in) const
 
virtual unsigned fuzzyWinner (unsigned _in) const
 
virtual unsigned fuzzyOutput (unsigned _in) const
 
virtual void classify (const ClassicTrainingVectors *_ts)
 
virtual TS alphaCore (TS _ts, double _alpha, unsigned _cluster) const
 
virtual void writeMembership (std::ostream &_os) const
 
virtual void readMembership (std::istream &_is)
 
- Public Member Functions inherited from CodeBook
 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 FeatureVectortest (const FeatureVector &_in) const
 
virtual unsigned testIndex (const FeatureVector &_in) const
 
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 readSelf (std::istream &_is, long _dim=-1, long _size=-1)
 
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)
 
virtual bool remove (unsigned int _idx)
 
size_t size () const
 
const LabeltargetAt (unsigned _i) const
 
LabeltargetAt (unsigned _i)
 
const FeatureVectoritemAt (unsigned _i) const
 
FeatureVectoritemAt (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)
 

Protected Attributes

const LayoutsomLayout
 
unsigned somWidth
 
unsigned somHeight
 
- Protected Attributes inherited from ClassificationTrainingSet< FeatureVector, Label >
bool isCalibrated
 
splitTS splitTrainingSet
 
unsigned nTargets
 

Friends

std::ostream & operator<< (std::ostream &_os, const FuzzyMap &_fsom)
 
std::istream & operator>> (std::istream &_is, FuzzyMap &_fsom)
 

Additional Inherited Members

- Public Types inherited from FuzzyCodeBook
typedef std::vector< std::vector< floatFeature > > MM
 
typedef ClassicTrainingVectors TS
 Alias for Membership Matrix. More...
 
typedef ClassificationTrainingSet< std::vector< floatFeature >, floatFeatureFV
 Alias for a Training set. More...
 
- 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, OutTS
 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...
 
- Public Attributes inherited from FuzzyCodeBook
MM memb
 Alias for Fuzzy vectors. More...
 
- Public Attributes inherited from CodeBook
std::vector< std::vector< unsigned > > classifVectors
 
std::vector< double > aveDistances
 
- Public Attributes inherited from ClassificationTrainingSet< FeatureVector, Label >
std::vector< FeatureVectortheItems
 
std::vector< LabeltheTargets
 
- Protected Member Functions inherited from CodeBook
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
 

Detailed Description

This class implements a Fuzzy Map of the type used by Fuzzy mapping Algorithms

Definition at line 308 of file map.h.

Constructor & Destructor Documentation

◆ FuzzyMap() [1/4]

FuzzyMap::FuzzyMap ( const std::string &  _layout,
unsigned  _width,
const unsigned &  _height,
const unsigned &  _size,
const double &  _lower,
const double &  _upper 
)

Constructs a Fuzzy SOM with random initial code vectors Parameter: _layout Type of layout Parameter: _width Width of the output plane Parameter: _height Height of the output plane Parameter: _size Size of code vectors Parameter: _lower Lower value for random elements Parameter: _upper Upper value for random elements

Definition at line 785 of file map.cpp.

788  : FuzzyCodeBook(_width*_height, _size, 0, _lower, _upper, false), somWidth(_width), somHeight(_height)
789 {
790  if (_layout == "HEXA")
791  {
792  auto *tmpLayout = new HEXALayout();
793  somLayout = tmpLayout;
794  }
795  else
796  {
797  auto *tmpLayout = new RECTLayout();
798  somLayout = tmpLayout;
799  }
800 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
unsigned somWidth
Definition: map.h:548
FuzzyCodeBook(const bool &_calib=false)

◆ FuzzyMap() [2/4]

FuzzyMap::FuzzyMap ( const std::string &  _layout,
unsigned  _width,
const unsigned &  _height,
const ClassicTrainingVectors _ts,
const bool  _use_rand_cvs = false 
)

Constructs a Fuzzy SOM with initial code vectors taken randomly from the training file. Parameter: _layout Type of layout Parameter: _width Width of the output plane Parameter: _height Height of the output plane Parameter: _ts Training set; will be used to get initial values Parameter: _use_rand_cvs Use random code vector pixel values

Definition at line 815 of file map.cpp.

818  : FuzzyCodeBook(_width*_height, _ts, _use_rand_cvs),
819  somWidth(_width), somHeight(_height)
820 {
821  if (_layout == "HEXA")
822  {
823  auto *tmpLayout = new HEXALayout();
824  somLayout = tmpLayout;
825  }
826  else
827  {
828  auto *tmpLayout = new RECTLayout();
829  somLayout = tmpLayout;
830  }
831 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
unsigned somWidth
Definition: map.h:548
FuzzyCodeBook(const bool &_calib=false)

◆ FuzzyMap() [3/4]

FuzzyMap::FuzzyMap ( std::istream &  _is,
const unsigned  _size = 0,
bool  _cv = true 
)

Construct a Fuzzy SOM from the code vectors in a stream Parameter: _is The stream Parameter: _size Size of code vectors (number of data points) Parameter: _cv If the stream holds a codevector file or a whole codebook file

Exceptions
runtime_errorIf there are problems with the stream

Construct a SOM from the code vectors in a stream Parameter: _is The stream Parameter: _size Size of code vectors (number of data points)

Exceptions
runtime_errorIf there are problems with the stream

Definition at line 839 of file map.cpp.

839  : FuzzyCodeBook(false)
840 {
841  somLayout = NULL;
842  if (_cv)
843  readSelf(_is, _size);
844  else
845  loadObject(_is);
846 }
const Layout * somLayout
Definition: map.h:542
virtual void loadObject(std::istream &_is)
Definition: map.cpp:1164
FuzzyCodeBook(const bool &_calib=false)
virtual void readSelf(std::istream &_is, const unsigned _size=0)
Definition: map.cpp:1113

◆ FuzzyMap() [4/4]

FuzzyMap::FuzzyMap ( const FuzzyMap other)
explicit

Definition at line 848 of file map.cpp.

848  : FuzzyCodeBook(false){
849  *this=other;
850 }
FuzzyCodeBook(const bool &_calib=false)

◆ ~FuzzyMap()

virtual FuzzyMap::~FuzzyMap ( )
inlinevirtual

Virtual destructor is needed

Definition at line 356 of file map.h.

357  {};

Member Function Documentation

◆ add()

void FuzzyMap::add ( const FeatureVector _v,
const Label _l = Label() 
)
virtual

This method throws an exception if called. There is no sense in adding vectors to a som

Exceptions
range_errorIf this method is called

Reimplemented from ClassificationTrainingSet< FeatureVector, Label >.

Definition at line 857 of file map.cpp.

858 {
859  throw std::runtime_error("You can't add vectors to a S.O.M.");
860 }

◆ applyPos()

SomPos FuzzyMap::applyPos ( const unsigned &  _in)

Returns the position of the code vector that represents the input in the som Parameter: _in Sample to classify (index to the sample)

Definition at line 1079 of file map.cpp.

1080 {
1081  return codVecPos(fuzzyTest(_in));
1082 }
SomPos codVecPos(SomIn &_v)
Definition: map.cpp:1069
virtual FeatureVector & fuzzyTest(unsigned _in) const

◆ clear()

void FuzzyMap::clear ( )

Clears the Fuzzy Som

Clears the Som

Definition at line 1019 of file map.cpp.

1020 {
1022  if (somLayout)
1023  delete somLayout;
1024  somWidth = 0;
1025  somHeight = 0;
1026 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
unsigned somWidth
Definition: map.h:548

◆ codVecPos()

SomPos FuzzyMap::codVecPos ( SomIn _v)

Returns the position in the som of a code vector Parameter: _v Reference to the code vector

Definition at line 1069 of file map.cpp.

1070 {
1071  return indexToPos(&_v - &(itemAt(0)));
1072 }
SomPos indexToPos(const unsigned &_i) const
Definition: map.cpp:1033
const FeatureVector & itemAt(unsigned _i) const
Definition: training_set.h:264

◆ getLayout()

virtual const Layout& FuzzyMap::getLayout ( ) const
inlinevirtual

Const Reference to the Map Layout

Definition at line 539 of file map.h.

540  {
541  return (Layout&) *somLayout;
542  };
const Layout * somLayout
Definition: map.h:542
Definition: map.h:573

◆ height()

unsigned FuzzyMap::height ( ) const

Returns the height of the SOM

Definition at line 924 of file map.cpp.

925 {
926  return somHeight;
927 }
unsigned somHeight
Definition: map.h:549

◆ indexToPos()

SomPos FuzzyMap::indexToPos ( const unsigned &  _i) const

Return the position associated to an index Parameter: _i Index of the code vector

Exceptions
out_of_range If _i is out of range

Definition at line 1033 of file map.cpp.

1034 {
1035  if (_i >= somWidth * somHeight)
1036  {
1037  std::ostringstream msg;
1038  msg << "Out of range. No item at position " << _i;
1039 
1040  throw std::out_of_range(msg.str());
1041  }
1042 
1043  return SomPos(_i % somWidth, _i / somWidth);
1044 }
unsigned somHeight
Definition: map.h:549
std::pair< long, long > SomPos
Definition: map.h:45
unsigned somWidth
Definition: map.h:548

◆ itemAtPos() [1/2]

SomIn & FuzzyMap::itemAtPos ( const SomPos _pos)

Returns a code vector given its position Parameter: _pos The position of the code vector

Exceptions
out_of_range If _pos is out of range

Definition at line 934 of file map.cpp.

935 {
936  if (_pos.first >= (signed)somWidth || _pos.second >= (signed)somHeight)
937  {
938  std::ostringstream msg;
939  msg << "Out of range. No item at position (" << _pos.first << ", " << _pos.second << ")";
940  throw std::out_of_range(msg.str());
941  }
942 
943  return itemAt((somWidth * _pos.second) + _pos.first);
944 }
unsigned somHeight
Definition: map.h:549
unsigned somWidth
Definition: map.h:548
const FeatureVector & itemAt(unsigned _i) const
Definition: training_set.h:264

◆ itemAtPos() [2/2]

const SomIn & FuzzyMap::itemAtPos ( const SomPos _pos) const

Returns a const reference to a code vector given its position Parameter: _pos The position of the code vector

Exceptions
out_of_range If _pos is out of range

Definition at line 952 of file map.cpp.

953 {
954  if (_pos.first >= (signed)somWidth || _pos.second >= (signed)somHeight)
955  {
956  std::ostringstream msg;
957  msg << "Out of range. No item at position (" << _pos.first << ", " << _pos.second << ")";
958  throw std::out_of_range(msg.str());
959  }
960 
961  return itemAt((somWidth * _pos.second) + _pos.first);
962 }
unsigned somHeight
Definition: map.h:549
unsigned somWidth
Definition: map.h:548
const FeatureVector & itemAt(unsigned _i) const
Definition: training_set.h:264

◆ layout()

const std::string & FuzzyMap::layout ( ) const

Returns the id of layout that som has

Definition at line 865 of file map.cpp.

866 {
867  return somLayout->id();
868 }
const Layout * somLayout
Definition: map.h:542
const std::string & id() const
Definition: map.cpp:536

◆ loadObject()

void FuzzyMap::loadObject ( std::istream &  _is)
virtual

Loads the FuzzyMap class from a stream. this method can be used to load the status of the class. Parameter: _is The output stream

Reimplemented from FuzzyCodeBook.

Definition at line 1164 of file map.cpp.

1165 {
1166  clear();
1167  std::string layout;
1168  _is >> layout;
1169  if (layout == "HEXA")
1170  {
1171  auto *tmpLayout = new HEXALayout();
1172  somLayout = tmpLayout;
1173  }
1174  else
1175  {
1176  auto *tmpLayout = new RECTLayout();
1177  somLayout = tmpLayout;
1178  }
1179  _is >> somWidth;
1180  _is >> somHeight;
1181  readClassifVectors(_is);
1182  readMembership(_is);
1184 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
const std::string & layout() const
Definition: map.cpp:865
void clear()
Definition: map.cpp:1019
virtual void readMembership(std::istream &_is)
unsigned somWidth
Definition: map.h:548
void readClassifVectors(std::istream &_is)
Definition: code_book.cpp:439
virtual void loadObject(std::istream &_is)
Definition: training_set.h:360

◆ localAve()

void FuzzyMap::localAve ( const SomPos _center,
std::vector< double > &  _aveVector 
) const

Returns the local average of a neuron in a non-const reference. (average of the sourounding vectors) Parameter: _center Reference to the center of neighborhood Parameter: _aveVector: returns the average vector

Definition at line 896 of file map.cpp.

897 {
898  somLayout->localAve(this, _center, _aveVector);
899 }
const Layout * somLayout
Definition: map.h:542
virtual void localAve(const FuzzyMap *_som, const SomPos &_center, std::vector< double > &_aveVector) const =0

◆ neighborhood() [1/2]

std::vector< unsigned > FuzzyMap::neighborhood ( const SomPos _center,
double  _radius 
) const

Returns the neighborhood of a neuron Parameter: _center Reference to the center of neighborhood Parameter: _radius Radius of neighbohood

Definition at line 875 of file map.cpp.

876 {
877  return somLayout->neighborhood(this, _center, _radius);
878 }
const Layout * somLayout
Definition: map.h:542
std::vector< unsigned > neighborhood(const ClassificationMap *_som, const SomPos &_center, double _radius) const
Definition: map.cpp:479

◆ neighborhood() [2/2]

void FuzzyMap::neighborhood ( const SomPos _center,
double  _radius,
std::vector< unsigned > &  _neig 
) const

Returns the neighborhood of a neuron in a non-const reference. Parameter: _center Reference to the center of neighborhood Parameter: _radius Radius of neighbohood

Definition at line 885 of file map.cpp.

886 {
887  _neig = somLayout->neighborhood(this, _center, _radius);
888 }
const Layout * somLayout
Definition: map.h:542
std::vector< unsigned > neighborhood(const ClassificationMap *_som, const SomPos &_center, double _radius) const
Definition: map.cpp:479

◆ neighDist()

double FuzzyMap::neighDist ( const SomPos _center,
const SomPos _v 
) const

Returns the distance between two neurons according to the Layout Parameter: _center Reference to the center of neighborhood Parameter: _v Position of the code vector

Definition at line 907 of file map.cpp.

908 {
909  return somLayout->dist(_center, _v);
910 }
const Layout * somLayout
Definition: map.h:542
virtual double dist(const SomPos &_center, const SomPos &_v) const =0

◆ operator=()

FuzzyMap & FuzzyMap::operator= ( const FuzzyMap op1)

Operator "=" Parameter: op1 FuzzyMap

Definition at line 1089 of file map.cpp.

1090 {
1091  std::stringstream _str;
1092  op1.printSelf(_str);
1093  readSelf(_str);
1094  return *this;
1095 }
virtual void printSelf(std::ostream &_os) const
Definition: map.cpp:1101
virtual void readSelf(std::istream &_is, const unsigned _size=0)
Definition: map.cpp:1113

◆ PosToIndex()

unsigned FuzzyMap::PosToIndex ( const SomPos _pos) const

Return the index associated to a position Parameter: _pos Position of the code vector

Exceptions
out_of_range If _i is out of range

Definition at line 1052 of file map.cpp.

1053 {
1054  if (_pos.first >= (signed)somWidth || _pos.second >= (signed)somHeight)
1055  {
1056  std::ostringstream msg;
1057  msg << "Out of range. No item at position (" << _pos.first << ", " << _pos.second << ")";
1058  throw std::out_of_range(msg.str());
1059  }
1060 
1061  return (unsigned)((somWidth * _pos.second) + _pos.first);
1062 }
unsigned somHeight
Definition: map.h:549
unsigned somWidth
Definition: map.h:548

◆ printSelf()

void FuzzyMap::printSelf ( std::ostream &  _os) const
virtual

Standard output for a fuzzy map Parameter: _os The output stream

Standard output for a Fuzzy SOM Parameter: _os The output stream

Reimplemented from CodeBook.

Definition at line 1101 of file map.cpp.

1102 {
1103  _os << itemAt(0).size() << " " <<
1104  somLayout->id() << " " << somWidth << " " << somHeight << " gaussian" << std::endl;
1105  writeItems(_os);
1106 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
const std::string & id() const
Definition: map.cpp:536
void writeItems(std::ostream &_os, bool _delim=false) const
Definition: training_set.h:561
unsigned somWidth
Definition: map.h:548
const FeatureVector & itemAt(unsigned _i) const
Definition: training_set.h:264

◆ readSelf()

void FuzzyMap::readSelf ( std::istream &  _is,
const unsigned  _size = 0 
)
virtual

Standard input for a fuzzy map Parameter: _size Size of code vectors (number of data points) Parameter: _is The input stream

Standard input for a Fuzzy SOM Parameter: _is The input stream

Reimplemented from FuzzyCodeBook.

Definition at line 1113 of file map.cpp.

1114 {
1115  clear();
1116  int dim;
1117  std::string layout;
1118  std::string str;
1119  _is >> dim;
1120  _is >> layout;
1121  if (layout == "HEXA")
1122  {
1123  auto *tmpLayout = new HEXALayout();
1124  somLayout = tmpLayout;
1125  }
1126  else
1127  {
1128  auto *tmpLayout = new RECTLayout();
1129  somLayout = tmpLayout;
1130  }
1131  _is >> somWidth;
1132  _is >> somHeight;
1133  str = integerToString(dim);
1134  str += " ";
1135  str += integerToString(somWidth * somHeight);
1136  str += " ";
1137  for (int i = str.size() - 1; i >= 0; i--)
1138  if (_is)
1139  _is.putback((char) str[i]);
1140  FuzzyCodeBook::readSelf(_is, _size);
1141 
1142 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
const std::string & layout() const
Definition: map.cpp:865
String integerToString(int I, int _width, char fill_with)
#define i
void clear()
Definition: map.cpp:1019
virtual void readSelf(std::istream &_is, const unsigned _size=0)
unsigned somWidth
Definition: map.h:548

◆ saveObject()

void FuzzyMap::saveObject ( std::ostream &  _os) const
virtual

Saves the FuzzyMap class into a stream. this method can be used to save the status of the class. Parameter: _os The output stream

Reimplemented from FuzzyCodeBook.

Definition at line 1150 of file map.cpp.

1151 {
1152  _os << somLayout->id() << " " << somWidth << " " << somHeight << std::endl;
1153  writeClassifVectors(_os);
1154  writeMembership(_os);
1156 }
unsigned somHeight
Definition: map.h:549
const Layout * somLayout
Definition: map.h:542
void writeClassifVectors(std::ostream &_os) const
Definition: code_book.cpp:453
virtual void saveObject(std::ostream &_os) const
Definition: training_set.h:349
const std::string & id() const
Definition: map.cpp:536
virtual void writeMembership(std::ostream &_os) const
unsigned somWidth
Definition: map.h:548

◆ targetAtPos() [1/2]

Label & FuzzyMap::targetAtPos ( const SomPos _pos)

Returns the target of a code vector given its position Parameter: _pos The position of the code vector

Definition at line 969 of file map.cpp.

970 {
971  if (!calibrated())
972  {
973  std::ostringstream msg;
974  msg << "The S.O.M. is not calibrated. No target at position ("
975  << _pos.first << ", " << _pos.second << ")";
976  throw std::out_of_range(msg.str());
977  }
978  if (_pos.first >= (signed)somWidth || _pos.second >= (signed)somHeight)
979  {
980  std::ostringstream msg;
981  msg << "Out of range. No target at position (" << _pos.first << ", "
982  << _pos.second << ")";
983  throw std::out_of_range(msg.str());
984  }
985 
986  return targetAt((somWidth * _pos.second) + _pos.first);
987 }
unsigned somHeight
Definition: map.h:549
const Label & targetAt(unsigned _i) const
Definition: training_set.h:221
unsigned somWidth
Definition: map.h:548

◆ targetAtPos() [2/2]

const Label & FuzzyMap::targetAtPos ( const SomPos _pos) const

Returns a const target of a code vector given its position Parameter: _pos The position of the code vector

Definition at line 994 of file map.cpp.

995 {
996  if (!calibrated())
997  {
998  std::ostringstream msg;
999  msg << "The S.O.M. is not calibrated. No target at position ("
1000  << _pos.first << ", " << _pos.second << ")";
1001  throw std::out_of_range(msg.str());
1002  }
1003  if (_pos.first >= (signed)somWidth || _pos.second >= (signed)somHeight)
1004  {
1005  std::ostringstream msg;
1006  msg << "Out of range. No target at position (" << _pos.first << ", "
1007  << _pos.second << ")";
1008  throw std::out_of_range(msg.str());
1009  }
1010 
1011  return targetAt((somWidth * _pos.second) + _pos.first);
1012 }
unsigned somHeight
Definition: map.h:549
const Label & targetAt(unsigned _i) const
Definition: training_set.h:221
unsigned somWidth
Definition: map.h:548

◆ width()

unsigned FuzzyMap::width ( ) const

Returns the width of the SOM

Definition at line 916 of file map.cpp.

917 {
918  return somWidth;
919 }
unsigned somWidth
Definition: map.h:548

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  _os,
const FuzzyMap _fsom 
)
friend

Definition at line 479 of file map.h.

480  {
481  _fsom.printSelf(_os);
482  return _os;
483  };
virtual void printSelf(std::ostream &_os) const
Definition: map.cpp:1101

◆ operator>>

std::istream& operator>> ( std::istream &  _is,
FuzzyMap _fsom 
)
friend

Definition at line 491 of file map.h.

492  {
493  _fsom.readSelf(_is);
494  return _is;
495  };
virtual void readSelf(std::istream &_is, const unsigned _size=0)
Definition: map.cpp:1113

Member Data Documentation

◆ somHeight

unsigned FuzzyMap::somHeight
protected

Definition at line 549 of file map.h.

◆ somLayout

const Layout* FuzzyMap::somLayout
protected

Definition at line 542 of file map.h.

◆ somWidth

unsigned FuzzyMap::somWidth
protected

Definition at line 548 of file map.h.


The documentation for this class was generated from the following files: