Java Cosine Similarity cosineSimilarity(float[] vectorA, float[] vectorB)

Here you can find the source of cosineSimilarity(float[] vectorA, float[] vectorB)

Description

cosine Similarity

License

Open Source License

Declaration

public static double cosineSimilarity(float[] vectorA, float[] vectorB) 

Method Source Code

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

public class Main {
    public static double cosineSimilarity(float[] vectorA, float[] vectorB) {
        double dotProduct = 0.0;
        double normA = 0.0;
        double normB = 0.0;
        for (int i = 0; i < vectorA.length; i++) {
            dotProduct += vectorA[i] * vectorB[i];
            normA += Math.pow(vectorA[i], 2);
            normB += Math.pow(vectorB[i], 2);
        }//www .j  a  v  a2  s  . c o  m
        return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
    }
}

Related

  1. cosineLawGetDegree(double a, double b, double c)
  2. cosineSim(double[] a, double[] b)
  3. cosineSimilarity(double[] vector1, double[] vector2)
  4. cosineSimilarity(double[] x, double[] y)
  5. cosineSimilarity(float[] f1, float[] f2)
  6. cosineSimilarity(String[] tkn0, String[] tkn1)