Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.DenseVector


  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


  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

   */
  private void generateSamples(int num, double mx, double my, double sd) {
    System.out.println("Generating " + num + " samples m=[" + mx + ", " + my
        + "] sd=" + sd);
    for (int i = 0; i < num; i++)
      sampleData.add(new DenseVector(new double[] {
          UncommonDistributions.rNorm(mx, sd),
          UncommonDistributions.rNorm(my, sd) }));
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public void testNormalModelSerialization() {
    double[] m = { 1.1, 2.2 };
    Model model = new NormalModel(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, NormalModel.class);
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.model.toString(), mh2.model.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.model.toString(), mh2.model.toString());
  }
View Full Code Here

  private void generateSamples(int num, double mx, double my, double sdx,
      double sdy) {
    System.out.println("Generating " + num + " samples m=[" + mx + ", " + my
        + "] sd=[" + sdx + ", " + sdy + "]");
    for (int i = 0; i < num; i++)
      sampleData.add(new DenseVector(new double[] {
          UncommonDistributions.rNorm(mx, sdx),
          UncommonDistributions.rNorm(my, sdy) }));
  }
View Full Code Here

    rmr("testdata");
    raw = new Vector[100];
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        int ix = i * 10 + j;
        Vector v = new DenseVector(3);
        v.setQuick(0, i);
        v.setQuick(1, j);
        if (i == j) {
          v.setQuick(2, 9);
        } else if (i + j == 9) {
          v.setQuick(2, 4.5);
        }
        raw[ix] = v;
      }
    }
  }
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.