public abstract class InputVectorDistanceMatrix extends 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 ArrayList<String> |
inputLabels |
protected DistanceMetric |
metric |
protected int |
numVectors |
Constructor and Description |
---|
InputVectorDistanceMatrix() |
Modifier and Type | Method and Description |
---|---|
int |
columns() |
boolean |
equals(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() |
ArrayList<String> |
getInputLabels() |
DistanceMetric |
getMetric() |
int[] |
getNNearest(int x,
int num)
Return the n nearest vectors of input x.
|
static InputVectorDistanceMatrix |
initFromFile(String fileName)
Factory method that reads and creates an
InputVectorDistanceMatrix from the given file. |
int |
numVectors() |
int |
rows() |
String |
toString() |
protected int numVectors
protected DistanceMetric metric
public DistanceMetric getMetric()
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 static InputVectorDistanceMatrix initFromFile(String fileName) throws 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).IOException
SOMToolboxException
protected int flatArraySize()
public int rows()
public int columns()