Here you can find the source of matrixKLDivergence(double m1[][], double m2[][])
public static double matrixKLDivergence(double m1[][], double m2[][])
//package com.java2s; //License from project: Open Source License public class Main { public static double matrixKLDivergence(double m1[][], double m2[][]) { if (m1.length != m2.length) return Double.MAX_VALUE; double avgKL = 0.0; for (int i = 0; i < m1.length; i++) { if (m1[i].length != m2[i].length) return Double.MAX_VALUE; avgKL += vectorKLDivergence(m1[i], m2[i]); }/*from w w w .ja va 2s . c o m*/ return avgKL / m1.length; } public static double vectorKLDivergence(double v1[], double v2[]) { if (v1.length != v2.length) return Double.MAX_VALUE; double kl = 0.0; for (int i = 0; i < v1.length; i++) { kl += v1[i] * Math.log(v1[i] / v2[i]); } return kl; } }