Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.Vector


  @Override
  public double distance(Vector p1, Vector p2) {
    double result = 0;

    Vector res = p2.minus(p1);
    if (weights == null) {
      for (int i = 0; i < res.cardinality(); i++) {
        result += Math.abs(res.get(i));
      }
    }
    else {
      for (int i = 0; i < res.cardinality(); i++) {
        result += Math.abs(res.get(i) * weights.get(i)); // todo this is where the weights goes, right?
      }
    }

    return result;
  }
View Full Code Here


  public void paint(Graphics g) {
    super.plotSampleData(g);
    Graphics2D g2 = (Graphics2D) g;

    Vector dv = new DenseVector(2);
    int i = result.size() - 1;
    for (Model<Vector>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(colors.length - 1, i--)]);
      for (Model<Vector> m : models) {
        NormalModel mm = (NormalModel) m;
        dv.assign(mm.sd * 3);
        if (isSignificant(mm))
          plotEllipse(g2, mm.mean, dv);
      }
    }
  }
View Full Code Here

      // split
      // prob and vector
      double pointProb = Double.parseDouble(pointInfo.substring(0, index));

      String encodedVector = pointInfo.substring(index + 1);
      Vector v = AbstractVector.decodeVector(encodedVector);
      if (mapperSepIndex != -1) // first time thru combiner
      {
        cluster.addPoint(v, Math.pow(pointProb, SoftCluster.getM()));
      } else {
        cluster.addPoints(v, pointProb);
View Full Code Here

  // Override the paint() method
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    plotSampleData(g);
    Vector v = new DenseVector(2);
    Vector dv = new DenseVector(2);
    g2.setColor(Color.RED);
    for (Vector param : sampleParams) {
      v.set(0, param.get(0));
      v.set(1, param.get(1));
      dv.set(0, param.get(2) * 3);
      dv.set(1, param.get(3) * 3);
      plotEllipse(g2, v, dv);
    }
  }
View Full Code Here

    double sx = (double) res / ds;
    g2.setTransform(AffineTransform.getScaleInstance(sx, sx));

    // plot the axes
    g2.setColor(Color.BLACK);
    Vector dv = new DenseVector(2).assign(size / 2);
    plotRectangle(g2, new DenseVector(2).assign(2), dv);
    plotRectangle(g2, new DenseVector(2).assign(-2), dv);

    // plot the sample data
    g2.setColor(Color.DARK_GRAY);
    dv.assign(0.03);
    for (Vector v : sampleData)
      plotRectangle(g2, v, dv);
  }
View Full Code Here

   * @param dv a Vector of rectangle sizes
   */
  void plotRectangle(Graphics2D g2, Vector v, Vector dv) {
    int h = size / 2;
    double[] flip = { 1, -1 };
    Vector v2 = v.copy().assign(new DenseVector(flip), new TimesFunction());
    v2 = v2.minus(dv.divide(2));
    double x = v2.get(0) + h;
    double y = v2.get(1) + h;
    g2.draw(new Rectangle2D.Double(x * ds, y * ds, dv.get(0) * ds, dv.get(1)
        * ds));
  }
View Full Code Here

   * @param dv a Vector of rectangle sizes
   */
  void plotEllipse(Graphics2D g2, Vector v, Vector dv) {
    int h = size / 2;
    double[] flip = { 1, -1 };
    Vector v2 = v.copy().assign(new DenseVector(flip), new TimesFunction());
    v2 = v2.minus(dv.divide(2));
    double x = v2.get(0) + h;
    double y = v2.get(1) + h;
    g2
        .draw(new Ellipse2D.Double(x * ds, y * ds, dv.get(0) * ds, dv.get(1)
            * ds));
  }
View Full Code Here

      int index = mapperSepIndex == -1 ? combinerSepIndex : mapperSepIndex;// needed
      // to
      // split
      // prob and vector
      double partialSumPtProb = new Double(value.substring(0, index));
      Vector total = AbstractVector.decodeVector(value.substring(index + 1));
      if (mapperSepIndex != -1) // escaped from combiner
      {
        cluster.addPoint(total, Math.pow(partialSumPtProb, SoftCluster.getM()));
      } else {
        cluster.addPoints(total, partialSumPtProb);
View Full Code Here

    int beginIndex = formattedString.indexOf('[');
    String id = formattedString.substring(0, beginIndex);
    String centroid = formattedString.substring(beginIndex);
    if (id.charAt(0) == 'C') {
      int canopyId = Integer.parseInt(formattedString.substring(1, beginIndex - 2));
      Vector canopyCentroid = AbstractVector.decodeVector(centroid);
      return new Canopy(canopyCentroid, canopyId);
    }
    return null;
  }
View Full Code Here

   * Compute the centroid by averaging the pointTotals
   *
   * @return a point which is the new centroid
   */
  public Vector computeCentroid() {
    Vector result = new SparseVector(pointTotal.cardinality());
    for (int i = 0; i < pointTotal.cardinality(); i++)
      result.set(i, pointTotal.get(i) / numPoints);
    return result;
  }
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.