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


Java SumLatticeDefault.getGammaProbability方法代码示例

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


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

示例1: testXis

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

	InstanceList instances = new InstanceList(p);
	instances.addThruPipe(new ArrayIterator(data));

	CRF crf1 = new CRF(p, null);
	crf1.addFullyConnectedStatesForLabels();
	CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood(
			crf1);
	crft1.train(instances, 10); // Let's get some parameters

	Instance inst = instances.get(0);
	Sequence input = (Sequence) inst.getData();
	SumLatticeDefault lattice = new SumLatticeDefault(crf1, input,
			(Sequence) inst.getTarget(), null, true);
	for (int ip = 0; ip < lattice.length() - 1; ip++) {
		for (int i = 0; i < crf1.numStates(); i++) {
			Transducer.State state = crf1.getState(i);
			Transducer.TransitionIterator it = state.transitionIterator(
					input, ip);
			double gamma = lattice.getGammaProbability(ip, state);
			double xiSum = 0;
			while (it.hasNext()) {
				Transducer.State dest = it.nextState();
				double xi = lattice.getXiProbability(ip, state, dest);
				xiSum += xi;
			}
			assertEquals(gamma, xiSum, 1e-5);
		}
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:33,代码来源:TestCRF.java

示例2: applyModel

import cc.mallet.fst.SumLatticeDefault; //导入方法依赖的package包/类
@Override
public List<ModelApplication> applyModel(
        AnnotationSet instanceAS, AnnotationSet inputAS, AnnotationSet sequenceAS, 
        String parms) {
  // stop growth
  CorpusRepresentationMalletSeq data = (CorpusRepresentationMalletSeq)corpusRepresentation;
  data.stopGrowth();
  
  List<ModelApplication> gcs = new ArrayList<ModelApplication>();

  Transducer crf = (Transducer)model;
  
  for(Annotation sequenceAnn : sequenceAS) {
    int sequenceSpanId = sequenceAnn.getId();
    Instance inst = data.getInstanceForSequence( 
            instanceAS, sequenceAnn, inputAS, null, null, TargetType.NONE, null, null);

    //Always put the instance through the same pipe used for training.
    inst = crf.getInputPipe().instanceFrom(inst);

    SumLatticeDefault sl = new SumLatticeDefault(crf,
            (FeatureVectorSequence) inst.getData());

    List<Annotation> instanceAnnotations = gate.Utils.getContainedAnnotations(
            instanceAS, sequenceAnn).inDocumentOrder();

    //Sanity check that we're mapping the probs back onto the right anns.
    //This being wrong might follow from errors reading in the data to mallet inst.
    if (instanceAnnotations.size() != ((FeatureVectorSequence) inst.getData()).size()) {
      logger.warn("LearningFramework: CRF output length: "
              + ((FeatureVectorSequence) inst.getData()).size()
              + ", GATE instances: " + instanceAnnotations.size()
              + ". Can't assign.");
    } else {
      int i = 0;
      for (Annotation instanceAnn : instanceAnnotations) {
        i++;

        String bestLabel = null;
        double bestProb = 0.0;

        //For each label option ..
        
        // NOTE: for CRF we had this code:
        //for (int j = 0; j < crf.getOutputAlphabet().size(); j++) {
        //  String label = crf.getOutputAlphabet().lookupObject(j).toString();
        // but for Transducer we do not have the getOutputAlphabet method so we use
        // model.getInputPipe().getTargetAlphabet() instead (this seems to be what 
        // is used inside CRF anyway.)
        for (int j = 0; j < crf.getInputPipe().getTargetAlphabet().size(); j++) {
          String label = crf.getInputPipe().getTargetAlphabet().lookupObject(j).toString();

          //Get the probability of being in state j at position i+1
          //Note that the plus one is because the labels are on the
          //transitions. Positions are between transitions.
          double marg = sl.getGammaProbability(i, crf.getState(j));
          if (marg > bestProb) {
            bestLabel = label;
            bestProb = marg;
          }
        }
        ModelApplication gc = new ModelApplication(
                instanceAnn, bestLabel, bestProb, sequenceSpanId);

        gcs.add(gc);
      }
    }
  }
  data.startGrowth();
  return gcs;
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:72,代码来源:EngineMBMalletSeq.java


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