44 const unsigned& _height,
const unsigned& _size)
45 :
CodeBook(_width*_height, _size, false), somWidth(_width), somHeight(_height)
47 if (_layout ==
"HEXA")
79 const unsigned& _height,
const unsigned& _size,
const double& _lower,
83 if (_layout ==
"HEXA")
111 const bool _use_rand_cvs)
112 :
CodeBook(_width*_height, _ts, _use_rand_cvs),
115 if (_layout ==
"HEXA")
151 throw std::runtime_error(
"You can't add vectors to a S.O.M.");
199 #ifdef UNUSED // detected as unused 29.6.2018 209 std::ostringstream msg;
210 msg <<
"Out of range. No item at position (" << _pos.first <<
", " << _pos.second <<
")";
211 throw std::out_of_range(msg.str());
228 std::ostringstream msg;
229 msg <<
"Out of range. No item at position (" << _pos.first <<
", " << _pos.second <<
")";
230 throw std::out_of_range(msg.str());
236 #ifdef UNUSED // detected as unused 29.6.2018 245 std::ostringstream msg;
246 msg <<
"The S.O.M. is not calibrated. No target at position (" 247 << _pos.first <<
", " << _pos.second <<
")";
248 throw std::out_of_range(msg.str());
252 std::ostringstream msg;
253 msg <<
"Out of range. No target at position (" << _pos.first <<
", " 254 << _pos.second <<
")";
255 throw std::out_of_range(msg.str());
270 std::ostringstream msg;
271 msg <<
"The S.O.M. is not calibrated. No target at position (" 272 << _pos.first <<
", " << _pos.second <<
")";
273 throw std::out_of_range(msg.str());
277 std::ostringstream msg;
278 msg <<
"Out of range. No target at position (" << _pos.first <<
", " 279 << _pos.second <<
")";
280 throw std::out_of_range(msg.str());
310 std::ostringstream msg;
311 msg <<
"Out of range. No item at position " << _i;
313 throw std::out_of_range(msg.str());
328 std::ostringstream msg;
329 msg <<
"Out of range. No item at position (" << _pos.first <<
", " << _pos.second <<
")";
330 throw std::out_of_range(msg.str());
333 return (
unsigned)((
somWidth * _pos.second) + _pos.first);
346 #ifdef UNUSED // detected as unused 29.6.2018 352 SomPos ClassificationMap::applyPos(
const SomIn& _in)
365 std::stringstream _str;
377 _os <<
itemAt(0).size() <<
" " <<
396 if (layout ==
"hexa")
456 if (layout ==
"HEXA")
480 double _radius)
const 482 std::vector<unsigned> neig;
485 for (
unsigned i = 0 ;
i < _som->
size() ;
i++)
502 double _radius)
const 504 std::vector<unsigned> neig;
507 for (
unsigned i = 0 ;
i < _som->
size() ;
i++)
527 double _radius)
const 529 return (dist(_center, _v) <= _radius);
553 return ((
double)
sqrt((
double)(_center.first - _v.first)*(_center.first - _v.first) +
554 (_center.second - _v.second)*(_center.second - _v.second)));
566 int dim = _som->
itemAt(0).size();
567 double *ptrAveVector=&(_aveVector[0]);
568 memset(ptrAveVector,0,dim*
sizeof(
double));
569 int tmpi = _center.first;
570 int tmpj = _center.second;
576 for (j = 0; j < dim; j++)
577 ptrAveVector[j] += codevector[j];
579 if ((tmpi + 1) < (int)_som->
width())
583 for (j = 0; j < dim; j++)
584 ptrAveVector[j] += codevector[j];
590 for (j = 0; j < dim; j++)
591 ptrAveVector[j] += codevector[j];
593 if ((tmpj + 1) < (int)_som->
height())
597 for (j = 0; j < dim; j++)
598 ptrAveVector[j] += codevector[j];
601 for (j = 0; j < dim; j++)
602 ptrAveVector[j] *= 1.0/2.0;
604 for (j = 0; j < dim; j++)
605 ptrAveVector[j] *= 1.0/4.0;
614 int tmpi = _center.first;
615 int tmpj = _center.second;
621 if ((tmpi + 1) < (
int)_som->
width())
629 if ((tmpj + 1) < (int)_som->
height())
650 diff = _center.first - _v.first;
652 if (((_center.second - _v.second) % 2) != 0)
654 if ((_center.second % 2) == 0)
664 diff = _center.second - _v.second;
665 ret += 0.75 * diff * diff;
666 ret = (double)
sqrt(ret);
681 int dim = _som->
itemAt(0).size();
682 for (j = 0; j < dim; j++)
684 int tmpi = _center.first;
685 int tmpj = _center.second;
690 for (j = 0; j < dim; j++)
693 if ((tmpi + 1) < (int)_som->
width())
696 for (j = 0; j < dim; j++)
702 for (j = 0; j < dim; j++)
705 if ((tmpj + 1) < (int)_som->
height())
708 for (j = 0; j < dim; j++)
711 if (((tmpj - 1) >= 0) && ((tmpi - 1) >= 0))
714 for (j = 0; j < dim; j++)
717 if (((tmpj + 1) < (int)_som->
height()) && ((tmpi - 1) >= 0))
720 for (j = 0; j < dim; j++)
726 for (j = 0; j < dim; j++)
727 _aveVector[j] /= 2.0;
729 for (j = 0; j < dim; j++)
730 _aveVector[j] /= 6.0;
740 int tmpi = _center.first;
741 int tmpj = _center.second;
747 if ((tmpi + 1) < (
int)_som->
width())
755 if ((tmpj + 1) < (int)_som->
height())
759 if (((tmpj - 1) >= 0) && ((tmpi - 1) >= 0))
763 if (((tmpj + 1) < (int)_som->
height()) && ((tmpi - 1) >= 0))
786 const unsigned& _height,
const unsigned& _size,
const double& _lower,
787 const double& _upper)
790 if (_layout ==
"HEXA")
817 const bool _use_rand_cvs)
821 if (_layout ==
"HEXA")
859 throw std::runtime_error(
"You can't add vectors to a S.O.M.");
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());
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());
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());
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());
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());
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());
1037 std::ostringstream msg;
1038 msg <<
"Out of range. No item at position " << _i;
1040 throw std::out_of_range(msg.str());
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());
1061 return (
unsigned)((
somWidth * _pos.second) + _pos.first);
1091 std::stringstream _str;
1103 _os <<
itemAt(0).size() <<
" " <<
1121 if (layout ==
"HEXA")
1137 for (
int i = str.size() - 1;
i >= 0;
i--)
1139 _is.putback((
char) str[
i]);
1169 if (layout ==
"HEXA")
const SomIn & itemAtPos(const SomPos &_pos) const
SomPos indexToPos(const unsigned &_i) const
virtual double dist(const SomPos &_center, const SomPos &_v) const
SomPos codVecPos(SomIn &_v)
FuzzyMap(const std::string &_layout, unsigned _width, const unsigned &_height, const unsigned &_size, const double &_lower, const double &_upper)
void sqrt(Image< double > &op)
void localAve(const SomPos &_center, std::vector< double > &_aveVector) const
SomPos indexToPos(const unsigned &_i) const
FuzzyMap & operator=(const FuzzyMap &op1)
const std::string & layout() const
virtual void localAve(const FuzzyMap *_som, const SomPos &_center, std::vector< double > &_aveVector) const =0
void writeClassifVectors(std::ostream &_os) const
ClassificationMap(const ClassificationMap &op1)
virtual double dist(const SomPos &_center, const SomPos &_v) const
String integerToString(int I, int _width, char fill_with)
const Label & targetAt(unsigned _i) const
virtual void printSelf(std::ostream &_os) const
virtual bool isIn(const SomPos &_center, const SomPos &_v, double _radius) const
std::vector< unsigned > neighborhood(const SomPos &_center, double _radius) const
virtual FeatureVector & test(const FeatureVector &_in) const
std::vector< unsigned > neighborhood(const SomPos &_center, double _radius) const
virtual void saveObject(std::ostream &_os) const
virtual void saveObject(std::ostream &_os) const
const std::string & layout() const
virtual void loadObject(std::istream &_is)
virtual void add(const FeatureVector &_v, const Label &_l=Label())
ClassificationMap & operator=(const ClassificationMap &op1)
std::pair< long, long > SomPos
virtual void printSelf(std::ostream &_os) const
virtual void saveObject(std::ostream &_os) const
virtual void add(const FeatureVector &_v, const Label &_l=Label())
virtual void readMembership(std::istream &_is)
virtual void loadObject(std::istream &_is)
const std::string & id() const
virtual void readSelf(std::istream &_is, const unsigned _size=0)
unsigned PosToIndex(const SomPos &_pos) const
virtual void writeMembership(std::ostream &_os) const
const Label & targetAtPos(const SomPos &_pos) const
basic_istream< char, std::char_traits< char > > istream
void writeItems(std::ostream &_os, bool _delim=false) const
virtual double numNeig(const FuzzyMap *_som, const SomPos &_center) const
SomPos codVecPos(SomIn &_v)
std::vector< unsigned > neighborhood(const ClassificationMap *_som, const SomPos &_center, double _radius) const
Label & targetAtPos(const SomPos &_pos)
virtual void readSelf(std::istream &_is)
virtual FeatureVector & fuzzyTest(unsigned _in) const
unsigned PosToIndex(const SomPos &_pos) const
void readClassifVectors(std::istream &_is)
double neighDist(const SomPos &_center, const SomPos &_v) const
SomPos applyPos(const unsigned &_in)
SomIn & itemAtPos(const SomPos &_pos)
virtual double numNeig(const FuzzyMap *_som, const SomPos &_center) const
virtual void loadObject(std::istream &_is)
virtual double dist(const SomPos &_center, const SomPos &_v) const =0
std::vector< floatFeature > FeatureVector
const FeatureVector & itemAt(unsigned _i) const
double neighDist(const SomPos &_center, const SomPos &_v) const
virtual void localAve(const FuzzyMap *_som, const SomPos &_center, std::vector< double > &_aveVector) const
virtual void localAve(const FuzzyMap *_som, const SomPos &_center, std::vector< double > &_aveVector) const
virtual void readSelf(std::istream &_is, long _dim=-1, long _size=-1)
virtual void readSelf(std::istream &_is, const unsigned _size=0)