Java 类weka.core.SerializationHelper 实例源码

项目:Generator    文件:LinearRegressionWekaWrapper.java   
public void train(String datasetFilename, boolean serialise)
{
    String[] lines = Utils.readLines(datasetFilename);
    int i = 1; // skip legend
    try
    {            
        for(i = 1; i < lines.length; i++) // skip legend
        {
            dataset.add(createFeatureVector(lines[i].split(","), true));
        }
        model = (Classifier) new LinearRegression();
        ((LinearRegression)model).setRidge(1.0e-10);
        model.buildClassifier(dataset);
        if(serialise)
        {                
            SerializationHelper.write(new FileOutputStream(modelFilename), model);
        }
    }
    catch(Exception e)
    {
        System.err.println("Error in line " + i + ": " + lines[i]);
        e.printStackTrace();
    }
}
项目:repo.kmeanspp.silhouette_score    文件:CheckClusterer.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Clusterer.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:repo.kmeanspp.silhouette_score    文件:CheckAssociator.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Associator.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:repo.kmeanspp.silhouette_score    文件:CheckAttributeSelection.java   
/**
 * tests for a serialVersionUID. Fails in case the schemes don't declare a UID
 * (both must!).
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];
  boolean eval;
  boolean search;

  print("serialVersionUID...");

  eval = !SerializationHelper.needsUID(m_Evaluator.getClass());
  search = !SerializationHelper.needsUID(m_Search.getClass());

  result[0] = eval && search;

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:repo.kmeanspp.silhouette_score    文件:CheckClassifier.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Classifier.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:repo.kmeanspp.silhouette_score    文件:CheckKernel.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Kernel.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:autoweka    文件:CheckAttributeSelection.java   
/**
 * tests for a serialVersionUID. Fails in case the schemes don't declare
 * a UID (both must!).
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];
  boolean eval;
  boolean search;

  print("serialVersionUID...");

  eval   = !SerializationHelper.needsUID(m_Evaluator.getClass());
  search = !SerializationHelper.needsUID(m_Search.getClass());

  result[0] = eval && search;

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:umple    文件:CheckClusterer.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Clusterer.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:umple    文件:CheckAssociator.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Associator.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:umple    文件:CheckAttributeSelection.java   
/**
 * tests for a serialVersionUID. Fails in case the schemes don't declare a UID
 * (both must!).
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];
  boolean eval;
  boolean search;

  print("serialVersionUID...");

  eval = !SerializationHelper.needsUID(m_Evaluator.getClass());
  search = !SerializationHelper.needsUID(m_Search.getClass());

  result[0] = eval && search;

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:umple    文件:CheckClassifier.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Classifier.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:umple    文件:CheckKernel.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 * 
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Kernel.getClass());

  if (result[0]) {
    println("yes");
  } else {
    println("no");
  }

  return result;
}
项目:browserprint    文件:Predictor.java   
public static void initialise(String browserModelFilePath, String osModelFilePath, String fontsPath) throws Exception{
    browserAttributes = new ArrayList<Attribute>();
    osAttributes = new ArrayList<Attribute>();
    browserClassAttribute = new Attribute("className", browserGroupsWeCareAbout);
    osClassAttribute = new Attribute("className", osGroupsWeCareAbout);
    browserAttributes.add(browserClassAttribute);
    osAttributes.add(osClassAttribute);
    for(int i = 1; i <= 5300; ++i){
        browserAttributes.add(new Attribute(Integer.toString(i)));
        osAttributes.add(new Attribute(Integer.toString(i)));
    }

    browserClassifier = (Classifier) SerializationHelper.read(browserModelFilePath);
    osClassifier = (Classifier) SerializationHelper.read(osModelFilePath);

    BrowserOsGuessFingerprintNumericRepresentation.initialise(fontsPath);
}
项目:rainbownlp    文件:WekaClassifier.java   
@Override
public void train(List<MLExample> pTrainExamples) throws Exception {
    ConfigurationUtil.TrainingMode = true;
    setPaths();

    //This part added since the session was so slow
    List<Integer> train_example_ids = new ArrayList<Integer>();
    for(MLExample example : pTrainExamples)
    {
        train_example_ids.add(example.getExampleId());
    }
    WekaFormatConvertor.writeToFile(train_example_ids, trainFile,taskName, new String[]{"1", "2"});

    DataSource source = new DataSource(trainFile);
    Instances data = source.getDataSet();
    // setting class attribute if the data format does not provide this information
    if (data.classIndex() == -1)
        data.setClassIndex(data.numAttributes() - 1);

    if(options!=null)
        wekaAlgorithm.setOptions(options);     // set the options
    wekaAlgorithm.buildClassifier(data);   // build classifier

     // serialize model
     SerializationHelper.write(modelFile, wekaAlgorithm);
}
项目:CookEase    文件:KitchenEventDetector.java   
private void loadModel(Context context) {
    // For complex models serialization overflows the stack, so run in on a different thread with a big stack!
    Log.d(TAG, "Beginning model load...");
    final Resources resources = context.getResources();
    new Thread(null, new Runnable() {

        @Override
        public void run() {
            try {
                setModel((Classifier) SerializationHelper.read(resources.openRawResource(mModelResourceID)));
                Log.d(TAG, "Model load complete!");
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error de-serializing model!");
            }       
        }

    }, "cookeaseModelLoader", 262144L).start();
}
项目:jbossBA    文件:CheckAttributeSelection.java   
/**
 * tests for a serialVersionUID. Fails in case the schemes don't declare
 * a UID (both must!).
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];
  boolean eval;
  boolean search;

  print("serialVersionUID...");

  eval   = !SerializationHelper.needsUID(m_Evaluator.getClass());
  search = !SerializationHelper.needsUID(m_Search.getClass());

  result[0] = eval && search;

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:hungrydragon    文件:ModelGenerator.java   
public void saveModel(Classifier model, String modelpath) {
    try {
        SerializationHelper.write(modelpath, model);
    } catch (Exception ex) {
        Logger.getLogger(ModelGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:collective-classification-weka-package    文件:CollectiveClassifierPanel.java   
/**
 * Save the currently selected experiment output to a file.
 * 
 * @param name  the name of the buffer to save
 */
protected void saveModel(Object[] data) {
  int retVal = m_ModelFileChooser.showSaveDialog(CollectiveClassifierPanel.this);
  if (retVal != JFileChooser.APPROVE_OPTION)
    return;
  try {
    SerializationHelper.writeAll(m_ModelFileChooser.getSelectedFile().getAbsolutePath(), data);
    m_Log.logMessage("Model saved successfully");
  }
  catch (Exception ex) {
    String msg = "Failed to save model to '" + m_ModelFileChooser.getSelectedFile() + "': " + ex;
    m_Log.logMessage(msg);
    JOptionPane.showMessageDialog(CollectiveClassifierPanel.this, msg);
  }
}
项目:autoweka    文件:CheckClusterer.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Clusterer.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:autoweka    文件:CheckAssociator.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Associator.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:autoweka    文件:CheckClassifier.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Classifier.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:autoweka    文件:CheckKernel.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Kernel.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:autoweka    文件:SerializedClassifierTest.java   
/**
  * creates a classifier, trains and serializes it
  * 
  * @param data the data to use (J48 with nominal class, M5P with
  *             numeric class)
  * @return     the results for the data
  */
 protected double[] trainAndSerializeClassifier(Instances data) {
   Classifier   classifier;
   double[] result;
   int      i;

   try {
     // build
     if (data.classAttribute().isNominal())
classifier = new weka.classifiers.trees.J48();
     else
classifier = new weka.classifiers.trees.M5P();
     classifier.buildClassifier(data);

     // record predictions
     result = new double[data.numInstances()];
     for (i = 0; i < result.length; i++)
result[i] = classifier.classifyInstance(data.instance(i));

     // save
     SerializationHelper.write(MODEL_FILENAME, classifier);
   }
   catch (Exception e) {
     fail("Training base classifier failed: " + e);
     return null;
   }

   return result;
 }
项目:autoweka    文件:AbstractTokenizerTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean     result;

  result = !SerializationHelper.needsUID(m_Tokenizer.getClass());

  if (!result)
    fail("Doesn't declare serialVersionUID!");
}
项目:autoweka    文件:AbstractNearestNeighbourSearchTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean     result;

  result = !SerializationHelper.needsUID(m_NearestNeighbourSearch.getClass());

  if (!result)
    fail("Doesn't declare serialVersionUID!");
}
项目:umple    文件:SerializedClassifier.java   
/**
 * loads the serialized model if necessary, throws an Exception if the
 * derserialization fails.
 * 
 * @throws Exception if deserialization fails
 */
protected void initModel() throws Exception {
  if (m_Model == null) {
    m_Model = (Classifier) SerializationHelper.read(m_ModelFile
      .getAbsolutePath());
  }
}
项目:umple    文件:SerializedClassifierTest.java   
/**
 * creates a classifier, trains and serializes it
 * 
 * @param data the data to use (J48 with nominal class, M5P with numeric
 *          class)
 * @return the results for the data
 */
protected double[] trainAndSerializeClassifier(Instances data) {
  Classifier classifier;
  double[] result;
  int i;

  try {
    // build
    if (data.classAttribute().isNominal()) {
      classifier = new weka.classifiers.trees.J48();
    } else {
      classifier = new weka.classifiers.trees.M5P();
    }
    classifier.buildClassifier(data);

    // record predictions
    result = new double[data.numInstances()];
    for (i = 0; i < result.length; i++) {
      result[i] = classifier.classifyInstance(data.instance(i));
    }

    // save
    SerializationHelper.write(MODEL_FILENAME, classifier);
  } catch (Exception e) {
    fail("Training base classifier failed: " + e);
    return null;
  }

  return result;
}
项目:umple    文件:AbstractTokenizerTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean result;

  result = !SerializationHelper.needsUID(m_Tokenizer.getClass());

  if (!result) {
    fail("Doesn't declare serialVersionUID!");
  }
}
项目:umple    文件:AbstractStopwordsTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean result;

  result = !SerializationHelper.needsUID(m_Stopwords.getClass());

  if (!result) {
    fail("Doesn't declare serialVersionUID!");
  }
}
项目:umple    文件:AbstractNearestNeighbourSearchTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean result;

  result = !SerializationHelper.needsUID(m_NearestNeighbourSearch.getClass());

  if (!result) {
    fail("Doesn't declare serialVersionUID!");
  }
}
项目:ache    文件:LinkClassifierBuilder.java   
public synchronized LinkClassifier forwardlinkTraining(Set<String> relUrls, int levels,
           String className) throws Exception {

    List<Sampler<LinkNeighborhood>> instances = loadTrainingInstances(relUrls, levels);

    String wekaInputAsString = createWekaInput(instances, false);

    logger.info("Training new link classifier...");
    Classifier classifier = trainWekaClassifier(wekaInputAsString);

       String modelFile = linkClassifierFolder.resolve("link_classifier.model").toString();
       String featuresFile = linkClassifierFolder.resolve("link_classifier.features").toString();

       logger.info("Link Clasifier model file: "+modelFile);
       logger.info("Link Clasifier features file: "+featuresFile);

       SerializationHelper.write(modelFile, classifier);
       writeFeaturesFile(featuresFile, features);

       String[] classValues = null;
       if (levels == 0) {
           classValues = new String[] {"POS", "NEG"};
       } else {
           classValues = new String[] {"0", "1", "2"};
       }

       return createLinkClassifierImpl(features, classValues, classifier, className, levels);
}
项目:semdroid    文件:WekaDataClassifier.java   
public void loadClassificationModel(InputStream modelPath) throws BadConfigException {
    try {
        mClassifier = (Classifier) SerializationHelper.read(modelPath);
    } catch (Exception e) {
        throw new BadConfigException(e.getMessage());
    } finally {
        IOUtils.closeQuietly(modelPath);
    }
}
项目:snowball-stemmers-weka-package    文件:AbstractCustomSnowballStemmerTest.java   
/**
 * tests whether the scheme declares a serialVersionUID.
 */
public void testSerialVersionUID() {
  boolean result;

  result = !SerializationHelper.needsUID(m_Stemmer.getClass());

  if (!result) {
    fail("Doesn't declare serialVersionUID!");
  }
}
项目:jbossBA    文件:CheckClusterer.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Clusterer.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:jbossBA    文件:CheckAssociator.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Associator.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:jbossBA    文件:CheckClassifier.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Classifier.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:jbossBA    文件:SerializedClassifier.java   
/**
 * loads the serialized model if necessary, throws an Exception if the
 * derserialization fails. Always propagates the current debug flag.
 * 
 * @throws Exception    if deserialization fails
 */
protected void initModel() throws Exception {
  if (m_Model == null)
    m_Model = (Classifier) SerializationHelper.read(m_ModelFile.getAbsolutePath());

  m_Model.setDebug(getDebug());
}
项目:jbossBA    文件:CheckKernel.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare
 * a UID.
 *
 * @return index 0 is true if the scheme declares a UID
 */
protected boolean[] declaresSerialVersionUID() {
  boolean[] result = new boolean[2];

  print("serialVersionUID...");

  result[0] = !SerializationHelper.needsUID(m_Kernel.getClass());

  if (result[0])
    println("yes");
  else
    println("no");

  return result;
}
项目:multisearch-weka-package    文件:AbstractSearchTest.java   
/**
 * tests for a serialVersionUID. Fails in case the scheme doesn't declare a
 * UID.
 */
public void testSerialVersionUID() {
  boolean[] result = new boolean[2];

  result[0] = !SerializationHelper.needsUID(m_Search.getClass());

  if (!result[0])
    fail("Does not declare serialVersionUID!");
}
项目:gsn    文件:ActivityVirtualSensor.java   
@Override
public boolean initialize() {
    try {
        cls_act = (Classifier) SerializationHelper.read(Environment.getExternalStorageDirectory().getAbsolutePath()
            + "/Android/data/tinygsn/" + fileName);
    } catch (Exception e) {
        return false;
    }
    return true;
}