Java Vector vectorKLDivergence(double v1[], double v2[])

Here you can find the source of vectorKLDivergence(double v1[], double v2[])

Description

vector KL Divergence

License

Open Source License

Declaration

public static double vectorKLDivergence(double v1[], double v2[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    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]);
        }//from w w w.j av  a2  s.c om
        return kl;
    }
}

Related

  1. vectorCos(int[] d1, int[] d2)
  2. vectorDiff(final double[] vecOne, final double[] vecTwo)
  3. vectorDir(int vert, int horiz)
  4. vectorDistance(double[] vec1, double[] vec2, double power)
  5. vectorIndexToUpperTriangularIndices(int numberOfRows, int index)
  6. vectorL2Norm(double[] v)
  7. vectorLog10(double v1[])
  8. vectorMagnitude4D(float[][][][] vec4D)
  9. vectorSimilarity(float[] wordVector1, float[] wordVector2)