Package org.apache.mahout.clustering.dirichlet.models

Examples of org.apache.mahout.clustering.dirichlet.models.AsymmetricSampledNormalModel


  }

  @Test
  public void testASNClusterClassification() {
    List<Model<VectorWritable>> models = new ArrayList<Model<VectorWritable>>();
    models.add(new AsymmetricSampledNormalModel(0, new DenseVector(2).assign(1), new DenseVector(2).assign(1)));
    models.add(new AsymmetricSampledNormalModel(1, new DenseVector(2), new DenseVector(2).assign(1)));
    models.add(new AsymmetricSampledNormalModel(2, new DenseVector(2).assign(-1), new DenseVector(2).assign(1)));
    AbstractVectorClassifier classifier = new VectorModelClassifier(models);
    Vector pdf = classifier.classify(new DenseVector(2));
    assertEquals("[0,0]", "[0.212, 0.576, 0.212]", AbstractCluster.formatVector(pdf, null));
    pdf = classifier.classify(new DenseVector(2).assign(2));
    assertEquals("[2,2]", "[0.952, 0.047, 0.000]", AbstractCluster.formatVector(pdf, null));
View Full Code Here


  @Test
  public void testAsymmetricSampledNormalModelWritableSerialization() throws Exception {
    double[] m = { 1.1, 2.2, 3.3 };
    double[] s = { 3.3, 4.4, 5.5 };
    Model<?> model = new AsymmetricSampledNormalModel(5, new DenseVector(m), new DenseVector(s));
    DataOutputBuffer out = new DataOutputBuffer();
    model.write(out);
    Model<?> model2 = new AsymmetricSampledNormalModel();
    DataInputBuffer in = new DataInputBuffer();
    in.reset(out.getData(), out.getLength());
    model2.readFields(in);
    assertEquals("models", model.toString(), model2.toString());
  }
View Full Code Here

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

    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

    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

  @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
        .fromJson(jsonString, AsymmetricSampledNormalModel.class);
    assertEquals("models", model.toString(), model2.toString());
  }
View Full Code Here

    builder
        .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.model.toString(), mh2.model.toString());
View Full Code Here

    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

    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.getStdDev().times(3));
        if (isSignificant(mm))
          plotEllipse(g2, mm.getMean(), dv);
      }
    }
  }
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
        .fromJson(jsonString, AsymmetricSampledNormalModel.class);
    assertEquals("models", model.toString(), model2.toString());
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.dirichlet.models.AsymmetricSampledNormalModel

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.