Package org.apache.mahout.math.random

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


import org.junit.Test;

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

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


  }

  @Test
  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

   * @param dimension   The dimension of the vectors to return.
   * @param radius      The size of the clusters we sample from.
   * @param alpha       Controls the growth of the number of clusters.  The number of clusters will be about alpha * log(samples)
   */
  public LumpyData(int dimension, double radius, double alpha) {
    this.centers = new MultiNormal(dimension);
    this.radius = radius;
    cluster = new ChineseRestaurant(alpha);
  }
View Full Code Here

  @Override
  public Vector sample() {
    int id = cluster.sample();
    if (id >= centroids.size()) {
      // need to invent a new cluster
      centroids.add(new MultiNormal(radius, centers.sample()));
    }
    return centroids.get(id).sample();
  }
View Full Code Here

  private UpdatableSearcher searcher;
  private Matrix dataPoints;

  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;
  }
View Full Code Here

  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

  public void testSetData() throws IOException {
    File f = File.createTempFile("matrix", ".m");
    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

  }

  @Test
  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

  private UpdatableSearcher searcher;
  private Matrix dataPoints;

  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;
  }
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.