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

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


  }.getType();

  public void testDirichletNormalModel() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    Printable model = new NormalModel(m, 0.75);
    String format = model.asFormatString(null);
    assertEquals("format", "nm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    NormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here


  }

  public void testDirichletNormalModelClusterAsFormatString() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    NormalModel model = new NormalModel(m, 0.75);
    Printable cluster = new DirichletCluster<VectorWritable>(model, 35.0);
    String format = cluster.asFormatString(null);
    assertEquals("format", "nm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
  }
View Full Code Here

  }

  public void testDirichletNormalModelClusterAsJsonString() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    NormalModel model = new NormalModel(m, 0.75);
    Printable cluster = new DirichletCluster<VectorWritable>(model, 35.0);
    String json = cluster.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
View Full Code Here

    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

    int i = DisplayDirichlet.result.size() - 1;
    for (Model<VectorWritable>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (Model<VectorWritable> m : models) {
        NormalModel mm = (NormalModel) m;
        dv.assign(mm.getStdDev() * 3);
        if (DisplayDirichlet.isSignificant(mm)) {
          DisplayDirichlet.plotEllipse(g2, mm.getMean(), dv);
        }
      }
    }
  }
View Full Code Here

    int i = DisplayDirichlet.result.size() - 1;
    for (Model<VectorWritable>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (Model<VectorWritable> m : models) {
        NormalModel mm = (NormalModel) m;
        dv.assign(mm.getStdDev() * 3);
        if (DisplayDirichlet.isSignificant(mm)) {
          DisplayDirichlet.plotEllipse(g2, mm.getMean(), dv);
        }
      }
    }
  }
View Full Code Here

    int i = DisplayDirichlet.result.size() - 1;
    for (Model<VectorWritable>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (Model<VectorWritable> m : models) {
        NormalModel mm = (NormalModel) m;
        dv.assign(mm.getStdDev() * 3);
        if (DisplayDirichlet.isSignificant(mm)) {
          DisplayDirichlet.plotEllipse(g2, mm.getMean(), dv);
        }
      }
    }
  }
View Full Code Here

 
  // =================== New Tests of Writable Implementations ====================
 
  public void testNormalModelWritableSerialization() throws Exception {
    double[] m = {1.1, 2.2, 3.3};
    Model<?> model = new NormalModel(new DenseVector(m), 3.3);
    DataOutputBuffer out = new DataOutputBuffer();
    model.write(out);
    Model<?> model2 = new NormalModel();
    DataInputBuffer in = new DataInputBuffer();
    in.reset(out.getData(), out.getLength());
    model2.readFields(in);
    assertEquals("models", model.toString(), model2.toString());
  }
View Full Code Here

    assertEquals("models", model.toString(), model2.toString());
  }
 
  public void testClusterWritableSerialization() throws Exception {
    double[] m = {1.1, 2.2, 3.3};
    DirichletCluster<?> cluster = new DirichletCluster(new NormalModel(new DenseVector(m), 4), 10);
    DataOutputBuffer out = new DataOutputBuffer();
    cluster.write(out);
    DirichletCluster<?> cluster2 = new DirichletCluster();
    DataInputBuffer in = new DataInputBuffer();
    in.reset(out.getData(), out.getLength());
View Full Code Here

  @Test
  public void testDirichletNormalModel() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    Cluster model = new NormalModel(5, m, 0.75);
    String format = model.asFormatString(null);
    assertEquals("format", "nm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    NormalModel model2 = gson.fromJson(json, MODEL_TYPE);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

TOP

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

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.