83 if (verbosity == 1 || verbosity == 3)
89 for (std::vector<SomIn>::iterator
i = _ts.
theItems.begin();
100 for (std::vector<unsigned>::iterator it = neig.begin();it < neig.end();it++)
104 for (
unsigned j = 0;
j < v.size();
j++)
113 for (
unsigned it = 0 ; it < _som.
size(); it++)
116 double alp = alpha * (double) exp((
double)(-dist * dist / (2.0 * radius *
radius)));
118 for (
unsigned j = 0;
j < v.size();
j++)
119 v[
j] += ((*
i)[
j] - v[
j]) * alp;
125 if (verbosity == 1 || verbosity == 3)
131 sprintf(s,
"Iteration %d of %d.\n", (
int)t, (
int)
somNSteps);
137 if (verbosity == 1 || verbosity == 3)
162 for (
size_t i = 0;
i < _examples.size();
i++)
164 SomIn& theBest = _som.
test(_examples.theItems[
i]);
168 auto tmp = (int)((_examples.size() * 5) / 100);
169 if ((tmp == 0) && (
i != 0))
179 return (qerror / (
double) _examples.size());
222 catch (std::exception& e)
224 std::stringstream msg;
225 msg << e.what() << std::endl <<
"Error reading the SOM algorithm";
226 throw std::runtime_error(msg.str());
268 if (_nSteps == 0 || initial ==
final || _step >= _nSteps)
271 return final + ((initial -
final) *
272 ((
double)(_nSteps - _step) / (
double)_nSteps));
282 _os << initial << std::endl;
283 _os <<
final << std::endl;
299 catch (std::exception& e)
301 std::stringstream msg;
302 msg << e.what() << std::endl <<
"Error reading Descent class";
303 throw std::runtime_error(msg.str());
virtual void printSelf(std::ostream &_os) const
SomPos indexToPos(const unsigned &_i) const
double euclideanDistance(const std::vector< T > &_v1, const std::vector< T > &_v2)
virtual void OnReportOperation(const std::string &_rsOp)=0
SOM(Descent &_alpha, Descent &_radius, neighType _neighType, unsigned long _nSteps)
virtual void readSelf(std::istream &_is)
virtual void OnInitOperation(unsigned long _est_it)=0
virtual const unsigned & getVerbosity() const
unsigned long somNSteps
Neighborhood type for training (Bubble or Gaussian)
void radius(Descent _radius)
std::vector< unsigned > neighborhood(const SomPos &_center, double _radius) const
virtual FeatureVector & test(const FeatureVector &_in) const
virtual void printSelf(std::ostream &_os) const
virtual void train(ClassificationMap &_som, ClassicTrainingVectors &_ts) const
neighType somNeigh
radius(t)
virtual void loadObject(std::istream &_is)
std::vector< Item > theItems
virtual double test(const ClassificationMap &_som, const TS &_examples) const
virtual void readSelf(std::istream &_is)
virtual void OnProgress(unsigned long _it)=0
virtual double operator()(const unsigned _step, const unsigned _nSteps) const
basic_istream< char, std::char_traits< char > > istream
SomPos codVecPos(SomIn &_v)
virtual void loadObject(std::istream &_is)
virtual void saveObject(std::ostream &_os) const
virtual void saveObject(std::ostream &_os) const
void alpha(Descent _alpha)
void nSteps(const unsigned long &_nSteps)
Descent somRadius
alpha(t)
double neighDist(const SomPos &_center, const SomPos &_v) const