Package org.apache.mahout.math.random

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


  @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


  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);

    x1.update(new Centroid(2, new DenseVector(b)));
View Full Code Here

  public void testSmallDistances() {
    for (double fuzz : new double[]{1.0e-5, 1.0e-6, 1.0e-7, 1.0e-8, 1.0e-9, 1.0e-10}) {
      MultiNormal x = new MultiNormal(fuzz, new ConstantVector(0, 20));
      for (int i = 0; i < 10000; i++) {
        final T v1 = vectorToTest(20);
        Vector v2 = v1.plus(x.sample());
        if (1 + fuzz * fuzz > 1) {
          String msg = String.format("fuzz = %.1g, >", fuzz);
          assertTrue(msg, v1.getDistanceSquared(v2) > 0);
          assertTrue(msg, v2.getDistanceSquared(v1) > 0);
        } else {
View Full Code Here

  protected static Matrix multiNormalRandomData(int numDataPoints, int numDimensions) {
    Matrix data = new DenseMatrix(numDataPoints, numDimensions);
    MultiNormal gen = new MultiNormal(20);
    for (MatrixSlice slice : data) {
      slice.vector().assign(gen.sample());
    }
    return data;
  }

  @Parameterized.Parameters
View Full Code Here

    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

  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

    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

  public void testSmallDistances() {
    for (double fuzz : new double[]{1.0e-5, 1.0e-6, 1.0e-7, 1.0e-8, 1.0e-9, 1.0e-10}) {
      MultiNormal x = new MultiNormal(fuzz, new ConstantVector(0, 20));
      for (int i = 0; i < 10000; i++) {
        final T v1 = vectorToTest(20);
        Vector v2 = v1.plus(x.sample());
        if (1 + fuzz * fuzz > 1) {
          String msg = String.format("fuzz = %.1g, >", fuzz);
          assertTrue(msg, v1.getDistanceSquared(v2) > 0);
          assertTrue(msg, v2.getDistanceSquared(v1) > 0);
        } else {
View Full Code Here

  protected static Matrix multiNormalRandomData(int numDataPoints, int numDimensions) {
    Matrix data = new DenseMatrix(numDataPoints, numDimensions);
    MultiNormal gen = new MultiNormal(20);
    for (MatrixSlice slice : data) {
      slice.vector().assign(gen.sample());
    }
    return data;
  }

  @Parameterized.Parameters
View Full Code Here

    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

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.