Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.Vector


    rmr("testdata");
    raw = new Vector[100];
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        int ix = i * 10 + j;
        Vector v = new DenseVector(3);
        v.setQuick(0, i);
        v.setQuick(1, j);
        if (i == j) {
          v.setQuick(2, 9);
        } else if (i + j == 9) {
          v.setQuick(2, 4.5);
        }
        raw[ix] = v;
      }
    }
  }
View Full Code Here


  private static List<Vector> getPoints(double[][] raw) {
    List<Vector> points = new ArrayList<Vector>();
    int i = 0;
    for (double[] fr : raw) {
      Vector vec = new SparseVector(String.valueOf(i++), fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

    for (int canopyIx = 0; canopyIx < canopies.size(); canopyIx++) {
      Canopy refCanopy = reference.get(canopyIx);
      Canopy testCanopy = canopies.get(canopyIx);
      assertEquals("canopy points " + canopyIx, refCanopy.getNumPoints(),
          testCanopy.getNumPoints());
      Vector refCentroid = refCanopy.computeCentroid();
      Vector testCentroid = testCanopy.computeCentroid();
      for (int pointIx = 0; pointIx < refCentroid.size(); pointIx++) {
        assertEquals("canopy centroid " + canopyIx + '[' + pointIx + ']',
            refCentroid.get(pointIx), testCentroid.get(pointIx));
      }
    }
  }
View Full Code Here

     * the list all points that are within distance threshold T2. Repeat until
     * the list is empty.
     */
    while (!points.isEmpty()) {
      Iterator<Vector> ptIter = points.iterator();
      Vector p1 = ptIter.next();
      ptIter.remove();
      Canopy canopy = new VisibleCanopy(p1);
      canopies.add(canopy);
      while (ptIter.hasNext()) {
        Vector p2 = ptIter.next();
        double dist = measure.distance(p1, p2);
        // Put all points that are within distance threshold T1 into the canopy
        if (dist < t1) {
          canopy.addPoint(p2);
        }
View Full Code Here

      double[][] expectedCentroids = {{1.5, 1.5}, {4.0, 4.0},
          {4.666666666666667, 4.6666666666666667}};
      assertEquals("canopy points " + canopyIx, expectedNumPoints[canopyIx],
          testCanopy.getNumPoints());
      double[] refCentroid = expectedCentroids[canopyIx];
      Vector testCentroid = testCanopy.computeCentroid();
      for (int pointIx = 0; pointIx < refCentroid.length; pointIx++) {
        assertEquals("canopy centroid " + canopyIx + '[' + pointIx + ']',
            refCentroid[pointIx], testCentroid.get(pointIx));
      }
    }
  }
View Full Code Here

      double[][] expectedCentroids = {{1.8, 1.8}, {4.2, 4.2},
          {4.666666666666667, 4.666666666666667}};
      assertEquals("canopy points " + canopyIx, expectedNumPoints[canopyIx],
          testCanopy.getNumPoints());
      double[] refCentroid = expectedCentroids[canopyIx];
      Vector testCentroid = testCanopy.computeCentroid();
      for (int pointIx = 0; pointIx < refCentroid.length; pointIx++) {
        assertEquals("canopy centroid " + canopyIx + '[' + pointIx + ']',
            refCentroid[pointIx], testCentroid.get(pointIx));
      }
    }
  }
View Full Code Here

          UncommonDistributions.rNorm(my, sdy)});
    }
  }

  private void addSample(double[] values) {
    Vector v = new SparseVector(2);
    for (int j = 0; j < values.length; j++) {
      v.setQuick(j, values[j]);
    }
    sampleData.add(v);
  }
View Full Code Here

    }
  }

  public void testRmultinom1() {
    double[] b = {0.4, 0.6};
    Vector v = new DenseVector(b);
    Vector t = v.like();
    for (int i = 1; i <= 100; i++) {
      Vector multinom = UncommonDistributions.rMultinom(100, v);
      t = t.plus(multinom);
    }
    System.out.println("sum(rMultinom(" + 100 + ", [0.4, 0.6]))/100="
        + t.divide(100).asFormatString());
View Full Code Here

  }

  public void testRmultinom2() {
    double[] b = {0.1, 0.2, 0.7};
    Vector v = new DenseVector(b);
    Vector t = v.like();
    for (int i = 1; i <= 100; i++) {
      Vector multinom = UncommonDistributions.rMultinom(100, v);
      t = t.plus(multinom);
    }
    System.out.println("sum(rMultinom(" + 100 + ", [ 0.1, 0.2, 0.7 ]))/100="
        + t.divide(100).asFormatString());
View Full Code Here

  }

  public void testRmultinom() {
    double[] b = {0.1, 0.2, 0.8};
    Vector v = new DenseVector(b);
    for (int i = 1; i <= 100; i++) {
      System.out.println("rMultinom(" + 100 + ", [0.1, 0.2, 0.8])="
          + UncommonDistributions.rMultinom(100, v).asFormatString());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.matrix.Vector

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.