45 #ifdef UNUSED // detected as unused 29.6.2018 49 double KerDenSOM::getSigma()
88 for (
size_t i = 0;
i < _examples.size();
i++)
94 auto tmp = (int)((_examples.size() * 5) / 100);
95 if ((tmp == 0) && (
i != 0))
105 return (qerror / (
double) _examples.size());
123 double *ptrTmpMap_cc=&(
tmpMap[cc][0]);
124 memset(ptrTmpMap_cc,0,
dim*
sizeof(
double));
125 double &tmpDens_cc=
tmpDens[cc];
132 auto tmpU = (double) _som->
memb[
vv][cc];
135 for (
size_t j = 0;
j <
dim;
j++)
136 ptrTmpMap_cc[
j] += tmpU * ptrExample[
j];
142 double convergence = 1;
145 double *ptrTmpV=&(
tmpV[0]);
146 while ((convergence > 1e-5) && (t2 < 100))
155 double *ptrTmpMap_cc=&(
tmpMap[cc][0]);
156 double iTmpDens_cc=1.0/
tmpDens[cc];
158 for (
size_t j = 0;
j <
dim;
j++)
160 double tmpU = (ptrTmpMap_cc[
j] + ptrTmpV[
j] * _reg) * iTmpDens_cc;
161 stopError1 += fabs(ptrCodeVector_cc[
j] - tmpU);
162 stopError2 += fabs(tmpU);
166 convergence = stopError1 / stopError2;
176 double stopError = 1e10;
182 if (verbosity == 1 || verbosity == 3)
187 updateU(_som, _examples, _sigma, alpha);
189 stopError = fabs(_sigma / ts2 - 1.);
191 updateV(_som, _examples, _reg);
192 if (verbosity == 1 || verbosity == 3)
197 sprintf(s,
"Iteration %d of %d. variation: %g\n", (
int)iter, (
int)
somNSteps, stopError);
202 if (verbosity == 1 || verbosity == 3)
225 for (
size_t j = 0;
j <
dim;
j++)
227 double diff=(double)(*ptrExample++) - (double)(*ptrCodeVector++);
230 t += r * (double)(_som->
memb[
vv][cc]);
233 return (
double)(t / (double)(numVectors*
dim));
250 std::vector<double> &tmpMap_cc=
tmpMap[cc];
251 double *ptrTmpMap_cc0=&tmpMap_cc[0];
252 memset(ptrTmpMap_cc0,0,
dim*
sizeof(
double));
253 double &tmpDens_cc=
tmpDens[cc];
257 double tmpU = _som->
memb[
vv][cc];
260 double *ptrTmpMap_cc=ptrTmpMap_cc0;
261 for (
size_t j = 0;
j <
dim;
j++)
263 *ptrTmpMap_cc += tmpU * (*ptrExample);
272 const std::vector<double> &tmpMap_cc=
tmpMap[cc];
273 double itmpDens_cc=1.0/
tmpDens[cc];
275 for (
size_t j = 0;
j <
dim;
j++)
277 double tmpU =tmpMap_cc[
j] * itmpDens_cc;
321 auxDist += pow(tmp, 2);
357 #ifdef UNUSED // detected as unused 29.6.2018 362 double KerDenSOM::randApproxGVC(
const TS* _examples,
const FuzzyMap* _som,
double _dataSD,
double _reg)
369 TS tmpTS(*_examples);
374 for (j = 0; j <
dim; j++)
378 for (j = 0; j <
dim; j++)
379 VV[j] += (_examples->theItems[vv][j] - _som->
theItems[cc][j]) * _som->
memb[
vv][cc];
381 for (j = 0; j <
dim; j++)
382 num += VV[j] * VV[j];
388 for (j = 0; j <
dim; j++)
389 tmpTS.theItems[vv][j] +=
rnd_gaus() * _dataSD;
391 updateV(&tmpSOM, &tmpTS, _reg);
397 for (j = 0; j <
dim; j++)
401 for (j = 0; j <
dim; j++)
402 VV[j] += (tmpTS.theItems[vv][j] - tmpSOM.
theItems[cc][j] - _examples->theItems[vv][j] + _som->
theItems[cc][j]) * _som->
memb[
vv][cc];
405 for (j = 0; j <
dim; j++)
410 return (
double) num / den;
429 std::cout <<
"Data (1..nd, 1..nv) " << std::endl;
430 for (
size_t i = 0;
i < _ts->size();
i++)
432 for (
size_t j = 0;
j < _ts->theItems[0].size();
j++)
434 std::cout <<
i + 1 <<
" " <<
j + 1 <<
" " << _ts->theItems[
i][
j] << std::endl;
447 std::cout <<
"Code vectors (1..ni, 1..nj, 1..nv) " << std::endl;
448 for (
size_t i = 0;
i < _som->
size();
i++)
452 for (
size_t j = 0;
j < _som->
theItems[0].size();
j++)
453 std::cout << tmpi + 1 <<
" " << tmpj + 1 <<
" " <<
j + 1 <<
" " << _som->
theItems[
i][
j] << std::endl;
464 std::cout <<
" Memberships (1..nd,1..ni,1..nj)" << std::endl;
465 for (
size_t i = 0;
i < _ts->size();
i++)
467 for (
size_t j = 0;
j < _som->
size();
j++)
471 std::cout <<
i + 1 <<
" " << tmpi + 1 <<
" " << tmpj + 1 <<
" " << _som->
memb[
i][
j] << std::endl;
476 #ifdef UNUSED // detected as unused 29.6.2018 485 FILE* F = fopen(_fname.c_str(),
"w");
492 if (_ts->isNormalized())
494 if (_ts->getNormalizationInfo().size() != _som->
theItems[0].size())
496 std::stringstream msg;
497 msg <<
"Normalization information does not coincide with codebook structure";
498 throw std::runtime_error(msg.str());
500 for (
unsigned it = 0; it < _som->
size(); it++)
502 for (
unsigned i = 0;
i < _som->
theItems[0].size();
i++)
505 _som->
theItems[it][i] = _som->
theItems[it][i] * _ts->getNormalizationInfo()[
i].sd + _ts->getNormalizationInfo()[
i].mean;
513 for (
size_t i = 0;
i < _som->
size();
i++)
515 for (
size_t j = 0;
j < _som->
theItems[0].size();
j++)
void showU(FuzzyMap *_som, const TS *_ts)
double euclideanDistance(const std::vector< T > &_v1, const std::vector< T > &_v2)
MM memb
Alias for Fuzzy vectors.
void localAve(const SomPos &_center, std::vector< double > &_aveVector) const
SomPos indexToPos(const unsigned &_i) const
const std::string & layout() const
virtual void OnReportOperation(const std::string &_rsOp)=0
virtual double updateSigmaII(FuzzyMap *_som, const TS *_examples, const double &_reg, const double &_alpha)=0
virtual void OnInitOperation(unsigned long _est_it)=0
virtual const unsigned & getVerbosity() const
virtual const Layout & getLayout() const
virtual double test(const FuzzyMap &_som, const TS &_examples) const
virtual void updateV1(FuzzyMap *_som, const TS *_examples)
void init_random_generator(int seed)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
virtual double updateU(FuzzyMap *_som, const TS *_examples, const double &_sigma, double &_alpha)=0
void showV(FuzzyMap *_som)
std::vector< std::vector< double > > tmpMap
virtual void initU(FuzzyMap *_som)
std::vector< Item > theItems
std::pair< long, long > SomPos
void setAnnSteps(const unsigned long &_annSteps)
virtual void OnProgress(unsigned long _it)=0
virtual double mainIterations(FuzzyMap *_som, const TS *_examples, double &_sigma, const double &_reg)
virtual double numNeig(const FuzzyMap *_som, const SomPos &_center) const =0
virtual void updateV(FuzzyMap *_som, const TS *_examples, const double &_sigma)
virtual FeatureVector & fuzzyTest(unsigned _in) const
virtual double updateSigmaI(FuzzyMap *_som, const TS *_examples)
fprintf(glob_prnt.io, "\)
void showX(const TS *_ts)
std::vector< double > tmpDens
unsigned int randomize_random_generator()
std::vector< double > tmpV
virtual void updateU1(FuzzyMap *_som, const TS *_examples)
std::vector< floatFeature > FeatureVector
void nSteps(const unsigned long &_nSteps)