public abstract class InputVectorDistanceMatrix
extends java.lang.Object
n*n
, where n
is the number of input vectors. The matrix is
symmetric, i.e. the upper-right and lower-left halves contain the same values. The diagonal contains the distances of
one element to itself, and is thus always 0.Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<java.lang.String> |
inputLabels |
protected DistanceMetric |
metric |
protected int |
numVectors |
Constructor and Description |
---|
InputVectorDistanceMatrix() |
Modifier and Type | Method and Description |
---|---|
int |
columns() |
boolean |
equals(java.lang.Object obj) |
protected int |
flatArraySize() |
abstract double |
getDistance(int x,
int y)
Return the distance between input vectors x and y.
|
double[] |
getDistances(int x)
Return the distances to all vectors from input x.
|
double[] |
getDistancesFlat()
Gets all the distances in a single flat array avoiding duplicates from the pairwise distances, thus of the size
of
numVectors * (numVectors - * 1) / 2 .This is a default implementation always constructing the array on the fly using the getDistance(int, int) method. |
cern.colt.matrix.impl.DenseDoubleMatrix1D |
getDistancesFlatAsMatrix() |
java.util.ArrayList<java.lang.String> |
getInputLabels() |
DistanceMetric |
getMetric() |
int[] |
getNNearest(int x,
int num)
Return the n nearest vectors of input x.
|
static InputVectorDistanceMatrix |
initFromFile(java.lang.String fileName)
Factory method that reads and creates an
InputVectorDistanceMatrix from the given file. |
int |
numVectors() |
int |
rows() |
java.lang.String |
toString() |
protected int numVectors
protected DistanceMetric metric
protected java.util.ArrayList<java.lang.String> inputLabels
public DistanceMetric getMetric()
public java.util.ArrayList<java.lang.String> getInputLabels()
public abstract double getDistance(int x, int y)
public int[] getNNearest(int x, int num)
public double[] getDistances(int x)
getDistance(int, int)
,
sub-classes might provide an optimised implementation.public int numVectors()
public double[] getDistancesFlat()
numVectors * (numVectors - * 1) / 2
.getDistance(int, int)
method. Specific subclasses might provide better performing implementations, as
e.g. LeightWeightMemoryInputVectorDistanceMatrix
.public cern.colt.matrix.impl.DenseDoubleMatrix1D getDistancesFlatAsMatrix()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public static InputVectorDistanceMatrix initFromFile(java.lang.String fileName) throws java.io.IOException, SOMToolboxException
InputVectorDistanceMatrix
from the given file. Depending on the
filename, returns either a RandomAccessFileInputVectorDistanceMatrix
(if the filename ends with '.bin')
or a LeightWeightMemoryInputVectorDistanceMatrix
(all other cases).java.io.IOException
SOMToolboxException
protected int flatArraySize()
public int rows()
public int columns()