Example usage for org.apache.commons.math3.linear RealVector dotProduct

List of usage examples for org.apache.commons.math3.linear RealVector dotProduct

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVector dotProduct.

Prototype

public double dotProduct(RealVector v) throws DimensionMismatchException 

Source Link

Document

Compute the dot product of this vector with v .

Usage

From source file:ru.mipt.pim.server.similarity.SuperBit.java

/**
 * Compute the signature of this vector//  w  ww.  ja  va  2  s .  c o m
 * 
 * @param vector
 * @return
 */
@Override
public boolean[] createSignature(RealVector vector) {
    boolean[] sig = new boolean[this.hyperplanes.length];
    for (int i = 0; i < this.hyperplanes.length; i++) {
        sig[i] = (vector.dotProduct(this.hyperplanes[i]) >= 0);
    }
    return sig;
}

From source file:trustframework.utils.Similarity.java

/**
 * Calculates cosine similarity between two frequencies
 * @param <T> Hash key class/*from ww  w. j a  va2  s  .c  o  m*/
 * @param freq1 frequency 1
 * @param freq2 frequency 2
 * @return cosine similarity [0,1]
 */
public static <T> double cosineSimilarity(Map<T, Integer> freq1, Map<T, Integer> freq2) {
    Set<T> terms = new HashSet<>();
    terms.addAll(freq1.keySet());
    terms.addAll(freq2.keySet());
    RealVector v1 = buildRealVector(freq1, terms);
    RealVector v2 = buildRealVector(freq2, terms);
    return (v1.dotProduct(v2)) / (v1.getNorm() * v2.getNorm());
}