Java – Compare Two Vectors (Java)


Currently I have two larger vectors of 50+ strings

I want to be able to compare these two Vectors and work out how similar they are. I think I need to use Cosine similarity?

Does anyone know of any methods that take in two Java Vectors and gives a value between 0 and 1 as to how similar they are?


Best Solution

Have a look at the similarity function in Lucene.

the above formula is motivated by the cosine-distance or dot-product between document and query vector

Here's a Previous SO question on this topic.