com.github.TKnudsen.ComplexDataObject.model.distanceMeasure.featureVector.EuclideanDistanceMeasure 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.
package com.github.TKnudsen.ComplexDataObject.model.distanceMeasure.featureVector;
import java.util.List;
import com.github.TKnudsen.ComplexDataObject.data.features.numericalData.NumericalFeature;
import com.github.TKnudsen.ComplexDataObject.data.features.numericalData.NumericalFeatureVector;
/**
*
* Title: EuclideanDistanceMeasure
*
*
*
* Description: Euclidean's Distance Measure for NumericalFeatureVectors
*
*
*
* Copyright: Copyright (c) 2012-2016
*
*
* @author Juergen Bernard
*/
public class EuclideanDistanceMeasure implements INumericalFeatureVectorDistanceMeasure {
/**
*
*/
private static final long serialVersionUID = -2728016822703430883L;
@Override
public double getDistance(NumericalFeatureVector o1, NumericalFeatureVector o2) {
List featuresO1 = o1.getVectorRepresentation();
List featuresO2 = o2.getVectorRepresentation();
double d = 0;
for (int i = 0; i < Math.min(featuresO1.size(), featuresO2.size()); i++)
d += Math.pow(featuresO1.get(i).doubleValue() - featuresO2.get(i).doubleValue(), 2);
d = Math.sqrt(d);
return d;
}
@Override
public String getName() {
return "EuclideanDistanceMeasure";
}
@Override
public String getDescription() {
return "Euclidean's Distance Measure for NumericalFeatureVectors";
}
}