Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.DenseVector


   * @param x an Observation
   * @return the Vector of probabilities
   */
  private Vector normalizedProbabilities(DirichletState<Observation> state,
      Observation x) {
    Vector pi = new DenseVector(numClusters);
    double max = 0;
    for (int k = 0; k < numClusters; k++) {
      double p = state.adjustedProbability(x, k);
      pi.set(k, p);
      if (max < p)
        max = p;
    }
    // normalize the probabilities by largest observed value
    pi.assign(new TimesFunction(), 1.0 / max);
    return pi;
  }
View Full Code Here


   * Compute the bound centroid by averaging the bound points
   *
   * @return a Vector which is the new bound centroid
   */
  public Vector computeBoundCentroid() {
    Vector result = new DenseVector(center.cardinality());
    for (Vector v : boundPoints)
      result.assign(v, new PlusFunction());
    return result.divide(boundPoints.size());
  }
View Full Code Here

    List<Double> doubles = new ArrayList<Double>();
    for (String value : numbers) {
      if (value.length() > 0)
        doubles.add(Double.valueOf(value));
    }
    Vector result = new DenseVector(doubles.size());
    int index = 0;
    for (Double d : doubles)
      result.set(index++, d);
    output.collect(null, new Text(result.asFormatString()));
  }
View Full Code Here

    List<Double> doubles = new ArrayList<Double>();
    for (String value : numbers) {
      if (value.length() > 0)
        doubles.add(Double.valueOf(value));
    }
    Vector point = new DenseVector(doubles.size());
    int index = 0;
    for (Double d : doubles)
      point.set(index++, d);
    MeanShiftCanopy canopy = new MeanShiftCanopy(point);
    output.collect(null, new Text(canopy.toString()));
  }
View Full Code Here

  @Override
  public Model<Vector>[] sampleFromPrior(int howMany) {
    Model<Vector>[] result = new NormalScModel[howMany];
    for (int i = 0; i < howMany; i++) {
      DenseVector mean = new DenseVector(60);
      for (int j = 0; j < 60; j++)
        mean.set(j, UncommonDistributions.rNorm(30, 0.5));
      result[i] = new NormalScModel(mean, 1);
    }
    return result;
  }
View Full Code Here

   * @param state the DirichletState<Vector> of this iteration
   * @param v an Vector
   * @return the Vector of probabilities
   */
  private static Vector normalizedProbabilities(DirichletState<Vector> state, Vector v) {
    Vector pi = new DenseVector(state.numClusters);
    double max = 0;
    for (int k = 0; k < state.numClusters; k++) {
      double p = state.adjustedProbability(v, k);
      pi.set(k, p);
      if (max < p)
        max = p;
    }
    // normalize the probabilities by largest observed value
    pi.assign(new TimesFunction(), 1.0 / max);
    return pi;
  }
View Full Code Here

   */
  public static Vector rBeta(int K, double shape1, double shape2) {
    //List<Double> params = new ArrayList<Double>(2);
    //params.add(shape1);
    //params.add(Math.max(0, shape2));
    Vector result = new DenseVector(K);
    for (int i = 0; i < K; i++)
      result.set(i, rBeta(shape1, shape2));
    return result;
  }
View Full Code Here

   */
  public static Vector rMultinom(int size, Vector probabilities) {
    // our probability argument may not be normalized.
    double total = probabilities.zSum();
    int cardinality = probabilities.cardinality();
    Vector result = new DenseVector(cardinality);
    for (int i = 0; total > 0 && i < cardinality; i++) {
      double p = probabilities.get(i);
      int ki = rBinomial(size, p / total);
      total -= p;
      size -= ki;
      result.set(i, ki);
    }
    return result;
  }
View Full Code Here

  public DirichletState() {
  }

  public Vector totalCounts() {
    Vector result = new DenseVector(numClusters);
    for (int i = 0; i < numClusters; i++)
      result.set(i, clusters.get(i).totalCount);
    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

TOP

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

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.