Example usage for org.apache.mahout.math.function Functions random

List of usage examples for org.apache.mahout.math.function Functions random

Introduction

In this page you can find the example usage for org.apache.mahout.math.function Functions random.

Prototype

public static DoubleFunction random() 

Source Link

Document

Constructs a function that returns a new uniform random number in the open unit interval (0.0,1.0) (excluding 0.0 and 1.0).

Usage

From source file:edu.indiana.d2i.htrc.vecproj.RandomProjection.java

License:Apache License

public RandomProjection(int originalDim /* d */, int reducedDim /* k */) {
    this.originalDim = originalDim;
    this.reducedDim = reducedDim;

    // generate random matrix, use a O(kd) algorithm [Achlioptas, 2000]
    random = Functions.random();
    DoubleFunctionWrapper randomWrapper = new DoubleFunctionWrapper();
    basis = new DenseMatrix(reducedDim, originalDim);
    for (int i = 0; i < reducedDim; i++) {
        DenseVector projection = new DenseVector(originalDim);
        projection.assign(randomWrapper);
        basis.assignRow(i, projection);// w w  w .j a  v a2 s .  com
    }
}

From source file:edu.indiana.d2i.htrc.vecproj.TestRandomProjection.java

License:Apache License

@Test
public void testProject() {
    long t0 = System.nanoTime();
    random = Functions.random();
    for (int i = 0; i < 100; i++) { // test 100 times
        DenseVector vector = new DenseVector(originalDim);
        vector.assign(random);/*from  w w w. j ava2  s .  c  o  m*/
        Vector projected = projector.project(vector);
        Assert.assertEquals(reducedDim, projected.size());
    }
    long t1 = System.nanoTime();
    System.out.println("elapsed " + ((double) (t1 - t0)) / 1e9);
}