Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.DenseVector$Element


  public Model<Vector>[] sampleFromPrior(int howMany) {
    Model<Vector>[] result = new AsymmetricSampledNormalModel[howMany];
    for (int i = 0; i < howMany; i++) {
      double[] m = {UncommonDistributions.rNorm(0, 1),
          UncommonDistributions.rNorm(0, 1)};
      DenseVector mean = new DenseVector(m);
      double[] s = {UncommonDistributions.rNorm(1, 1),
          UncommonDistributions.rNorm(1, 1)};
      DenseVector sd = new DenseVector(s);
      result[i] = new AsymmetricSampledNormalModel(mean, sd);
    }
    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.getNumClusters());
    double max = 0;
    for (int k = 0; k < state.getNumClusters(); 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 Model<Vector>[] sampleFromPrior(int howMany) {
    Model<Vector>[] result = new SampledNormalModel[howMany];
    for (int i = 0; i < howMany; i++) {
      double[] m = {UncommonDistributions.rNorm(0, 1),
          UncommonDistributions.rNorm(0, 1)};
      DenseVector mean = new DenseVector(m);
      result[i] = new SampledNormalModel(mean, 1);
    }
    return result;
  }
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.size();
    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 void setOffset(double offset) {
    this.offset = offset;
  }

  public Vector totalCounts() {
    Vector result = new DenseVector(numClusters);
    for (int i = 0; i < numClusters; i++) {
      result.set(i, clusters.get(i).getTotalCount());
    }
    return result;
  }
View Full Code Here

  @Override
  public Model<Vector>[] sampleFromPrior(int howMany) {
    Model<Vector>[] result = new NormalModel[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 NormalModel(mean, 1);
    }
    return result;
  }
View Full Code Here

      tokens[attr] = token;
    }

    int nbattrs = Dataset.countAttributes(attrs);

    DenseVector vector = new DenseVector(nbattrs);

    int aId = 0;
    int label = -1;
    for (int attr = 0; attr < attrs.length; attr++) {
      if (attrs[attr].isIgnored())
        continue;

      String token = tokens[attr];

      if (attrs[attr].isNumerical()) {
        vector.set(aId++, Double.parseDouble(token));
      } else { // CATEGORICAL or LABEL
        // update values
        if (values[attr] == null)
          values[attr] = new ArrayList<String>();
        if (!values[attr].contains(token))
          values[attr].add(token);

        if (attrs[attr].isCategorical()) {
          vector.set(aId++, values[attr].indexOf(token));
        } else { // LABEL
          label = values[attr].indexOf(token);
        }
      }
    }
View Full Code Here

  @Override
  public Model<Vector>[] sampleFromPrior(int howMany) {
    Model<Vector>[] result = new NormalModel[howMany];
    for (int i = 0; i < howMany; i++) {
      result[i] = new NormalModel(new DenseVector(2), 1);
    }
    return result;
  }
View Full Code Here

    /**
     * @see org.andromda.metafacades.uml.EventFacade#getTransition()
     */
    protected java.lang.Object handleGetTransition()
    {
        Element owner = this.metaObject.getOwner();
        if (owner instanceof Transition)
        {
            return owner;
        }
        return null;
View Full Code Here

TOP

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

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.