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


Java SparseVector.setAll方法代码示例

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


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

示例1: testStateAddWeights

import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
public void testStateAddWeights() {
	Pipe p = makeSpacePredictionPipe(); // This used to be
	// MEMM.makeSpacePredictionPipe(),
	// but I don't know why -akm 12/2007
	InstanceList training = new InstanceList(p);
	training.addThruPipe(new ArrayIterator(data)); // This used to be
	// MEMM.data, but I
	// don't know why -akm
	// 12/2007

	CRF crf = new CRF(p, null);
	crf.addFullyConnectedStatesForLabels();
	CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
	crft.trainIncremental(training);

	// Check that the notstart state is used at test time
	Sequence input = (Sequence) training.get(0).getData();
	Sequence output = new MaxLatticeDefault(crf, input)
			.bestOutputSequence();

	boolean notstartFound = false;
	for (int i = 0; i < output.size(); i++) {
		if (output.get(i).toString().equals("notstart")) {
			notstartFound = true;
		}
	}
	System.err.println(output.toString());
	assertTrue(notstartFound);

	// Now add -infinite weight onto a transition, and make sure that it's
	// honored.
	CRF.State state = crf.getState("notstart");
	int widx = crf.getWeightsIndex("BadBad");
	int numFeatures = crf.getInputAlphabet().size();
	SparseVector w = new SparseVector(new double[numFeatures]);
	w.setAll(Double.NEGATIVE_INFINITY);
	crf.setWeights(widx, w);

	state.addWeight(0, "BadBad");
	state.addWeight(1, "BadBad");

	// Verify that this effectively prevents the notstart state from being
	// used
	output = new MaxLatticeDefault(crf, input).bestOutputSequence();
	notstartFound = false;
	for (int i = 0; i < output.size() - 1; i++) {
		if (output.get(i).toString().equals("notstart")) {
			notstartFound = true;
		}
	}
	assertTrue(!notstartFound);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:53,代码来源:TestCRF.java


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