Example usage for org.apache.commons.math.random UnitSphereRandomVectorGenerator UnitSphereRandomVectorGenerator

List of usage examples for org.apache.commons.math.random UnitSphereRandomVectorGenerator UnitSphereRandomVectorGenerator

Introduction

In this page you can find the example usage for org.apache.commons.math.random UnitSphereRandomVectorGenerator UnitSphereRandomVectorGenerator.

Prototype

public UnitSphereRandomVectorGenerator(final int dimension, final RandomGenerator rand) 

Source Link

Usage

From source file:datafu.pig.hash.lsh.cosine.HyperplaneLSH.java

/**
 * Locality sensitive hash that maps vectors onto 0,1 in such a way that colliding
 * vectors are "near" one another according to cosine similarity with high probability.  
 * /* w w w  .j a v  a  2 s. com*/
 * <p>
 * Generally, multiple LSH are combined via repetition to increase the range of the hash function to the full set of longs.
 * This repetition is accomplished by wrapping instances of the LSH in a LSHFamily, which does the combination.
 * 
 * The size of the hash family corresponds to the number of independent hashes you want to apply to the data.
 * In a k-near neighbors style of searching, this corresponds to the number of neighbors you want to find
 * (i.e. the number of vectors within a distance according to cosine similarity).
 */
public HyperplaneLSH(int dim, RandomGenerator rg) {
    super(dim, rg);

    UnitSphereRandomVectorGenerator generator = new UnitSphereRandomVectorGenerator(dim, rg);
    //compute our vector representing a hyperplane of dimension dim by taking a random vector
    //located on the unit sphere
    double[] normalVector = generator.nextVector();
    r = new ArrayRealVector(normalVector);
}