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


Java InstanceList.split方法代码示例

本文整理汇总了Java中cc.mallet.types.InstanceList.split方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceList.split方法的具体用法?Java InstanceList.split怎么用?Java InstanceList.split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.types.InstanceList的用法示例。


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

示例1: testTokenAccuracy

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void testTokenAccuracy() {
	Pipe p = makeSpacePredictionPipe();

	InstanceList instances = new InstanceList(p);
	instances.addThruPipe(new ArrayIterator(data));
	InstanceList[] lists = instances.split(new Random(777), new double[] {
			.5, .5 });

	CRF crf = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf.addFullyConnectedStatesForLabels();
	CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
	crft.setUseSparseWeights(true);

	crft.trainIncremental(lists[0]);

	TokenAccuracyEvaluator eval = new TokenAccuracyEvaluator(lists,
			new String[] { "Train", "Test" });
	eval.evaluateInstanceList(crft, lists[1], "Test");

	assertEquals(0.9409, eval.getAccuracy("Test"), 0.001);

}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:TestCRF.java

示例2: testTrainStochasticGradient

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void testTrainStochasticGradient() {
	Pipe p = makeSpacePredictionPipe();
	Pipe p2 = new TestCRF2String();

	InstanceList instances = new InstanceList(p);
	instances.addThruPipe(new ArrayIterator(data));
	InstanceList[] lists = instances.split(new double[] { .5, .5 });
	CRF crf = new CRF(p, p2);
	crf.addFullyConnectedStatesForLabels();
	crf.setWeightsDimensionAsIn(lists[0], false);
	CRFTrainerByStochasticGradient crft = new CRFTrainerByStochasticGradient(
			crf, 0.0001);
	System.out.println("Training Accuracy before training = "
			+ crf.averageTokenAccuracy(lists[0]));
	System.out.println("Testing  Accuracy before training = "
			+ crf.averageTokenAccuracy(lists[1]));
	System.out.println("Training...");
	// either fixed learning rate or selected on a sample
	crft.setLearningRateByLikelihood(lists[0]);
	// crft.setLearningRate(0.01);
	crft.train(lists[0], 100);
	crf.print();
	System.out.println("Training Accuracy after training = "
			+ crf.averageTokenAccuracy(lists[0]));
	System.out.println("Testing  Accuracy after training = "
			+ crf.averageTokenAccuracy(lists[1]));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:28,代码来源:TestCRF.java

示例3: subsetData

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
private InstanceList subsetData (InstanceList data, double pct)
{
  InstanceList[] lsts = data.split (r, new double[] { pct, 1 - pct });
  return lsts[0];
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:6,代码来源:ACRFExtractorTrainer.java

示例4: testAddOrderNStates

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void testAddOrderNStates() {
	Pipe p = makeSpacePredictionPipe();

	InstanceList instances = new InstanceList(p);
	instances.addThruPipe(new ArrayIterator(data));
	InstanceList[] lists = instances.split(new java.util.Random(678),
			new double[] { .5, .5 });

	// Compare 3 CRFs trained with addOrderNStates, and make sure
	// that having more features leads to a higher likelihood

	CRF crf1 = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf1.addOrderNStates(lists[0], new int[] { 1, },
			new boolean[] { false, }, "START", null, null, false);
	new CRFTrainerByLabelLikelihood(crf1).trainIncremental(lists[0]);

	CRF crf2 = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf2.addOrderNStates(lists[0], new int[] { 1, 2, }, new boolean[] {
			false, true }, "START", null, null, false);
	new CRFTrainerByLabelLikelihood(crf2).trainIncremental(lists[0]);

	CRF crf3 = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf3.addOrderNStates(lists[0], new int[] { 1, 2, }, new boolean[] {
			false, false }, "START", null, null, false);
	new CRFTrainerByLabelLikelihood(crf3).trainIncremental(lists[0]);

	// Prevent cached values
	double lik1 = getLikelihood(crf1, lists[0]);
	double lik2 = getLikelihood(crf2, lists[0]);
	double lik3 = getLikelihood(crf3, lists[0]);

	System.out.println("CRF1 likelihood " + lik1);

	assertTrue("Final zero-order likelihood <" + lik1
			+ "> greater than first-order <" + lik2 + ">", lik1 < lik2);
	assertTrue("Final defaults-only likelihood <" + lik2
			+ "> greater than full first-order <" + lik3 + ">", lik2 < lik3);

	assertEquals(-167.2234457483949, lik1, 0.0001);
	assertEquals(-165.81326484466342, lik2, 0.0001);
	assertEquals(-90.37680146432787, lik3, 0.0001);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:43,代码来源:TestCRF.java

示例5: disabledtestAddOrderNStates

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void disabledtestAddOrderNStates ()
{
   Pipe p = makeSpacePredictionPipe ();

   InstanceList instances = new InstanceList (p);
  instances.addThruPipe (new ArrayIterator(data));
  InstanceList[] lists = instances.split (new java.util.Random (678), new double[]{.5, .5});

	// Compare 3 CRFs trained with addOrderNStates, and make sure
	// that having more features leads to a higher likelihood

  MEMM crf1 = new MEMM(p.getDataAlphabet(), p.getTargetAlphabet());
  crf1.addOrderNStates (lists [0],
											 new int[] { 1, },
											 new boolean[] { false, },
											 "START",
											 null,
											 null,
											 false);
  crf1.setWeightsDimensionAsIn(lists[0]);
  MEMMTrainer memmt1 = new MEMMTrainer (crf1);
	memmt1.train(lists [0]);


  MEMM crf2 = new MEMM(p.getDataAlphabet(), p.getTargetAlphabet());
  crf2.addOrderNStates (lists [0],
												 new int[] { 1, 2, },
												 new boolean[] { false, true },
												 "START",
												 null,
												 null,
												 false);
  crf2.setWeightsDimensionAsIn(lists[0]);
  MEMMTrainer memmt2 = new MEMMTrainer (crf2);
	memmt2.train(lists [0]);


  MEMM crf3 = new MEMM(p.getDataAlphabet(), p.getTargetAlphabet());
  crf3.addOrderNStates (lists [0],
											 new int[] { 1, 2, },
											 new boolean[] { false, false },
											 "START",
											 null,
											 null,
											 false);
  crf3.setWeightsDimensionAsIn(lists[0]);
  MEMMTrainer memmt3 = new MEMMTrainer (crf3);
	memmt3.train(lists [0]);

	// Prevent cached values
	double lik1 = getLikelihood (memmt1, lists[0]);
	double lik2 = getLikelihood (memmt2, lists[0]);
	double lik3 = getLikelihood (memmt3, lists[0]);

	System.out.println("CRF1 likelihood "+lik1);

	assertTrue ("Final zero-order likelihood <"+lik1+"> greater than first-order <"+lik2+">",
							lik1 < lik2);
	assertTrue ("Final defaults-only likelihood <"+lik2+"> greater than full first-order <"+lik3+">",
							lik2 < lik3);

	assertEquals (-167.335971702, lik1, 0.0001);
	assertEquals (-166.212235389, lik2, 0.0001);
	assertEquals ( -90.386005741, lik3, 0.0001);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:66,代码来源:TestMEMM.java


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