![JAR search and dependency download from the Maven repository](/logo.png)
com.github.TKnudsen.ComplexDataObject.data.distanceMatrix.PairwiseDistancesMatrix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
The newest version!
package com.github.TKnudsen.ComplexDataObject.data.distanceMatrix;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* Distance matrix implementation that accepts a matrix of pairwise distances
* from an external source.
*
* Assumes that the given pairwise distances are symmetric.
*
*
* *
*
* Copyright: (c) 2016-2017 Juergen Bernard, https://github.com/TKnudsen/DMandML
*
*
* @author Christian Ritter, Juergen Bernard
* @version 1.05
*/
public class PairwiseDistancesMatrix implements IDistanceMatrix {
private double[][] distanceMatrix;
private Map objectMapping;
private List extends T> elements;
public PairwiseDistancesMatrix(List extends T> elements, double[][] pairwiseDistances) {
this.distanceMatrix = pairwiseDistances;
this.elements = elements;
initializeObjectMapping();
}
private void initializeObjectMapping() {
objectMapping = new HashMap<>();
int i = 0;
for (T t : getElements()) {
objectMapping.put(t, i++);
}
}
@Override
public double getDistance(T o1, T o2) {
Integer i = objectMapping.get(o1);
Integer j = objectMapping.get(o2);
if (i == null || j == null) {
return Double.NaN;
}
return getDistanceMatrix()[i][j];
}
@Override
public boolean isSymmetric() {
return true;
}
@Override
public double applyAsDouble(T t, T u) {
return getDistance(t, u);
}
@Override
public String getName() {
return "PairwiseDistancesMatrix";
}
@Override
public String getDescription() {
return "IDistanceMatrix wrapper for pairwise distances already represented as 2D double array";
}
@Override
public double[][] getDistanceMatrix() {
return distanceMatrix;
}
@Override
public List extends T> getElements() {
return elements;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy