Java examples for java.lang:Math Vector
Perform a vector dot product between two vectors
//package com.java2s; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { /**//from ww w . ja v a2s.c om * * Perform a vector dot product between two vectors * * @param vector1 * @param vector2 * @return dotproduct */ public static double dot(Map<String, Integer> vector1, Map<String, Integer> vector2) { double dotproduct = 0.0; Set<String> vector1Vocab = vector1.keySet(); Iterator<String> iter = vector1Vocab.iterator(); Integer vector1Freq; Integer vector2Freq; String word = null; while (iter.hasNext()) { word = iter.next(); vector1Freq = vector1.get(word); if (vector2.containsKey(word)) { vector2Freq = vector2.get(word); } else { continue; } dotproduct = dotproduct + (vector1Freq * vector2Freq); } return dotproduct; } }