Examples of JsonVectorAdapter


Examples of org.apache.mahout.matrix.JsonVectorAdapter

  }

  @SuppressWarnings("unchecked")
  public void testModelHolderSerialization2() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder
        .registerTypeAdapter(ModelHolder.class, new JsonModelHolderAdapter());
    Gson gson = builder.create();
    double[] d = {1.1, 2.2};
    double[] s = {3.3, 4.4};
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  /** Format the canopy for output */
  public static String formatCanopy(MeanShiftCanopy canopy) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = gBuilder.create();
    return gson.toJson(canopy, MeanShiftCanopy.class);
  }
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

   */
  public static MeanShiftCanopy decodeCanopy(String formattedString) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = gBuilder.create();
    return gson.fromJson(formattedString, MeanShiftCanopy.class);
  }
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  @Override
  public JsonElement serialize(DirichletState<?> src, Type typeOfSrc,
                               JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    builder.registerTypeAdapter(ModelDistribution.class,
        new JsonModelDistributionAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  @Override
  public DirichletState<?> deserialize(JsonElement json, Type typeOfT,
                                       JsonDeserializationContext context) throws JsonParseException {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    builder.registerTypeAdapter(ModelDistribution.class,
        new JsonModelDistributionAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  @Override
  public JsonElement serialize(Model<?> src, Type typeOfSrc,
                               JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  @Override
  public Model<?> deserialize(JsonElement json, Type typeOfT,
                              JsonDeserializationContext context) throws JsonParseException {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get("class").getAsString();
    String model = obj.get("model").getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

  private static final Type typeOfModel = new TypeToken<DirichletCluster<Vector>>() {
  }.getType();

  public String asFormatString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, typeOfModel);
  }
View Full Code Here

Examples of org.apache.mahout.matrix.JsonVectorAdapter

    model.write(out);
  }

  public static DirichletCluster<Vector> fromFormatString(String formatString) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formatString, typeOfModel);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.