Here you can find the source of cosineSimilarity(float[] vectorA, float[] vectorB)
public static double cosineSimilarity(float[] vectorA, float[] vectorB)
//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)); } }