当前位置: 首页>>代码示例>>Java>>正文


Java MaxEntTrainer类代码示例

本文整理汇总了Java中cc.mallet.classify.MaxEntTrainer的典型用法代码示例。如果您正苦于以下问题:Java MaxEntTrainer类的具体用法?Java MaxEntTrainer怎么用?Java MaxEntTrainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MaxEntTrainer类属于cc.mallet.classify包,在下文中一共展示了MaxEntTrainer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initClassifier

import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public void initClassifier(Map<String, Object> parameters) throws DataMiningException {
  String classifierName = "MaxEntL1";
  // String classifierName = "C45";
  Double gaussianPrior = null;
  if (parameters != null && parameters.containsKey("classifier")) {
    classifierName = (String) parameters.get("classifier");
  }
  if (classifierName.equals("MaxEntL1") && parameters != null && parameters.containsKey("classifier")) {
    gaussianPrior = (Double) parameters.get("gaussianPrior");
  }
  try {
    trainer = (ClassifierTrainer<?>) Class.forName("cc.mallet.classify." + classifierName + "Trainer").newInstance();
    if (classifierName.equals("MaxEntL1")) {
      if (gaussianPrior != null) {
        ((MaxEntTrainer) trainer).setGaussianPriorVariance(gaussianPrior);
      }
    }
    // ((MaxEntTrainer)trainer).setGaussianPriorVariance(1.0);
    /*
     * ((C45Trainer)trainer).setMinNumInsts(3); ((C45Trainer)trainer).setDepthLimited(true); ((C45Trainer)trainer).setMaxDepth(2);
     * ((C45Trainer)trainer).setDoPruning(true);
     */
  } catch (Exception e) {
    throw new DataMiningException("unknown classifier: " + classifierName, e);
  }
}
 
开发者ID:begab,项目名称:kpe,代码行数:27,代码来源:MalletDataHandler.java

示例2: createTrainer

import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public ClassifierTrainer<MaxEnt> createTrainer(String... args) {
  MaxEntTrainer trainer = new MaxEntTrainer();
  if (args != null) {
    if (args.length % 2 != 0) {
      throw new IllegalArgumentException("each argument must be supplied with a value:  "
          + getUsageMessage());
    }
    for (int i = 0; i < args.length; i += 2) {
      String optionName = args[i];
      String optionValue = args[i + 1];
      if (optionName.equals("--numIterations")) {
        int numIterations = Integer.parseInt(optionValue);
        if (numIterations > 0)
          trainer.setNumIterations(numIterations);
        else
          throw new IllegalArgumentException("numIterations must be positive.  "
              + getUsageMessage());
      }

      else if (optionName.equals("--gaussianPriorVariance"))
        trainer.setGaussianPriorVariance(Double.parseDouble(optionValue));
      else
        throw new IllegalArgumentException(String.format(
            "the argument %1$s is invalid.  ",
            optionName) + getUsageMessage());
    }
  }
  return trainer;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:30,代码来源:MaxEntTrainerFactory.java

示例3: testRandomTrainedOn

import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
private double testRandomTrainedOn (InstanceList training)
{
  ClassifierTrainer trainer = new MaxEntTrainer();

  Alphabet fd = dictOfSize (3);
  String[] classNames = new String[] {"class0", "class1", "class2"};

  Randoms r = new Randoms (1);
  Iterator<Instance> iter = new RandomTokenSequenceIterator (r,  new Dirichlet(fd, 2.0),
        30, 0, 10, 200, classNames);
  training.addThruPipe (iter);

  InstanceList testing = new InstanceList (training.getPipe ());
  testing.addThruPipe (new RandomTokenSequenceIterator (r,  new Dirichlet(fd, 2.0),
        30, 0, 10, 200, classNames));

  System.out.println ("Training set size = "+training.size());
  System.out.println ("Testing set size = "+testing.size());

  Classifier classifier = trainer.train (training);

  System.out.println ("Accuracy on training set:");
  System.out.println (classifier.getClass().getName()
                        + ": " + new Trial(classifier, training).getAccuracy());

  System.out.println ("Accuracy on testing set:");
  double testAcc = new Trial (classifier, testing).getAccuracy();
  System.out.println (classifier.getClass().getName()
                        + ": " + testAcc);

  return testAcc;
}
 
开发者ID:mimno,项目名称:Mallet,代码行数:33,代码来源:TestPagedInstanceList.java

示例4: testTrainSplit

import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public static Trial testTrainSplit(InstanceList instances) {

        InstanceList[] instanceLists = instances.split(new Randoms(),
                new double[] { 0.9, 0.1, 0.0 });

        // LOG.debug("{} training instance, {} testing instances",
        // instanceLists[0].size(), instanceLists[1].size());

        @SuppressWarnings("rawtypes")
        ClassifierTrainer trainer = new MaxEntTrainer();
        Classifier classifier = trainer.train(instanceLists[TRAINING]);
        return new Trial(classifier, instanceLists[TESTING]);
    }
 
开发者ID:BlueBrain,项目名称:bluima,代码行数:14,代码来源:ReferencesClassifierTrainer.java

示例5: run

import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public void run () {
		Alphabet alphabet = dictOfSize(20);
		
		// TRAIN
		Clustering training = sampleClustering(alphabet);		
		Pipe clusterPipe = new OverlappingFeaturePipe();
		System.err.println("Training with " + training);
		InstanceList trainList = new InstanceList(clusterPipe);
		trainList.addThruPipe(new ClusterSampleIterator(training, random, 0.5, 100));
		System.err.println("Created " + trainList.size() + " instances.");
		Classifier me = new MaxEntTrainer().train(trainList);
		ClassifyingNeighborEvaluator eval =
			new ClassifyingNeighborEvaluator(me, "YES");
																					 
		Trial trial = new Trial(me, trainList);
		System.err.println(new ConfusionMatrix(trial));
		InfoGain ig = new InfoGain(trainList);
		ig.print();

// 		Clusterer clusterer = new GreedyAgglomerative(training.getInstances().getPipe(),
// 																									eval, 0.5);
		Clusterer clusterer = new GreedyAgglomerativeByDensity(training.getInstances().getPipe(),
																													 eval, 0.5, false,
																													 new java.util.Random(1));

		// TEST
		Clustering testing = sampleClustering(alphabet);		
		InstanceList testList = testing.getInstances();
		Clustering predictedClusters = clusterer.cluster(testList);			

		// EVALUATE
		System.err.println("\n\nEvaluating System: " + clusterer);
		ClusteringEvaluators evaluators = new ClusteringEvaluators(new ClusteringEvaluator[]{
				new BCubedEvaluator(),
				new PairF1Evaluator(),
				new MUCEvaluator(),
				new AccuracyEvaluator()});

		System.err.println("truth:" + testing);
		System.err.println("pred: " + predictedClusters);				
		System.err.println(evaluators.evaluate(testing, predictedClusters)); 					
	}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:43,代码来源:FirstOrderClusterExample.java


注:本文中的cc.mallet.classify.MaxEntTrainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。