Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.Vector


  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) {
        AsymmetricSampledNormalModel mm = (AsymmetricSampledNormalModel) m;
        dv.assign(mm.sd.times(3));
        if (isSignificant(mm))
          plotEllipse(g2, mm.mean, dv);
      }
    }
  }
View Full Code Here


      ParameteredGeneralizations.configureParameters(this, jobConf);
    }
    try {
      FileSystem fs = FileSystem.get(jobConf);
      if (weightsFile.get() != null) {
        Vector weights = (Vector) vectorClass.get().newInstance();
        if (!fs.exists(weightsFile.get())) {
          throw new FileNotFoundException(weightsFile.get().toString());
        }
        DataInputStream in = fs.open(weightsFile.get());
        try {
          weights.readFields(in);
        } finally {
          in.close();
        }
        this.weights = weights;
      }
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

        double a = feature.get();

        double b = vector1.get(feature.index());

        Vector weights = getWeights();
        double weight = weights == null ? 1.0 : weights.get(feature.index());

        ab += a * b * weight;
        a2 += a * a * weight;
        b2 += b * b * weight;
      }
    }


    for (Vector.Element feature : vector1) {
      if (!featuresSeen.add(feature.index())) {

        double a = vector0.get(feature.index());

        double b = feature.get();

        Vector weights = getWeights();
        double weight = weights == null ? 1.0 : weights.get(feature.index());

        ab += a * b * weight;
        a2 += a * a * weight;
        b2 += b * b * weight;
      }
View Full Code Here

  protected List<Cluster> clusters;

  @Override
  public void map(WritableComparable<?> key, Text values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    Vector point = AbstractVector.decodeVector(values.toString());
    Cluster.emitPointToNearestCluster(point, clusters, values, output);
  }
View Full Code Here

public class KMeansClusterMapper extends KMeansMapper {
  @Override
  public void map(WritableComparable<?> key, Text values,
      OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
    Vector point = AbstractVector.decodeVector(values.toString());
    Cluster.outputPointWithClusterInfo(values.toString(), point, clusters,
        values, output);
  }
View Full Code Here

    String center = formattedString.substring(beginIndex);
    char firstChar = id.charAt(0);
    boolean startsWithV = firstChar == 'V';
     if (firstChar == 'C' || startsWithV) {
      int clusterId = Integer.parseInt(formattedString.substring(1, beginIndex - 2));   
      Vector clusterCenter = AbstractVector.decodeVector(center);
      Cluster cluster = new Cluster(clusterCenter, clusterId);
      cluster.converged = startsWithV;
      return cluster;
    }
    return null;
View Full Code Here

   * Return if the cluster is converged by comparing its center and centroid.
   *
   * @return if the cluster is converged
   */
  public boolean computeConvergence() {
    Vector centroid = computeCentroid();
    converged = measure.distance(centroid, center) <= convergenceDelta;
    return converged;
  }
View Full Code Here

    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

      System.out.println("test k= " + k);

      List<SoftCluster> clusterList = new ArrayList<SoftCluster>();
      // pick k initial cluster centers at random
      for (int i = 0; i < k + 1; i++) {
        Vector vec = tweakValue(points.get(i));
        SoftCluster cluster = new SoftCluster(vec);
        // add the center so the centroid will be correct upon output
        cluster.addPoint(cluster.getCenter(), 1);

        clusterList.add(cluster);
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.