Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.mahout.clustering.dirichlet;
 
 import  com.google.gson.Gson;
 import  com.google.gson.GsonBuilder;
 import  com.google.gson.reflect.TypeToken;
 import  org.apache.hadoop.io.Writable;
 
 
 public class DirichletCluster<O> implements Writable {
 
   @SuppressWarnings("unchecked")
   @Override
   public void readFields(DataInput inthrows IOException {
     this. = in.readDouble();
     this. = (Model<O>) readModel(in);
   }
 
   @Override
   public void write(DataOutput outthrows IOException {
     out.writeDouble();
     writeModel(out);
   }
 
   private Model<O> model// the model for this iteration
 
   private double totalCount// total count of observations for the model
 
   public DirichletCluster(Model<O> modeldouble totalCount) {
     super();
     this. = model;
     this. = totalCount;
   }
 
   public DirichletCluster() {
     super();
   }
 
   public Model<O> getModel() {
     return ;
   }
 
   public void setModel(Model<O> model) {
     this. = model;
     this. += model.count();
   }
 
   public double getTotalCount() {
     return ;
   }
 
   private static final Type typeOfModel = new TypeToken<DirichletCluster<Vector>>() {
   }.getType();
 
   public String asFormatString() {
     GsonBuilder builder = new GsonBuilder();
     builder.registerTypeAdapter(Vector.classnew JsonVectorAdapter());
     builder.registerTypeAdapter(Model.classnew JsonModelAdapter());
     Gson gson = builder.create();
     return gson.toJson(this);
   }

  
Reads a typed Model instance from the input stream
 
   public static Model<?> readModel(DataInput inthrows IOException {
     String modelClassName = in.readUTF();
     Model<?> model;
     try {
       model = Class.forName(modelClassName).asSubclass(Model.class)
           .newInstance();
     } catch (ClassNotFoundException e) {
       throw new IllegalStateException(e);
     } catch (IllegalAccessException e) {
       throw new IllegalStateException(e);
     } catch (InstantiationException e) {
       throw new IllegalStateException(e);
     }
     model.readFields(in);
    return model;
  }

  
Writes a typed Model instance to the output stream
  public static void writeModel(DataOutput outModel<?> modelthrows IOException {
    out.writeUTF(model.getClass().getName());
    model.write(out);
  }
  public static DirichletCluster<VectorfromFormatString(String formatString) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.classnew JsonVectorAdapter());
    builder.registerTypeAdapter(Model.classnew JsonModelAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formatString);
  }
New to GrepCode? Check out our FAQ X