![JAR search and dependency download from the Maven repository](/logo.png)
src.it.unimi.di.law.vector.CosineSimilarityStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of archive4j Show documentation
Show all versions of archive4j Show documentation
Archive4J is a suite of tools to store compactly term/count information of a document collection.
package it.unimi.di.law.vector;
/*
* Copyright (C) 2008-2013 Paolo Boldi, Massimo Santini and Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see .
*
*/
//RELEASE-STATUS: DIST
/** A class that compute the similarity between pattern using cosine similarity. */
public class CosineSimilarityStrategy implements SimilarityStrategy {
static final long serialVersionUID = 2006001L;
public double similarity(Vector v0, Vector v1) {
double dot = v0.dotProduct( v1 );
return dot == 0.0 ? 0.0 : dot / ( v0.ell2Norm() * v1.ell2Norm() );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy