All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.data.distanceMatrix.DistanceMatrices Maven / Gradle / Ivy

Go to download

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.List;
import java.util.function.ToDoubleBiFunction;

public class DistanceMatrices {

	/**
	 * pairwise distances between elements calculated with a distance measure
	 * represented by a biFunction. Assumes that the pairwise distances are not
	 * symmetric.
	 * 
	 * @param              The element type
	 * @param elements        The elements
	 * @param distanceMeasure The distance measure
	 * @return pairwise distances represented as a matrix of doubles
	 */
	public static  double[][] distanceMatrix(List elements,
			ToDoubleBiFunction distanceMeasure) {

		return distanceMatrix(elements, distanceMeasure, false);
	}

	/**
	 * pairwise distances between elements calculated with a distance measure
	 * represented by a biFunction.
	 * 
	 * @param               The element type
	 * @param elements         The elements
	 * @param distanceMeasure  The distance measure
	 * @param symmetricMeasure determine whether apply(a,b) and apply(b,a) will
	 *                         always lead to the same result. if yes this will
	 *                         speedup the process by factor two.
	 * @return pairwise distances represented as a matrix of doubles
	 */
	public static  double[][] distanceMatrix(List elements,
			ToDoubleBiFunction distanceMeasure, boolean symmetricMeasure) {

		DistanceMatrixParallel distanceMatrix = new DistanceMatrixParallel(elements, distanceMeasure,
				symmetricMeasure, true);

		return distanceMatrix.getDistanceMatrix();
	}

	/**
	 * avoid instantiation
	 */
	private DistanceMatrices() {
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy