本文整理汇总了Java中cc.mallet.optimize.Optimizable.setParameters方法的典型用法代码示例。如果您正苦于以下问题:Java Optimizable.setParameters方法的具体用法?Java Optimizable.setParameters怎么用?Java Optimizable.setParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.optimize.Optimizable
的用法示例。
在下文中一共展示了Optimizable.setParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrint
import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testPrint() {
Pipe p = new SerialPipes(new Pipe[] {
new CharSequence2TokenSequence("."), new TokenText(),
new TestCRFTokenSequenceRemoveSpaces(),
new TokenSequence2FeatureVectorSequence(),
new PrintInputAndTarget(), });
InstanceList one = new InstanceList(p);
String[] data = new String[] { "ABCDE", };
one.addThruPipe(new ArrayIterator(data));
CRF crf = new CRF(p, null);
crf.addFullyConnectedStatesForThreeQuarterLabels(one);
CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
crf.setWeightsDimensionAsIn(one, false);
Optimizable mcrf = crft.getOptimizableCRF(one);
double[] params = new double[mcrf.getNumParameters()];
for (int i = 0; i < params.length; i++) {
params[i] = i;
}
mcrf.setParameters(params);
crf.print();
}
示例2: testGetSetParameters
import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
/**
* Tests that parameters set by setParameters can be retrieved by
* getParameters.
* @param maxable Instance of a Maximizable that should be tested.
* Its current parameters will be overwritten.
*/
public static boolean testGetSetParameters (Optimizable maxable)
{
System.out.println ("TestMaximizable testGetSetParameters");
// Set all the parameters to unique values using setParameters()
double[] parameters = new double [maxable.getNumParameters()];
maxable.getParameters (parameters);
for (int i = 0; i < parameters.length; i++)
parameters[i] = (double)i;
maxable.setParameters (parameters);
// Test to make sure those parameters are there
MatrixOps.setAll (parameters, 0.0);
maxable.getParameters (parameters);
for (int i = 0; i < parameters.length; i++)
assertTrue (parameters[i] == (double)i);
return true;
}