Java Code Examples for org.nd4j.linalg.api.ndarray.INDArray#distance2()

The following examples show how to use org.nd4j.linalg.api.ndarray.INDArray#distance2() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestModels.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 6 votes vote down vote up
private static int compareWithOtherClasses(Set<Map.Entry<File, List<INDArray>>> entries,
                                           Map.Entry<File, List<INDArray>> entry) {
    int misMatch = 0;
    File folder = entry.getKey();
    List<INDArray> currentEmbeddingsList = entry.getValue();
    for (INDArray currentEmbedding : currentEmbeddingsList) {
        for (Map.Entry<File, List<INDArray>> entryOther : entries) {
            if (entryOther.getKey().getName().equals(folder.getName())) {
                continue;
            }
            List<INDArray> otherEmbeddingsList = entryOther.getValue();
            for (INDArray otherEmbedding : otherEmbeddingsList) {
                if (currentEmbedding.distance2(otherEmbedding) < THRESHOLD) {
                    misMatch++;
                }
            }
        }
    }
    return misMatch;
}
 
Example 2
Source File: TestModels.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 5 votes vote down vote up
private static int compareInsideOneClassSequentially(Map.Entry<File, List<INDArray>> entry) {
    int wrongPredictionsInsideOneClassOrdered = 0;
    List<INDArray> value = entry.getValue();
    INDArray prevEmbeddings = value.get(0);
    for (int i = 1; i < value.size(); i++) {
        if (prevEmbeddings.distance2(value.get(i)) >= THRESHOLD) {
            wrongPredictionsInsideOneClassOrdered++;
        }
        prevEmbeddings = value.get(i);
    }
    return wrongPredictionsInsideOneClassOrdered;
}
 
Example 3
Source File: FaceRecognition.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 4 votes vote down vote up
private double distance(INDArray a, INDArray b) {
    return a.distance2(b);
}
 
Example 4
Source File: EvaluationUtils.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
private static double calculateEuclideanImageDistance(final INDArray inst1, final INDArray inst2) {
	return inst1.distance2(inst2) / inst1.length();
}
 
Example 5
Source File: Transforms.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param d1
 * @param d2
 * @return
 */
public static double euclideanDistance(@NonNull INDArray d1, @NonNull INDArray d2) {
    return d1.distance2(d2);
}
 
Example 6
Source File: Transforms.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * @param d1
 * @param d2
 * @return
 */
public static double euclideanDistance(@NonNull INDArray d1, @NonNull INDArray d2) {
    return d1.distance2(d2);
}