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


Java Optimizable.ByGradientValue方法代码示例

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


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

示例1: someUnsupportedTrain

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public boolean someUnsupportedTrain (ACRF acrf,
                      InstanceList trainingList,
                      InstanceList validationList,
                      InstanceList testSet,
                      ACRFEvaluator eval,
                      int numIter)
{

  Optimizable.ByGradientValue macrf = createOptimizable (acrf, trainingList);
  train (acrf, trainingList, validationList, testSet, eval, 5, macrf);
  ACRF.Template[] tmpls = acrf.getTemplates ();
  for (int ti = 0; ti < tmpls.length; ti++)
    tmpls[ti].addSomeUnsupportedWeights (trainingList);
  logger.info ("Some unsupporetd weights initialized.  Training...");
  return train (acrf, trainingList, validationList, testSet, eval, numIter, macrf);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:DefaultAcrfTrainer.java

示例2: train

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public boolean train (ACRF acrf, InstanceList trainingList, InstanceList validationList, InstanceList testSet,
                      ACRFEvaluator eval, int numIter, Optimizable.ByGradientValue macrf)
{
  if (wrongWrongType == NO_WRONG_WRONG) {
    return super.train (acrf, trainingList, validationList, testSet, eval, numIter, macrf);
  } else {
    Maxable bipwMaxable = (Maxable) macrf;
    // add wrong wrongs after 5 iterations
    logger.info ("BiconditionalPiecewiseACRFTrainer: Initial training");
    super.train (acrf, trainingList, validationList, testSet, eval, wrongWrongIter, macrf);
    FileUtils.writeGzippedObject (new File (outputPrefix, "initial-acrf.ser.gz"), acrf);
    logger.info ("BiconditionalPiecewiseACRFTrainer: Adding wrong-wrongs");
    bipwMaxable.addWrongWrong (trainingList);
    logger.info ("BiconditionalPiecewiseACRFTrainer: Adding wrong-wrongs");
    boolean converged = super.train (acrf, trainingList, validationList, testSet, eval, numIter, macrf);
    reportTrainingLikelihood (acrf, trainingList);
    return converged;
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:PwplACRFTrainer.java

示例3: testGetSetParameters

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testGetSetParameters() {
	int inputVocabSize = 100;
	int numStates = 5;
	Alphabet inputAlphabet = new Alphabet();
	for (int i = 0; i < inputVocabSize; i++)
		inputAlphabet.lookupIndex("feature" + i);
	Alphabet outputAlphabet = new Alphabet();
	CRF crf = new CRF(inputAlphabet, outputAlphabet);
	String[] stateNames = new String[numStates];
	for (int i = 0; i < numStates; i++)
		stateNames[i] = "state" + i;
	crf.addFullyConnectedStates(stateNames);
	CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
	Optimizable.ByGradientValue mcrf = crft
			.getOptimizableCRF(new InstanceList(null));
	TestOptimizable.testGetSetParameters(mcrf);
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:18,代码来源:TestCRF.java

示例4: testSpaceSerializable

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testSpaceSerializable () throws IOException, ClassNotFoundException
{
  Pipe p = makeSpacePredictionPipe ();
  InstanceList training = new InstanceList (p);
  training.addThruPipe (new ArrayIterator (data));

  MEMM memm = new MEMM (p, null);
  memm.addFullyConnectedStatesForLabels ();
  memm.addStartState();
  memm.setWeightsDimensionAsIn(training);
 MEMMTrainer memmt = new MEMMTrainer (memm);
  memmt.train (training, 10);

  MEMM memm2 = (MEMM) TestSerializable.cloneViaSerialization (memm);

  Optimizable.ByGradientValue mcrf1 = memmt.getOptimizableMEMM(training);
  double val1 = mcrf1.getValue ();
  Optimizable.ByGradientValue mcrf2 = memmt.getOptimizableMEMM(training);
  double val2 = mcrf2.getValue ();

  assertEquals (val1, val2, 1e-5);
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:23,代码来源:TestMEMM.java

示例5:

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
/**
 * Tests that getValue and getValueGradient are consistent.
 * Tests for consistency at <tt>params = 0</tt> and at
 *  <tt> params = -0.0001 * grad(f)</tt>
 *  @see #testValueAndGradientCurrentParameters testValueAndGradientCurrentParameters
 * @throws IllegalStateException If the test fails.
 */
public static boolean	testValueAndGradient (Optimizable.ByGradientValue maxable)
{
	double[] parameters = new double [maxable.getNumParameters()];
	MatrixOps.setAll (parameters, 0.0);
	maxable.setParameters (parameters);
	testValueAndGradientCurrentParameters (maxable);
	MatrixOps.setAll (parameters, 0.0);
	double[] delta = new double[maxable.getNumParameters()];
	maxable.getValueGradient (delta);
	logger.info ("Gradient two-Norm = "+MatrixOps.twoNorm(delta));
	logger.info ("  max parameter change = "+(MatrixOps.infinityNorm(delta) * -0.001));
	MatrixOps.timesEquals (delta, -0.0001);
	MatrixOps.plusEquals (parameters, delta);
	maxable.setParameters (parameters);
	testValueAndGradientCurrentParameters (maxable);
	return true;
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:25,代码来源:TestOptimizable.java

示例6: train

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
boolean train (ACRF acrf,
InstanceList training,
InstanceList validation,
InstanceList testing,
ACRFEvaluator eval,
int numIter,
Optimizable.ByGradientValue macrf);
 
开发者ID:mimno,项目名称:GRMM,代码行数:8,代码来源:ACRFTrainer.java

示例7: CRFOptimizableByGradientValues

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
/**
 * @param crf CRF whose parameters we wish to estimate.
 * @param opts Optimizable.ByGradientValue objective functions. 
 * 
 * Parameters are estimated by maximizing the sum of the individual
 * objective functions.
 */
public CRFOptimizableByGradientValues (CRF crf, Optimizable.ByGradientValue[] opts) {
	this.crf = crf;
	this.optimizables = opts;
	this.cachedGradient = new double[crf.parameters.getNumFactors()];
	this.cachedValueWeightsStamp = -1;
	this.cachedGradientWeightsStamp = -1;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:15,代码来源:CRFOptimizableByGradientValues.java

示例8: ConjugateGradient

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public ConjugateGradient (Optimizable.ByGradientValue function, double initialStepSize)
{
  this.initialStepSize = initialStepSize;
  this.optimizable = function;
  this.lineMaximizer = new BackTrackLineSearch (function);
  //Alternative:
  //this.lineMaximizer = new GradientBracketLineOptimizer (function);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:ConjugateGradient.java

示例9: testRandomMaximizable

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testRandomMaximizable ()
{
	MaxEntTrainer trainer = new MaxEntTrainer();
	Alphabet fd = dictOfSize (6);
	String[] classNames = new String[] {"class0", "class1"};
	InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20);
	Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist);
	TestOptimizable.testValueAndGradient (maxable);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:10,代码来源:TestMaxEntTrainer.java

示例10: getOptimizable

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public Optimizable.ByGradientValue getOptimizable (InstanceList trainingList) {
  if (ge == null) {
    ge = new MaxEntOptimizableByGE(trainingList,constraints,classifier);
    ge.setTemperature(temperature);
    ge.setGaussianPriorVariance(gaussianPriorVariance);
  }
  return ge;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:MaxEntGETrainer.java

示例11:

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
/**
 * Tests that getValue and getValueGradient are consistent 
 *   at a random parameter setting.
 *  @see #testValueAndGradientCurrentParameters testValueAndGradientCurrentParameters
 * @throws IllegalStateException If the test fails.
 */
public static boolean testValueAndGradientRandomParameters 
(Optimizable.ByGradientValue maxable, Random r)
{
	double[] params = new double [maxable.getNumParameters()];
	for (int i = 0; i < params.length; i++) {
		params[i] = r.nextDouble ();
		if (r.nextBoolean ()) 
			params [i] = -params[i];
	}
	maxable.setParameters (params);
	testValueAndGradientCurrentParameters (maxable);
	return true;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:TestOptimizable.java

示例12: train

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public boolean train (ACRF acrf,
                      InstanceList trainingList,
                      InstanceList validationList,
                      InstanceList testSet,
                      ACRFEvaluator eval,
                      int numIter)
{
  Optimizable.ByGradientValue macrf = createOptimizable (acrf, trainingList);
  return train (acrf, trainingList, validationList, testSet,
          eval, numIter, macrf);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:DefaultAcrfTrainer.java

示例13: testSetGetParameters

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testSetGetParameters ()
{
		MaxEntTrainer trainer = new MaxEntTrainer();
	Alphabet fd = dictOfSize (6);
	String[] classNames = new String[] {"class0", "class1", "class2"};
	InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20);
	Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist);
	TestOptimizable.testGetSetParameters (maxable);
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:10,代码来源:TestMaxEntTrainer.java

示例14: testSpaceMaximizable

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
public void testSpaceMaximizable ()
  {
    Pipe p = makeSpacePredictionPipe ();
    InstanceList training = new InstanceList (p);
//    String[] data = { TestMEMM.data[0], }; // TestMEMM.data[1], TestMEMM.data[2], TestMEMM.data[3], };
//    String[] data = { "ab" };
    training.addThruPipe (new ArrayIterator (data));

//    CRF4 memm = new CRF4 (p, null);
    MEMM memm = new MEMM (p, null);
    memm.addFullyConnectedStatesForLabels ();
    memm.addStartState();
    memm.setWeightsDimensionAsIn(training);
    
	  MEMMTrainer memmt = new MEMMTrainer (memm);
//    memm.gatherTrainingSets (training); // ANNOYING: Need to set up per-instance training sets
    memmt.train (training, 1);  // Set weights dimension, gathers training sets, etc.

//    memm.print();
//    memm.printGradient = true;
//    memm.printInstanceLists();

//    memm.setGaussianPriorVariance (Double.POSITIVE_INFINITY);
    Optimizable.ByGradientValue mcrf = memmt.getOptimizableMEMM(training);
    TestOptimizable.setNumComponents (150);
    TestOptimizable.testValueAndGradient (mcrf);
  }
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:28,代码来源:TestMEMM.java

示例15: getLikelihood

import cc.mallet.optimize.Optimizable; //导入方法依赖的package包/类
double getLikelihood (MEMMTrainer memmt, InstanceList data) {
	Optimizable.ByGradientValue mcrf = memmt.getOptimizableMEMM(data);
	// Do this elaborate thing so that crf.cachedValueStale is forced true
	double[] params = new double [mcrf.getNumParameters()];
	mcrf.getParameters (params);
	mcrf.setParameters (params);
	return mcrf.getValue ();
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:9,代码来源:TestMEMM.java


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