Package org.apache.mahout.math.random

Examples of org.apache.mahout.math.random.MultiNormal


  public void testNearMatch() {
    searcher.clear();
    List<MatrixSlice> queries = Lists.newArrayList(Iterables.limit(dataPoints, 100));
    searcher.addAllMatrixSlicesAsWeightedVectors(dataPoints);

    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>> r = searcher.search(query, 2);
      query = query.plus(epsilon);
      assertEquals("Distance has to be small", epsilon.norm(2), r.get(0).getWeight(), 1.0e-1);
      assertEquals("Answer must be substantially the same as query", epsilon.norm(2),
          r.get(0).getValue().minus(query).norm(2), 1.0e-1);
View Full Code Here


  @Test
  public void testOrdering() {
    searcher.clear();
    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.addAllMatrixSlices(dataPoints);

    for (MatrixSlice query : queries) {
      List<WeightedThing<Vector>> r = searcher.search(query.vector(), 200);
View Full Code Here

  private static List<? extends WeightedVector> cubishTestData(double radius) {
    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
      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

      for (int j = 0; j < numDimensions; ++j) {
        v.set(j, 1.0 / pow2J * (i & pow2J));
        pow2J >>= 1;
      }
      mean.add(new Centroid(i, v, 1));
      rowSamplers.add(new MultiNormal(distributionRadius, v));
    }

    // Sample the requested number of data points.
    List<Centroid> data = Lists.newArrayListWithCapacity(numDatapoints);
    for (int i = 0; i < numDatapoints; ++i) {
View Full Code Here

  public void testSetData() throws IOException {
    File f = File.createTempFile("matrix", ".m", getTestTempDir());
    f.deleteOnExit();

    Matrix m0 = new DenseMatrix(100000, 30);
    MultiNormal gen = new MultiNormal(30);
    for (MatrixSlice row : m0) {
      row.vector().assign(gen.sample());
    }
    FileBasedMatrix.writeMatrix(f, m0);

    FileBasedMatrix m = new FileBasedMatrix(100000, 30);
    m.setData(f, true);
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.random.MultiNormal

Copyright © 2018 www.massapicom. 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.