The following example illustrates the use of Dissimilarities for computing the Euclidean distance between the rows of a matrix:
import java.io.*; import com.imsl.stat.*; import com.imsl.math.*; public class DissimilaritiesEx1 { public static void main(String argv[]) throws Exception { double[][] x = { { 1., 1.}, { 1., 0.}, { 1., -1.}, { 1., 2.}}; Dissimilarities dist = new Dissimilarities(x); dist.compute(); double[][] distanceMatrix = dist.getDistanceMatrix(); new PrintMatrix().print(distanceMatrix); } }
0 1 2 3 0 0 1 2 1 1 0 0 1 2 2 0 0 0 3 3 0 0 0 0Link to Java source.