com.github.TKnudsen.ComplexDataObject.model.statistics.JensenShannonDivergence 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.model.statistics;
import com.github.TKnudsen.ComplexDataObject.model.distanceMeasure.Double.probabilities.KullbackLeiblerDivergenceDistance;
/**
*
* Title: JensenShannonDivergence
*
*
*
* Description: calculates the Jensen Shannon Divergence - a measure to assess
* the difference between to probability distibutions.
*
*
*
* Copyright: Copyright (c) 2018
*
*
* @author Juergen Bernard
* @version 1.01
*/
public class JensenShannonDivergence {
/**
*
* @param a
* @param b
* @return
*/
public static double jensenShannonDivergence(double[] a, double[] b) {
double[] med = new double[a.length];
for (int i = 0; i < med.length; i++)
med[i] = (a[i] + b[i]) / 2;
KullbackLeiblerDivergenceDistance kld = new KullbackLeiblerDivergenceDistance(true);
return (kld.dist(a, med) + kld.dist(b, med)) * 0.5;
}
}