Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

private Double pearsonMatch(List<String> w1, List<String> w2) {

Double numerator = 0.0, sqr1 = 0.0, sqr2 = 0.0, a = 0.0, b = 0.0;


for(String w : words) {
int ai = Collections.frequency(w1, w);
int bi = Collections.frequency(w2, w);
numerator += (ai - a) * (bi - b);
sqr1 += (ai - a) * (ai - a);
sqr2 += (bi - b) * (bi - b);
}
return numerator / (Math.sqrt(sqr1) * Math.sqrt(sqr2));
}

You might also like