at.tuwien.ifs.somtoolbox.layers
Class GrowingCellLayer

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.layers.GrowingCellLayer
All Implemented Interfaces:
Layer

public class GrowingCellLayer
extends Object
implements Layer

Version:
$Id: GrowingCellLayer.java 3590 2010-05-21 10:43:45Z mayer $
Author:
Johannes Inführ, Andreas Zweng

Nested Class Summary
 
Nested classes/interfaces inherited from interface at.tuwien.ifs.somtoolbox.layers.Layer
Layer.GridLayout, Layer.GridTopology
 
Field Summary
private  float alpha
          Reduction Factor for signal counter
private  double attractScale
          Scaling Factor for gravity between Units
private  double coherenceForceFactor
          Scaling Factor for gravity between Units independent of connectedness/distance
private  InputData data
          Data used for training
private  int dim
          Dimensions of the input-data
private  JFrame display
          Frame used to display the CellUnits
private  double[] emptyUnitMarkVector
          Weight-Vector for Units that fill holes in unitfield
private  float epsilonB
          Adaption Factor of best matching unit
private  float epsilonN
          Adaption Factor of neighbors of best matching unit
private  float eta
          Cutoff-Value for normalized probability density
private  int lamda
          Number of adaption steps between adding/removing of Units
private  int maxEpochs
          Number of Iterations on the input data
private  DistanceMetric metric
          Distance Metric used for GrowingCellStructures
private  QualityMeasure qualityMeasure
          QualityMesure used for GrowingCellStructures
private  Random rand
          Random Nr Generator for Weight-Vector initialisation
private  double repellingScale
          Scaling Factor for repulsion between Units
private  List<GrowingCellTetraheder> tetraheders
          List of Tetraheders formed by the Units
private  GrowingCellUnit[][] unitfield
          Storagearray for Units for export
private  List<GrowingCellUnit> units
          List of Units that get trained
 
Constructor Summary
GrowingCellLayer(int dim, boolean normalize, long randomSeed, InputData data)
          Std.
 
Method Summary
private  void addAttractingForce(GrowingCellUnit unitToMove, GrowingCellUnit unitForcing, double[] attractingForce)
          Calculate the attracting force between unitToMove and unitForcing and store it in attractingForce
private  void addRepellingForce(GrowingCellUnit unitToMove, GrowingCellUnit unitForcing, double[] force)
          Calculate the repelling force between unitToMove and unitForcing and store it in force
private  void analyzeDimension(GrowingCellUnit[][] data, int[] dimandoffset)
          Analyses maximum extension of the Units in data and their offset
private  void analyzeDimension(List<GrowingCellUnit> units, int[] dimandoffset)
          Analyses maximum extension of the Units in units and their offset
private  double calculateVoronoiEstimate(GrowingCellUnit u)
          Calculates the voronoi region estimate for unit u
private  void calculateVoronoiEstimate(List<GrowingCellUnit> neighborsToBe)
          Sets the voronoiEstimate of all neighborsToBe
private  void checkConsistency()
          Checks consistency of tetraheders and units
private  void clearMappedInput()
          Clears the mapped Input of every unit
private  void correctUnitPositions()
          Correct Unit Positions so that they stay at the upper left corner (10,10) and don't drift away
private  void decreaseSignalCounters()
          Decrease SignalCoutners of units by alpha percent
 Collection<? extends GrowingCellStructures> getAllSubMaps()
           
 Unit[] getAllUnits()
          Returns an array of all units in the map layer; the specific order of the units is unspecified.
 double[][] getComponentPlane(int component)
          Returns a component plane of the component specified by the argument component.
 double[][] getComponentPlane(int component, int z)
          Returns a component plane of the component specified by the argument component.
 InputData getData()
           
 int getDim()
           
private  double getDistance(double[] v1, double[] v2)
           
private  GrowingCellUnit getFarthestNeighbor(GrowingCellUnit unit)
           
 Layer.GridLayout getGridLayout()
           
 Layer.GridTopology getGridTopology()
           
 String getIdString()
          Returns the identification string of the map layer.
private  List<GrowingCellUnit> getInsertionTopologicalNeighbors(GrowingCellUnit sfwinner, GrowingCellUnit sfpartner)
           
 int getLevel()
          Returns the level of the map layer in a hierarchical model.
 double getMapDistance(int x1, int y1, int z1, int x2, int y2, int z2)
          Returns the distance between two units on the map grid.
 double getMapDistance(Unit u1, Unit u2)
          Returns the distance between two units on the map grid.
 DistanceMetric getMetric()
          Returns the metric used for distance calculation.
 int getNumberOfMappedInputs()
          Returns the total number of Inputs mapped on all units in the map layer.
 QualityMeasure getQualityMeasure()
          Returns the quality information.
 String getRevision()
          Returns the revision string of this layer.
private  GrowingCellUnit getSignalFrequencyWinner()
           
private  List<GrowingCellUnit> getTopologicalNeighbors(GrowingCellUnit unit)
           
private  List<GrowingCellTetraheder> getTouchedTetraheders(GrowingCellUnit u1, GrowingCellUnit u2)
          Returns Tetraheders that have u1 and u2 in common
 Unit getUnit(int x, int y)
          Returns the Unit at the position specified by the x and y arguments.
 Unit getUnit(int x, int y, int z)
          Returns the Unit at the position specified by the x and y arguments.
 Unit getUnitForDatum(String name)
          Returns the unit onto which the datum specified by its name by argument name is mapped.
private  GrowingCellUnit getWinner(InputDatum input)
           
 UnitDistance[] getWinnersAndDistances(InputDatum input, int numWinners)
           
 int getXSize()
          Returns the width of the map layer.
 int getYSize()
          Returns the height of the map layer.
 int getZSize()
          Returns the depth of the map layer.
private  void mapCompleteData(InputData data)
          Maps data to the units
private  void prepareForOutput()
          Moves the units for optimized space requirement The order along x and y axis stays the same, but the space between units gets reduced to 0, x is reduced before y so a narrow stripe along the y axis will emerge
private  void removeUnits(List<GrowingCellUnit> unitsToRemove)
          removes units specified in unitsToRemove and possible resulting disconnected units
 QualityMeasure train(InputData data, float epsilonB, float epsilonN, float alpha, int lamda, float eta, SOMProperties props)
          Trains the CellLayer with the given Parameters and returns the QualityMeasure
private  void trainNormal(InputData data, ProgressListener progressWriter)
          Trains the CellLayer with the secified InputData and logs to progressWriter
private  void updateInsertSignalCounters(GrowingCellUnit newUnit, List<GrowingCellUnit> neighbors)
          Updates the SignalCounters after an insert of a new unit
private  void updatePositions()
          Update the Position of Units in display-space by means of a simple physics simulation
private  void updateWinnerAndNeighbors(GrowingCellUnit winner, InputDatum currentInput)
          Updates the weight-vectors of winning unit and its neighbors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

units

private List<GrowingCellUnit> units
List of Units that get trained


tetraheders

private List<GrowingCellTetraheder> tetraheders
List of Tetraheders formed by the Units


data

private InputData data
Data used for training


dim

private int dim
Dimensions of the input-data


qualityMeasure

private QualityMeasure qualityMeasure
QualityMesure used for GrowingCellStructures


metric

private DistanceMetric metric
Distance Metric used for GrowingCellStructures


unitfield

private GrowingCellUnit[][] unitfield
Storagearray for Units for export


emptyUnitMarkVector

private double[] emptyUnitMarkVector
Weight-Vector for Units that fill holes in unitfield


rand

private Random rand
Random Nr Generator for Weight-Vector initialisation


epsilonB

private float epsilonB
Adaption Factor of best matching unit


epsilonN

private float epsilonN
Adaption Factor of neighbors of best matching unit


alpha

private float alpha
Reduction Factor for signal counter


lamda

private int lamda
Number of adaption steps between adding/removing of Units


eta

private float eta
Cutoff-Value for normalized probability density


maxEpochs

private int maxEpochs
Number of Iterations on the input data


display

private JFrame display
Frame used to display the CellUnits


attractScale

private double attractScale
Scaling Factor for gravity between Units


repellingScale

private double repellingScale
Scaling Factor for repulsion between Units


coherenceForceFactor

private double coherenceForceFactor
Scaling Factor for gravity between Units independent of connectedness/distance

Constructor Detail

GrowingCellLayer

public GrowingCellLayer(int dim,
                        boolean normalize,
                        long randomSeed,
                        InputData data)
Std. Constructor for Cell Layers

Parameters:
dim - Dimensions of the InputData
normalize - Wheter or not the Data is normalized
randomSeed - Seed to use for random components
data - InputData to be used for training
Method Detail

getAllUnits

public Unit[] getAllUnits()
Description copied from interface: Layer
Returns an array of all units in the map layer; the specific order of the units is unspecified.

Specified by:
getAllUnits in interface Layer

getComponentPlane

public double[][] getComponentPlane(int component)
Description copied from interface: Layer
Returns a component plane of the component specified by the argument component. Returns null, if the argument component is out of range.

Specified by:
getComponentPlane in interface Layer
Parameters:
component - the index of the component.
Returns:
a double matrix containing the values of the weight vectors' respective components, or null if argument component is invalid.

getComponentPlane

public double[][] getComponentPlane(int component,
                                    int z)
Description copied from interface: Layer
Returns a component plane of the component specified by the argument component. Returns null, if the argument component is out of range.

Specified by:
getComponentPlane in interface Layer
Parameters:
component - the index of the component.
z - TODO
Returns:
a double matrix containing the values of the weight vectors' respective components, or null if argument component is invalid.

getIdString

public String getIdString()
Description copied from interface: Layer
Returns the identification string of the map layer.

Specified by:
getIdString in interface Layer
Returns:
the identification string of the map layer.

getLevel

public int getLevel()
Description copied from interface: Layer
Returns the level of the map layer in a hierarchical model.

Specified by:
getLevel in interface Layer
Returns:
the level of the map layer in a hierarchical model.

getMapDistance

public double getMapDistance(int x1,
                             int y1,
                             int z1,
                             int x2,
                             int y2,
                             int z2)
Description copied from interface: Layer
Returns the distance between two units on the map grid.

Specified by:
getMapDistance in interface Layer
Parameters:
x1 - the horizontal position of the first unit.
y1 - the vertical position of the first unit.
z1 - the height position of the first unit.
x2 - the horizontal position of the second unit.
y2 - the vertical position of the second unit.
z2 - the height position of the second unit.
Returns:
the distance between two units.

getMapDistance

public double getMapDistance(Unit u1,
                             Unit u2)
Description copied from interface: Layer
Returns the distance between two units on the map grid.

Specified by:
getMapDistance in interface Layer
Parameters:
u1 - the first unit.
u2 - the second unit.
Returns:
the distance between two units.

getMetric

public DistanceMetric getMetric()
Description copied from interface: Layer
Returns the metric used for distance calculation.

Specified by:
getMetric in interface Layer
Returns:
the metric used for distance calculation.

getNumberOfMappedInputs

public int getNumberOfMappedInputs()
Description copied from interface: Layer
Returns the total number of Inputs mapped on all units in the map layer.

Specified by:
getNumberOfMappedInputs in interface Layer

getQualityMeasure

public QualityMeasure getQualityMeasure()
Description copied from interface: Layer
Returns the quality information.

Specified by:
getQualityMeasure in interface Layer
Returns:
the quality information, or null if not existent.

getRevision

public String getRevision()
Description copied from interface: Layer
Returns the revision string of this layer. This string should be written to output files to be able to trace back the implementation revision based on the CVS revision a map was trained with.

Specified by:
getRevision in interface Layer
Returns:
the revision string of this layer.

getUnit

public Unit getUnit(int x,
                    int y)
             throws LayerAccessException
Description copied from interface: Layer
Returns the Unit at the position specified by the x and y arguments. A LayerAccessException is thrown, if the coordinates are invalid.

Specified by:
getUnit in interface Layer
Parameters:
x - the horizontal position on the map layer.
y - the vertical position on the map layer.
Returns:
the unit at the specified position.
Throws:
LayerAccessException - if the coordinates are out of range.

getUnit

public Unit getUnit(int x,
                    int y,
                    int z)
             throws LayerAccessException
Description copied from interface: Layer
Returns the Unit at the position specified by the x and y arguments. A LayerAccessException is thrown, if the coordinates are invalid.

Specified by:
getUnit in interface Layer
Parameters:
x - the horizontal position on the map layer.
y - the vertical position on the map layer.
z - TODO
Returns:
the unit at the specified position.
Throws:
LayerAccessException - if the coordinates are out of range.

getUnitForDatum

public Unit getUnitForDatum(String name)
Description copied from interface: Layer
Returns the unit onto which the datum specified by its name by argument name is mapped.

Specified by:
getUnitForDatum in interface Layer
Parameters:
name - the name of the input datum to be searched for.
Returns:
the unit onto which the datum is mapped, or null if the datum is not found on the map.

getXSize

public int getXSize()
Description copied from interface: Layer
Returns the width of the map layer.

Specified by:
getXSize in interface Layer
Returns:
the width of the map layer.

getYSize

public int getYSize()
Description copied from interface: Layer
Returns the height of the map layer.

Specified by:
getYSize in interface Layer
Returns:
the height of the map layer.

getZSize

public int getZSize()
Description copied from interface: Layer
Returns the depth of the map layer.

Specified by:
getZSize in interface Layer
Returns:
the depth of the map layer.

getWinnersAndDistances

public UnitDistance[] getWinnersAndDistances(InputDatum input,
                                             int numWinners)

getDim

public int getDim()

getAllSubMaps

public Collection<? extends GrowingCellStructures> getAllSubMaps()

train

public QualityMeasure train(InputData data,
                            float epsilonB,
                            float epsilonN,
                            float alpha,
                            int lamda,
                            float eta,
                            SOMProperties props)
Trains the CellLayer with the given Parameters and returns the QualityMeasure

Parameters:
data - InputData
epsilonB - Adaption factor for best matching unit
epsilonN - Adaption factor for neighbours of best matching unit
alpha - Reduction factor for Signalcount
lamda - Interval between Adding/Removing of Units
eta - Cutoff-Value for normalised probability density
props - Additional properties to use (numIterations==maximum number of epochs, quality measure name)

mapCompleteData

private void mapCompleteData(InputData data)
Maps data to the units

Parameters:
data - InputData to map

clearMappedInput

private void clearMappedInput()
Clears the mapped Input of every unit


trainNormal

private void trainNormal(InputData data,
                         ProgressListener progressWriter)
Trains the CellLayer with the secified InputData and logs to progressWriter

Parameters:
data - Data used for training
progressWriter - ProgressListener for logging

updatePositions

private void updatePositions()
Update the Position of Units in display-space by means of a simple physics simulation


correctUnitPositions

private void correctUnitPositions()
Correct Unit Positions so that they stay at the upper left corner (10,10) and don't drift away


addAttractingForce

private void addAttractingForce(GrowingCellUnit unitToMove,
                                GrowingCellUnit unitForcing,
                                double[] attractingForce)
Calculate the attracting force between unitToMove and unitForcing and store it in attractingForce

Parameters:
unitToMove - unit to be moved
unitForcing - unit which applies the force
attractingForce - vector to add the resulting force to

addRepellingForce

private void addRepellingForce(GrowingCellUnit unitToMove,
                               GrowingCellUnit unitForcing,
                               double[] force)
Calculate the repelling force between unitToMove and unitForcing and store it in force

Parameters:
unitToMove - unit to be moved
unitForcing - unit which applies the fore
force - vector to add the resulting force to

removeUnits

private void removeUnits(List<GrowingCellUnit> unitsToRemove)
removes units specified in unitsToRemove and possible resulting disconnected units

Parameters:
unitsToRemove - the units that need to be removed

checkConsistency

private void checkConsistency()
Checks consistency of tetraheders and units


updateInsertSignalCounters

private void updateInsertSignalCounters(GrowingCellUnit newUnit,
                                        List<GrowingCellUnit> neighbors)
Updates the SignalCounters after an insert of a new unit

Parameters:
newUnit - the new inserted unit
neighbors - the neighbors of that unit

calculateVoronoiEstimate

private void calculateVoronoiEstimate(List<GrowingCellUnit> neighborsToBe)
Sets the voronoiEstimate of all neighborsToBe

Parameters:
neighborsToBe - Units that get an updated estimate

calculateVoronoiEstimate

private double calculateVoronoiEstimate(GrowingCellUnit u)
Calculates the voronoi region estimate for unit u

Parameters:
u - Unit to calculate the estimate for
Returns:
the calculated voronoi region volume estimate

getTouchedTetraheders

private List<GrowingCellTetraheder> getTouchedTetraheders(GrowingCellUnit u1,
                                                          GrowingCellUnit u2)
Returns Tetraheders that have u1 and u2 in common

Parameters:
u1 - CellUnit 1
u2 - CellUnit 2
Returns:
Tetraheders which are connected to u1 and u2

getInsertionTopologicalNeighbors

private List<GrowingCellUnit> getInsertionTopologicalNeighbors(GrowingCellUnit sfwinner,
                                                               GrowingCellUnit sfpartner)
Returns:
CellUnits which will be neighbors of a new unit between sfwinner and sfpartner

getSignalFrequencyWinner

private GrowingCellUnit getSignalFrequencyWinner()
Returns:
CellUnit with highest signal frequency

decreaseSignalCounters

private void decreaseSignalCounters()
Decrease SignalCoutners of units by alpha percent


updateWinnerAndNeighbors

private void updateWinnerAndNeighbors(GrowingCellUnit winner,
                                      InputDatum currentInput)
Updates the weight-vectors of winning unit and its neighbors

Parameters:
winner - the winning unit
currentInput - current input vector

getTopologicalNeighbors

private List<GrowingCellUnit> getTopologicalNeighbors(GrowingCellUnit unit)
Returns:
the topological neighbours of the unit

getWinner

private GrowingCellUnit getWinner(InputDatum input)
Returns:
unit closest to input

getFarthestNeighbor

private GrowingCellUnit getFarthestNeighbor(GrowingCellUnit unit)
Returns:
topological neighbor with the largest distance to unit

getDistance

private double getDistance(double[] v1,
                           double[] v2)
Returns:
Distance between v1 and v2

getData

public InputData getData()
Returns:
InputData that is used for training

prepareForOutput

private void prepareForOutput()
Moves the units for optimized space requirement The order along x and y axis stays the same, but the space between units gets reduced to 0, x is reduced before y so a narrow stripe along the y axis will emerge


analyzeDimension

private void analyzeDimension(GrowingCellUnit[][] data,
                              int[] dimandoffset)
Analyses maximum extension of the Units in data and their offset

Parameters:
data - array with units (with null Objects)

analyzeDimension

private void analyzeDimension(List<GrowingCellUnit> units,
                              int[] dimandoffset)
Analyses maximum extension of the Units in units and their offset

Parameters:
units - List of Units without null elements

getGridLayout

public Layer.GridLayout getGridLayout()
Specified by:
getGridLayout in interface Layer

getGridTopology

public Layer.GridTopology getGridTopology()
Specified by:
getGridTopology in interface Layer