Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.DenseVector


  public void testMeasure() {

    DistanceMeasure distanceMeasure = distanceMeasureFactory();

    Vector[] vectors = {
        new DenseVector(new double[]{1, 1, 1, 1, 1, 1}),
        new DenseVector(new double[]{2, 2, 2, 2, 2, 2}),
        new DenseVector(new double[]{6, 6, 6, 6, 6, 6}),
        new DenseVector(new double[]{-1,-1,-1,-1,-1,-1})
    };

    compare(distanceMeasure, vectors);

    vectors = new Vector[4];
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  public void testSampledNormalModelSerialization() {
    double[] m = {1.1, 2.2};
    Model<?> model = new SampledNormalModel(new DenseVector(m), 3.3);
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    String jsonString = gson.toJson(model);
    Model<?> model2 = gson.fromJson(jsonString, SampledNormalModel.class);
View Full Code Here

  @SuppressWarnings("unchecked")
  public void testAsymmetricSampledNormalModelSerialization() {
    double[] m = {1.1, 2.2};
    double[] s = {3.3, 4.4};
    Model<?> model = new AsymmetricSampledNormalModel(new DenseVector(m),
        new DenseVector(s));
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    String jsonString = gson.toJson(model);
    Model<?> model2 = gson
View Full Code Here

    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder
        .registerTypeAdapter(ModelHolder.class, new JsonModelHolderAdapter());
    Gson gson = builder.create();
    double[] d = {1.1, 2.2};
    ModelHolder mh = new ModelHolder(new NormalModel(new DenseVector(d), 3.3));
    String format = gson.toJson(mh);
    System.out.println(format);
    ModelHolder mh2 = gson.fromJson(format, ModelHolder.class);
    assertEquals("mh", mh.getModel().toString(), mh2.getModel().toString());
  }
View Full Code Here

        .registerTypeAdapter(ModelHolder.class, new JsonModelHolderAdapter());
    Gson gson = builder.create();
    double[] d = {1.1, 2.2};
    double[] s = {3.3, 4.4};
    ModelHolder mh = new ModelHolder(new AsymmetricSampledNormalModel(
        new DenseVector(d), new DenseVector(s)));
    String format = gson.toJson(mh);
    System.out.println(format);
    ModelHolder mh2 = gson.fromJson(format, ModelHolder.class);
    assertEquals("mh", mh.getModel().toString(), mh2.getModel().toString());
  }
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="
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="
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

  @Override
  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.set(0, mm.getStdDev().get(0) * 3);
        dv.set(1, mm.getStdDev().get(1) * 3);
        if (isSignificant(mm))
          plotEllipse(g2, mm.getMean(), dv);
      }
    }
  }
View Full Code Here

    @Override
    public Vector next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      Vector result = type == VectorType.SPARSE ? new SparseVector(numItems) : new DenseVector(numItems);
      result.assign(new UnaryFunction(){
        @Override
        public double apply(double arg1) {
          return random.nextDouble();
        }
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.