Xmipp  v3.23.11-Nereus
Public Member Functions | Protected Member Functions | List of all members
HEXALayout Class Reference

#include <map.h>

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

Public Member Functions

 HEXALayout ()
 
virtual double dist (const SomPos &_center, const SomPos &_v) const
 
virtual void localAve (const FuzzyMap *_som, const SomPos &_center, std::vector< double > &_aveVector) const
 
virtual double numNeig (const FuzzyMap *_som, const SomPos &_center) const
 
- Public Member Functions inherited from Layout
 Layout (const std::string &_id="")
 
virtual ~Layout ()
 
std::vector< unsigned > neighborhood (const ClassificationMap *_som, const SomPos &_center, double _radius) const
 
std::vector< unsigned > neighborhood (const FuzzyMap *_som, const SomPos &_center, double _radius) const
 
virtual bool isIn (const SomPos &_center, const SomPos &_v, double _radius) const
 
const std::string & id () const
 

Protected Member Functions

 HEXALayout (const std::string &_id)
 

Detailed Description

This class manages a layout in this way: (Neurons are in the center of the hexagons, so distance to the 6 immediate neighbors are 1) \(Xdim is ---—>)

HEXAGONAL:
O O O O O O O O O
O O O & & & O O O
O O & @ @ & O O O
O O & @ + @ & O O
O O & @ @ & O O O
O O O & & & O O O
O O O O O O O O O

Definition at line 729 of file map.h.

Constructor & Destructor Documentation

◆ HEXALayout() [1/2]

HEXALayout::HEXALayout ( )
inline

Generic constructor

Definition at line 736 of file map.h.

736  : Layout("hexa")
737  {};
Layout(const std::string &_id="")
Definition: map.h:581

◆ HEXALayout() [2/2]

HEXALayout::HEXALayout ( const std::string &  _id)
inlineprotected

Definition at line 758 of file map.h.

758  : Layout(_id)
759  {};
Layout(const std::string &_id="")
Definition: map.h:581

Member Function Documentation

◆ dist()

double HEXALayout::dist ( const SomPos _center,
const SomPos _v 
) const
virtual

Returns the distance between two vectors in their given position Parameter: _center Position of the center of neighborhood Parameter: _v Position of the code vector

Implements Layout.

Definition at line 646 of file map.cpp.

647 {
648  double ret;
649  double diff;
650  diff = _center.first - _v.first;
651 
652  if (((_center.second - _v.second) % 2) != 0)
653  {
654  if ((_center.second % 2) == 0)
655  {
656  diff -= 0.5;
657  }
658  else
659  {
660  diff += 0.5;
661  }
662  }
663  ret = diff * diff;
664  diff = _center.second - _v.second;
665  ret += 0.75 * diff * diff;
666  ret = (double) sqrt(ret);
667  return ret;
668 }
void sqrt(Image< double > &op)

◆ localAve()

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

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

Implements Layout.

Definition at line 677 of file map.cpp.

678 {
679 
680  int j;
681  int dim = _som->itemAt(0).size();
682  for (j = 0; j < dim; j++)
683  _aveVector[j] = 0.0;
684  int tmpi = _center.first;
685  int tmpj = _center.second;
686  int kk = 0;
687  if ((tmpi - 1) >= 0)
688  {
689  kk++;
690  for (j = 0; j < dim; j++)
691  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi - 1, tmpj)))[j]);
692  }
693  if ((tmpi + 1) < (int)_som->width())
694  {
695  kk++;
696  for (j = 0; j < dim; j++)
697  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi + 1, tmpj)))[j]);
698  }
699  if ((tmpj - 1) >= 0)
700  {
701  kk++;
702  for (j = 0; j < dim; j++)
703  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi, tmpj - 1)))[j]);
704  }
705  if ((tmpj + 1) < (int)_som->height())
706  {
707  kk++;
708  for (j = 0; j < dim; j++)
709  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi, tmpj + 1)))[j]);
710  }
711  if (((tmpj - 1) >= 0) && ((tmpi - 1) >= 0))
712  {
713  kk++;
714  for (j = 0; j < dim; j++)
715  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi - 1, tmpj - 1)))[j]);
716  }
717  if (((tmpj + 1) < (int)_som->height()) && ((tmpi - 1) >= 0))
718  {
719  kk++;
720  for (j = 0; j < dim; j++)
721  _aveVector[j] += (double)(_som->itemAt(_som->PosToIndex(SomPos(tmpi - 1, tmpj + 1)))[j]);
722  }
723  /* for (j = 0; j < dim; j++)
724  _aveVector[j] /= kk;*/
725  if (_som->height() == 1 || _som->width() == 1)
726  for (j = 0; j < dim; j++)
727  _aveVector[j] /= 2.0;
728  else
729  for (j = 0; j < dim; j++)
730  _aveVector[j] /= 6.0;
731 }
unsigned width() const
Definition: map.cpp:916
std::pair< long, long > SomPos
Definition: map.h:45
unsigned height() const
Definition: map.cpp:924
#define j
unsigned PosToIndex(const SomPos &_pos) const
Definition: map.cpp:1052
const Item & itemAt(unsigned _i) const
Definition: training_set.h:264

◆ numNeig()

double HEXALayout::numNeig ( const FuzzyMap _som,
const SomPos _center 
) const
virtual

Returns the average number of neighbors. Parameter: _center Reference to the center of neighborhood Parameter: _radius: Radius

Returns the average number of intermediate neighbors. Parameter: _center Reference to the center of neighborhood

Implements Layout.

Definition at line 738 of file map.cpp.

739 {
740  int tmpi = _center.first;
741  int tmpj = _center.second;
742  double kk = 0;
743  if ((tmpi - 1) >= 0)
744  {
745  kk++;
746  }
747  if ((tmpi + 1) < (int)_som->width())
748  {
749  kk++;
750  }
751  if ((tmpj - 1) >= 0)
752  {
753  kk++;
754  }
755  if ((tmpj + 1) < (int)_som->height())
756  {
757  kk++;
758  }
759  if (((tmpj - 1) >= 0) && ((tmpi - 1) >= 0))
760  {
761  kk++;
762  }
763  if (((tmpj + 1) < (int)_som->height()) && ((tmpi - 1) >= 0))
764  {
765  kk++;
766  }
767  if (_som->width() == 1 || _som->height() == 1)
768  return (kk / 2.0);
769  else
770  return (kk / 6.0);
771 }
unsigned width() const
Definition: map.cpp:916
unsigned height() const
Definition: map.cpp:924

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