public class Unit extends InputContainer
Unit
. Labels can be assigned to a Unit
to describe the mapped
data. A Unit
can also have an assigned map for use in hierarchical models.mappedSOM
should be made more general than it is now. FIXME: similar to what should be
done with GrowingLayer
, we should make a Unit3D version out of this for 3D SOMs, to keep the memory
fingerprint small, and avoid overloading many methods with 2D and 3D params, which makes it very hard to readModifier and Type | Class and Description |
---|---|
static class |
Unit.FeatureWeightMode
Types of feature weighting modes
|
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<InputDatum> |
batchSomNeighbourhood |
private Label[] |
bestcontextWeights |
static java.lang.String |
CONTEXT |
private Label[] |
contextGateLabels |
private int |
dim |
private double[] |
featureWeights |
static java.lang.String |
GATE |
private Label[] |
gateWeights |
private static int |
INIT_INTERVAL_INTERPOLATE |
private static int |
INIT_PCA |
private static int |
INIT_RANDOM |
private static int |
INIT_VECTOR |
private Label[] |
kaskiGateLabels |
private Label[] |
kaskiLabels |
static java.lang.String |
KEYWORDS |
private Label[] |
labels |
static java.lang.String |
LABELSOM |
private Layer |
layer |
private GrowingSOM |
mappedSOM |
private double |
quantizationError |
private double[] |
weightVector |
private int |
xPos |
private int |
yPos |
private int |
zPos |
Constructor and Description |
---|
Unit(Layer l,
int x,
int y,
double[] vec)
Constructs a
Unit on Layer specified by argument layer at position
x /y with a given weight vector vec . |
Unit(Layer l,
int x,
int y,
int z,
double[] vec)
Constructs a
Unit on Layer specified by argument layer at position
x /y with a given weight vector vec . |
Unit(Layer l,
int x,
int y,
int z,
int d,
java.util.Random rand,
boolean norm)
Constructs a
Unit on Layer specified by argument layer at position
x /y with a randomly initialized weight vector of dimension d . |
Unit(Layer l,
int x,
int y,
int z,
int d,
java.util.Random rand,
boolean norm,
int initialisationMode) |
Unit(Layer l,
int x,
int y,
int d,
java.util.Random rand,
boolean norm)
Constructs a
Unit on Layer specified by argument layer at position
x /y with a randomly initialized weight vector of dimension d . |
Unit(Layer l,
int x,
int y,
int d,
java.util.Random rand,
boolean norm,
int initialisationMode) |
Modifier and Type | Method and Description |
---|---|
void |
addBatchSomNeighbour(InputDatum d) |
void |
addMappedInput(InputData data,
boolean calcQE)
Map all the input vectors contained in specified
InputData object onto this unit. |
void |
addMappedInput(InputDatum datum,
boolean calcQE)
Adds a single input datum to the unit.
|
void |
addMappedInput(java.lang.String name,
double dist,
boolean calcQE)
Convenience method to add an input datum specified by its name and distance.
|
void |
calculateQuantizationError()
Recalculates the quantization error for this unit.
|
void |
clearBatchSomList() |
void |
clearLabels()
Removes the labels of this unit.
|
void |
clearMappedInput()
Removes the mapped input data and sets this units quantization error to 0.
|
void |
copyFeatureWeights(double[] featureWeights) |
Label[] |
getBestContextWeights() |
Label[] |
getContextGateLabels() |
int |
getDim() |
double[] |
getFeatureWeights() |
Label[] |
getGateWeights() |
Label[] |
getKaskiGateLabels() |
Label[] |
getKaskiLabels() |
Label[] |
getLabels() |
Label[] |
getLabels(java.lang.String type)
Returns an array of labels or null, if no labels are assigned to this unit.
|
Layer |
getLayer()
Returns the layer of units this unit is part of.
|
java.lang.String |
getMapIdString()
Returns the map identification string of this unit's layer.
|
int |
getMapLevel()
Returns the level of this unit's layer in a hierarchy of maps.
|
GrowingSOM |
getMappedSOM()
Returns the map assigned to this unit or
null otherwise. |
int |
getMapXSize()
Returns the width of this unit's map.
|
int |
getMapYSize()
Returns the height of this unit's map.
|
int |
getMapZSize()
Returns the depth of this unit's map.
|
java.lang.String |
getUnitLabels() |
double[] |
getWeightVector()
Returns the weight vector of this unit.
|
void |
getWeightVectorFromBatchSomNeighbourhood() |
int |
getXPos()
Returns the horizontal position of this unit on the map it is part of.
|
int |
getYPos()
Returns the vertical position of this unit on the map it is part of.
|
int |
getZPos()
Returns the depth position of this unit on the map it is part of.
|
void |
initWeightVectorBySample(InputDatum datum)
Sets this unit's weight vector to the vector of the input datum specified by argument
datum . |
boolean |
isTopLeftUnit() |
java.lang.String |
printCoordinates() |
java.lang.String |
printCoordinatesSpaceSeparated() |
java.lang.String |
printUnitDetails(InputData inputData,
TemplateVector tv) |
void |
removeMappedInput(java.lang.String label) |
void |
restoreBestContextWeightLabels(int nrbestcontext,
java.lang.String[] bestContextWeightUnitLabels) |
void |
restoreContextGateLabels(int nrContextGate,
java.lang.String[] contextGateUnitLabels) |
void |
restoreGateWeightLabels(int nrgateweights,
java.lang.String[] gateWeightUnitLabels) |
void |
restoreKaskiGateLabels(int nrKaskiGate,
java.lang.String[] kaskiGateUnitabels) |
void |
restoreKaskiLabels(int nrKaski,
java.lang.String[] kaskiUnitLabels,
double[] kaskiUnitLabelsWgt) |
void |
restoreLabels(int nrUnitLabels,
java.lang.String[] unitLabels,
double[] unitLabelsQe,
double[] unitLabelsWgt)
Restores the labels of a unit based on the information provided by the arguments.
|
void |
restoreMappings(int nrVecsMapped,
java.lang.String[] mappedVecs,
double[] mappedVecsDist)
Restores the mapped input data of a unit based on the information provided by the arguments.
|
void |
setContextGateLabels(Label[] context_gate_labels) |
void |
setFeatureWeights(double[] featureWeights) |
void |
setKaskiGateLabels(Label[] kaski_gate_labels) |
void |
setLabels(Label[] labels)
Assigns labels to this unit.
|
void |
setMappedSOM(GrowingSOM mappedSOM)
Assigns a map to this unit.
|
(package private) void |
setPositions(int x,
int y,
int z) |
void |
setWeightVector(double[] vector)
Sets the weight vector of this unit.
|
java.lang.String |
toString() |
void |
updatePosition(int x,
int y) |
void |
updatePosition(int x,
int y,
int z)
Sets the coordinates of this unit on the map, if they have changed.
|
addMappedInput, clearMappedInputs, getInputIndex, getMappedInputDistance, getMappedInputDistance, getMappedInputDistances, getMappedInputName, getMappedInputNames, getMappedInputNamesAsList, getNumberOfMappedInputs, isMapped
public static final java.lang.String KEYWORDS
public static final java.lang.String GATE
public static final java.lang.String CONTEXT
public static final java.lang.String LABELSOM
private static final int INIT_RANDOM
private static final int INIT_INTERVAL_INTERPOLATE
private static final int INIT_VECTOR
private static final int INIT_PCA
private int dim
private Label[] labels
private Label[] kaskiGateLabels
private Label[] kaskiLabels
private Label[] gateWeights
private Label[] bestcontextWeights
private Label[] contextGateLabels
private Layer layer
private GrowingSOM mappedSOM
private double quantizationError
private double[] weightVector
private double[] featureWeights
private int xPos
private int yPos
private int zPos
private java.util.ArrayList<InputDatum> batchSomNeighbourhood
public Unit(Layer l, int x, int y, double[] vec)
Unit
on Layer
specified by argument layer
at position
x
/y
with a given weight vector vec
.l
- the layer that contains this Unit
.x
- the horizontal position on the layer
.y
- the vertical position on the layer
.vec
- the weight vector.public Unit(Layer l, int x, int y, int z, double[] vec)
Unit
on Layer
specified by argument layer
at position
x
/y
with a given weight vector vec
.l
- the layer that contains this Unit
.x
- the horizontal position on the layer
.y
- the vertical position on the layer
.z
- the depth position on the layer
.vec
- the weight vector.public Unit(Layer l, int x, int y, int d, java.util.Random rand, boolean norm)
Unit
on Layer
specified by argument layer
at position
x
/y
with a randomly initialized weight vector of dimension d
. Argument
norm
determines whether the weight vector should be normalized or not. TODO: This might be change in
the future due to unflexibility regarding hard coded normalization methods.l
- the layer that contains this Unit
.x
- the horizontal position on the layer
.y
- the vertical position on the layer
.d
- the dimensionality of the weight vector.rand
- a random number generator provided by the caller.norm
- the type of normalization (see text above).public Unit(Layer l, int x, int y, int z, int d, java.util.Random rand, boolean norm)
Unit
on Layer
specified by argument layer
at position
x
/y
with a randomly initialized weight vector of dimension d
. Argument
norm
determines whether the weight vector should be normalized or not. TODO: This might be change in
the future due to unflexibility regarding hard coded normalization methods.l
- the layer that contains this Unit
.x
- the horizontal position on the layer
.y
- the vertical position on the layer
.z
- the depth position on the layer
.d
- the dimensionality of the weight vector.rand
- a random number generator provided by the caller.norm
- the type of normalization (see text above).public Unit(Layer l, int x, int y, int d, java.util.Random rand, boolean norm, int initialisationMode)
public Unit(Layer l, int x, int y, int z, int d, java.util.Random rand, boolean norm, int initialisationMode)
public void addMappedInput(InputDatum datum, boolean calcQE)
datum
- the input datum to be added.calcQE
- determines if the quantization error should be recalculated.addMappedInput(String, double, boolean)
public void addMappedInput(InputData data, boolean calcQE)
InputData
object onto this unit.data
- The container for input vectorcalcQE
- determines if the quantization error should be recalculated.addMappedInput(InputDatum, boolean)
public void addMappedInput(java.lang.String name, double dist, boolean calcQE)
calcQE
is true
.name
- the name of the input datum.dist
- the precalculated distance between input datum and weight vectorcalcQE
- determines if the quantization error should be recalculated.public void removeMappedInput(java.lang.String label)
removeMappedInput
in class InputContainer
public void calculateQuantizationError()
public void clearLabels()
public void clearMappedInput()
public Label[] getLabels(java.lang.String type)
public Label[] getLabels()
public Label[] getKaskiGateLabels()
public Label[] getKaskiLabels()
public Label[] getGateWeights()
public Label[] getBestContextWeights()
public Label[] getContextGateLabels()
public Layer getLayer()
public java.lang.String getMapIdString()
public int getMapLevel()
public GrowingSOM getMappedSOM()
null
otherwise.null
otherwise.public void setMappedSOM(GrowingSOM mappedSOM)
mappedSOM
- a map to be assigned to this unit.public int getMapXSize()
public int getMapYSize()
public int getMapZSize()
public double[] getWeightVector()
public void setWeightVector(double[] vector) throws SOMToolboxException
vector
- the weight vector.SOMToolboxException
public int getXPos()
public int getYPos()
public int getZPos()
public void initWeightVectorBySample(InputDatum datum)
datum
.datum
- the input datum.public void restoreLabels(int nrUnitLabels, java.lang.String[] unitLabels, double[] unitLabelsQe, double[] unitLabelsWgt)
nrUnitLabels
must be equal to the dimensionalities of the arrays specified in the other arguments.
If this is not the case, no labels will be restored.nrUnitLabels
- the number of labels.unitLabels
- an array of strings containing the labels' names.unitLabelsQe
- an array of double values containing the qunatization errors for the single labels.unitLabelsWgt
- an array of double values containing the actual values for the single labels.public void restoreContextGateLabels(int nrContextGate, java.lang.String[] contextGateUnitLabels)
public void restoreKaskiLabels(int nrKaski, java.lang.String[] kaskiUnitLabels, double[] kaskiUnitLabelsWgt)
public void restoreKaskiGateLabels(int nrKaskiGate, java.lang.String[] kaskiGateUnitabels)
public void restoreGateWeightLabels(int nrgateweights, java.lang.String[] gateWeightUnitLabels)
public void restoreBestContextWeightLabels(int nrbestcontext, java.lang.String[] bestContextWeightUnitLabels)
public void restoreMappings(int nrVecsMapped, java.lang.String[] mappedVecs, double[] mappedVecsDist)
nrVecsMapped
must be equal to the dimensionalities of the arrays specified in the other
arguments. If this is not the case, no input data will be restored. The quantization error will also be
recalculated.nrVecsMapped
- the number of input data.mappedVecs
- an array of strings containing the data identifiers.mappedVecsDist
- an array of double values containing the distances between the weight vector and the
respective input data.public void setLabels(Label[] labels)
labels
- array of labels to be assigned to this unit.public void setKaskiGateLabels(Label[] kaski_gate_labels)
public void setContextGateLabels(Label[] context_gate_labels)
public void updatePosition(int x, int y, int z)
x
- the horizontal position on the map.y
- the vertical position on the map.z
- the height position on the map.public void updatePosition(int x, int y)
public void addBatchSomNeighbour(InputDatum d)
public void clearBatchSomList()
public void getWeightVectorFromBatchSomNeighbourhood()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String printCoordinates()
public java.lang.String printCoordinatesSpaceSeparated()
public java.lang.String printUnitDetails(InputData inputData, TemplateVector tv)
public double[] getFeatureWeights()
public void setFeatureWeights(double[] featureWeights)
public void copyFeatureWeights(double[] featureWeights)
public int getDim()
public java.lang.String getUnitLabels()
void setPositions(int x, int y, int z)
public boolean isTopLeftUnit()