Package org.apache.mahout.math.random

Examples of org.apache.mahout.math.random.MultiNormal.sample()


public abstract class AbstractSearchTest {
  protected static Matrix randomData() {
    Matrix data = new DenseMatrix(1000, 20);
    MultiNormal gen = new MultiNormal(20);
    for (MatrixSlice slice : data) {
      slice.vector().assign(gen.sample());
    }
    return data;
  }

  public abstract Iterable<MatrixSlice> testData();
View Full Code Here


    s.addAllMatrixSlicesAsWeightedVectors(testData());

    MultiNormal noise = new MultiNormal(0.01, new DenseVector(20));
    for (MatrixSlice slice : queries) {
      Vector query = slice.vector();
      final Vector epsilon = noise.sample();
      List<WeightedThing<Vector>> r0 = s.search(query, 2);
      query = query.plus(epsilon);
      List<WeightedThing<Vector>> r = s.search(query, 2);
      r = s.search(query, 2);
      assertEquals("Distance has to be small", epsilon.norm(2), r.get(0).getWeight(), 1e-5);
View Full Code Here

  @Test
  public void testOrdering() {
    Matrix queries = new DenseMatrix(100, 20);
    MultiNormal gen = new MultiNormal(20);
    for (int i = 0; i < 100; i++) {
      queries.viewRow(i).assign(gen.sample());
    }

    Searcher s = getSearch(20);
    // s.setSearchSize(200);
    s.addAllMatrixSlices(testData());
View Full Code Here

    List<WeightedVector> data = Lists.newArrayListWithCapacity(K1 + 5000);
    int row = 0;

    MultiNormal g = new MultiNormal(radius, new ConstantVector(0, 10));
    for (int i = 0; i < K1; i++) {
      data.add(new WeightedVector(g.sample(), 1, row++));
    }

    for (int i = 0; i < 5; i++) {
      Vector m = new DenseVector(10);
      m.set(i, i == 0 ? 6 : 6);
View Full Code Here

    for (int i = 0; i < 5; i++) {
      Vector m = new DenseVector(10);
      m.set(i, i == 0 ? 6 : 6);
      MultiNormal gx = new MultiNormal(radius, m);
      for (int j = 0; j < 1000; j++) {
        data.add(new WeightedVector(gx.sample(), 1, row++));
      }
    }
    return data;
  }
}
View Full Code Here

  public static void main(String[] args) {
    Sampler<Vector> rand = new MultiNormal(new ConstantVector(1, VECTOR_DIMENSION));
    List<WeightedVector> referenceVectors = Lists.newArrayListWithExpectedSize(REFERENCE_SIZE);
    for (int i = 0; i < REFERENCE_SIZE; ++i) {
      referenceVectors.add(new WeightedVector(rand.sample(), 1, i));
    }
    System.out.printf("Generated reference matrix.\n");

    List<WeightedVector> queryVectors = Lists.newArrayListWithExpectedSize(QUERY_SIZE);
    for (int i = 0; i < QUERY_SIZE; ++i) {
View Full Code Here

    }
    System.out.printf("Generated reference matrix.\n");

    List<WeightedVector> queryVectors = Lists.newArrayListWithExpectedSize(QUERY_SIZE);
    for (int i = 0; i < QUERY_SIZE; ++i) {
      queryVectors.add(new WeightedVector(rand.sample(), 1, i));
    }
    System.out.printf("Generated query matrix.\n");

    for (int threads : new int[]{1, 2, 3, 4, 5, 6, 10, 20, 50}) {
      for (int block : new int[]{1, 10, 50}) {
View Full Code Here

    List<WeightedVector> data = Lists.newArrayListWithCapacity(K1 + 5000);
    int row = 0;

    MultiNormal g = new MultiNormal(radius, new ConstantVector(0, 10));
    for (int i = 0; i < K1; i++) {
      data.add(new WeightedVector(g.sample(), 1, row++));
    }

    for (int i = 0; i < 5; i++) {
      Vector m = new DenseVector(10);
      m.set(i, 6); // This was originally i == 0 ? 6 : 6 which can't be right
View Full Code Here

    for (int i = 0; i < 5; i++) {
      Vector m = new DenseVector(10);
      m.set(i, 6); // This was originally i == 0 ? 6 : 6 which can't be right
      MultiNormal gx = new MultiNormal(radius, m);
      for (int j = 0; j < 1000; j++) {
        data.add(new WeightedVector(gx.sample(), 1, row++));
      }
    }
    return data;
  }
}
View Full Code Here

public class CentroidTest extends AbstractVectorTest<Centroid> {
  @Test
  public void testUpdate() {
    MultiNormal f = new MultiNormal(20);

    Vector a = f.sample();
    Vector b = f.sample();
    Vector c = f.sample();

    DenseVector x = new DenseVector(a);
    Centroid x1 = new Centroid(1, x);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.