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


Java Sequence类代码示例

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


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

示例1: apply

import cc.mallet.types.Sequence; //导入依赖的package包/类
/**
 * Apply a transducer to an input sequence to produce the k highest-scoring
 * output sequences.
 *
 * @param model the <code>Transducer</code>
 * @param input the input sequence
 * @param k the number of answers to return
 * @return array of the k highest-scoring output sequences
 */
public static Sequence[] apply(Transducer model, Sequence input, int k)
{
  Sequence[] answers;
  if (k == 1) {
    answers = new Sequence[1];
    answers[0] = model.transduce (input);
  }
  else {
    MaxLatticeDefault lattice =
            new MaxLatticeDefault (model, input, null, cacheSizeOption.value());

    answers = lattice.bestOutputSequences(k).toArray(new Sequence[0]);
  }
  return answers;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:25,代码来源:SimpleTaggerWithConstraints.java

示例2: averageTokenAccuracy

import cc.mallet.types.Sequence; //导入依赖的package包/类
/**
 * Runs inference across all the instances and returns the average token
 * accuracy.
 */
public double averageTokenAccuracy (InstanceList ilist)
{
	double accuracy = 0;
	for (int i = 0; i < ilist.size(); i++) {
		Instance instance = ilist.get(i);
		Sequence input = (Sequence) instance.getData();
		Sequence output = (Sequence) instance.getTarget();
		assert (input.size() == output.size());
		Sequence predicted = maxLatticeFactory.newMaxLattice(this, input).bestOutputSequence();
		double pathAccuracy = Sequences.elementwiseAccuracy(output, predicted); 
		accuracy += pathAccuracy;
		logger.fine ("Transducer path accuracy = "+pathAccuracy);
	}
	return accuracy/ilist.size();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:Transducer.java

示例3: addSpansFromTags

import cc.mallet.types.Sequence; //导入依赖的package包/类
private void addSpansFromTags (LabeledSpans labeled, Tokenization input, Sequence tags, LabelAlphabet dict,
                              Label backgroundTag)
{
  int i = 0;
  int docidx = 0;
  while (i < tags.size()) {
    Label thisTag = dict.lookupLabel (tags.get(i).toString());
    int startTokenIdx = i;
    while (i < tags.size()) {
      Label nextTag = dict.lookupLabel (tags.get(i).toString ());
      if (thisTag != nextTag) break;
      i++;
    }
    int endTokenIdx = i;
    Span span = input.subspan(startTokenIdx, endTokenIdx);
    addBackgroundIfNecessary (labeled, (StringSpan) span, docidx, backgroundTag);
    docidx = ((StringSpan) span).getEndIdx ();
    labeled.add (new LabeledSpan (span, thisTag, thisTag == backgroundTag));
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:21,代码来源:DefaultTokenizationFilter.java

示例4: predict

import cc.mallet.types.Sequence; //导入依赖的package包/类
/** This method is deprecated. */
// But it is here as a reminder to do something about induceFeaturesFor(). */
@Deprecated
public Sequence[] predict (InstanceList testing) {
	testing.setFeatureSelection(this.globalFeatureSelection);
	for (int i = 0; i < featureInducers.size(); i++) {
		FeatureInducer klfi = (FeatureInducer)featureInducers.get(i);
		klfi.induceFeaturesFor (testing, false, false);
	}
	Sequence[] ret = new Sequence[testing.size()];
	for (int i = 0; i < testing.size(); i++) {
		Instance instance = testing.get(i);
		Sequence input = (Sequence) instance.getData();
		Sequence trueOutput = (Sequence) instance.getTarget();
		assert (input.size() == trueOutput.size());
		Sequence predOutput = new MaxLatticeDefault(this, input).bestOutputSequence();
		assert (predOutput.size() == trueOutput.size());
		ret[i] = predOutput;
	}
	return ret;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:22,代码来源:CRF.java

示例5: addSpansFromTags

import cc.mallet.types.Sequence; //导入依赖的package包/类
private void addSpansFromTags (LabeledSpans labeled, Tokenization input, Sequence tags, LabelAlphabet dict,
                               Label backgroundTag)
{
  int i = 0;
  int docidx = 0;
  while (i < tags.size ()) {
    Label thisTag = dict.lookupLabel (tags.get (i).toString ());
    int startTokenIdx = i;
    while (++i < tags.size ()) {
      Label nextTag = dict.lookupLabel (tags.get (i).toString ());
      if (isBeginTag (nextTag) || !tagsMatch (thisTag, nextTag)) break;
    }
    int endTokenIdx = i;
    Span span = createSpan (input, startTokenIdx, endTokenIdx);
    addBackgroundIfNecessary (labeled, (StringSpan) span, docidx, backgroundTag);
    docidx = ((StringSpan) span).getEndIdx ();

    if (isBeginTag (thisTag) || isInsideTag (thisTag)) {
      thisTag = trimTag (dict, thisTag);
    }
    labeled.add (new LabeledSpan (span, thisTag, thisTag == backgroundTag));
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:BIOTokenizationFilter.java

示例6: bestStateAlignments

import cc.mallet.types.Sequence; //导入依赖的package包/类
/**
  * Perform the backward pass of Viterbi, returning the n-best sequences of
  * States. Note that the length of each State Sequence is inputLength+1,
  * because the first element of the sequence is the start state, and the first
  * input/output symbols occur on the transition from a start state to the next
  * state. The last State in the sequence corresponds to the final state.
  */	
public List<SequencePairAlignment<Object,State>> bestStateAlignments (int n) {
	if (stateAlignmentCache != null && stateAlignmentCache.size() >= n)
		return stateAlignmentCache;
	bestViterbiNodeSequences(n); // ensure that viterbiNodeAlignmentCache has at least size n
	ArrayList<SequencePairAlignment<Object,State>> ret = new ArrayList<SequencePairAlignment<Object,State>>(n);
	for (int i = 0; i < n; i++) {
		State[] ss = new State[latticeLength];
		Sequence<ViterbiNode> vs = viterbiNodeAlignmentCache.get(i).output();
		for (int j = 0; j < latticeLength; j++)
			ss[j] = vs.get(j).state; // Here is where we grab the state from the ViterbiNode
		ret.add(new SequencePairAlignment<Object,State>(input, new ArraySequence<State>(ss), viterbiNodeAlignmentCache.get(i).getWeight()));
	}
	stateAlignmentCache = ret;
	return ret;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:MaxLatticeDefault.java

示例7: tokenAccuracy

import cc.mallet.types.Sequence; //导入依赖的package包/类
public double tokenAccuracy (Sequence referenceOutput, PrintWriter out)
{
	Sequence output = bestOutputSequence();
	int accuracy = 0;
	String testString;
	assert (referenceOutput.size() == output.size());
	for (int i = 0; i < output.size(); i++) {
		//logger.fine("tokenAccuracy: ref: "+referenceOutput.get(i)+" viterbi: "+output.get(i));
		testString = output.get(i).toString();
		if (out != null) {
			out.println(testString);
		}
		if (referenceOutput.get(i).toString().equals (testString)) {
			accuracy++;
		}
	}
	logger.info ("Number correct: " + accuracy + " out of " + output.size());
	return ((double)accuracy)/output.size();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:MaxLatticeDefault.java

示例8: computeLikelihood

import cc.mallet.types.Sequence; //导入依赖的package包/类
private double computeLikelihood(InstanceList trainingSample) {
	double loglik = 0.0;
	for (int i = 0; i < trainingSample.size(); i++) {
		Instance trainingInstance = trainingSample.get(i);
		FeatureVectorSequence fvs = (FeatureVectorSequence) trainingInstance
				.getData();
		Sequence labelSequence = (Sequence) trainingInstance.getTarget();
		loglik += new SumLatticeDefault(crf, fvs, labelSequence, null)
				.getTotalWeight();
		loglik -= new SumLatticeDefault(crf, fvs, null, null)
				.getTotalWeight();
	}
	constraints.zero();
	expectations.zero();
	return loglik;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:CRFTrainerByStochasticGradient.java

示例9: trainIncrementalLikelihood

import cc.mallet.types.Sequence; //导入依赖的package包/类
/**
 * Adjust the parameters by learning rate according to the gradient of this
 * single Instance, and return the true label sequence likelihood.
 */
public double trainIncrementalLikelihood(Instance trainingInstance,
		double rate) {
	double singleLoglik;
	constraints.zero();
	expectations.zero();
	FeatureVectorSequence fvs = (FeatureVectorSequence) trainingInstance
			.getData();
	Sequence labelSequence = (Sequence) trainingInstance.getTarget();
	singleLoglik = new SumLatticeDefault(crf, fvs, labelSequence,
			constraints.new Incrementor()).getTotalWeight();
	singleLoglik -= new SumLatticeDefault(crf, fvs, null,
			expectations.new Incrementor()).getTotalWeight();
	// Calculate parameter gradient given these instances: (constraints -
	// expectations)
	constraints.plusEquals(expectations, -1);
	// Change the parameters a little by this difference, obeying
	// weightsFrozen
	crf.parameters.plusEquals(constraints, rate, true);

	return singleLoglik;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:26,代码来源:CRFTrainerByStochasticGradient.java

示例10: transitionIterator

import cc.mallet.types.Sequence; //导入依赖的package包/类
public Transducer.TransitionIterator transitionIterator(
		Sequence inputSequence, int inputPosition,
		Sequence outputSequence, int outputPosition) {
	if (inputPosition < 0 || outputPosition < 0)
		throw new UnsupportedOperationException(
				"Epsilon transitions not implemented.");
	if (inputSequence == null)
		throw new UnsupportedOperationException(
				"HMMs are generative models; but this is not yet implemented.");
	if (!(inputSequence instanceof FeatureSequence))
		throw new UnsupportedOperationException(
				"HMMs currently expect Instances to have FeatureSequence data");
	return new TransitionIterator(this,
			(FeatureSequence) inputSequence, inputPosition,
			(outputSequence == null ? null : (String) outputSequence
					.get(outputPosition)), hmm);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:HMM.java

示例11: evaluateInstanceList

import cc.mallet.types.Sequence; //导入依赖的package包/类
public void evaluateInstanceList (TransducerTrainer tt, InstanceList data, String description)
{
  int correct = 0;
  for (int i = 0; i < data.size(); i++) {
    Instance instance = data.get(i);
    Sequence input = (Sequence) instance.getData();
    Sequence trueOutput = (Sequence) instance.getTarget();
    assert (input.size() == trueOutput.size());
    Sequence predOutput = tt.getTransducer().transduce (input);
    assert (predOutput.size() == trueOutput.size());
    if (sequencesMatch (trueOutput, predOutput))
      correct++;
    }
  double acc = ((double)correct) / data.size();
accuracy.put(description, acc);

  logger.info (description+" Num instances = "+data.size()+"  Num correct = "+correct+" Per-instance accuracy = "+acc);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:19,代码来源:InstanceAccuracyEvaluator.java

示例12: sequencesMatch

import cc.mallet.types.Sequence; //导入依赖的package包/类
private boolean sequencesMatch (Sequence trueOutput, Sequence predOutput)
{
  for (int j = 0; j < trueOutput.size(); j++) {
    Object tru = trueOutput.get(j);
    Object pred = predOutput.get(j);
    if (!tru.toString().equals (pred.toString())) {
      return false;
    }
  }
  return true;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:InstanceAccuracyEvaluator.java

示例13: apply

import cc.mallet.types.Sequence; //导入依赖的package包/类
/**
 * Apply a transducer to an input sequence to produce the k highest-scoring
 * output sequences.
 *
 * @param model the <code>Transducer</code>
 * @param input the input sequence
 * @param k the number of answers to return
 * @return array of the k highest-scoring output sequences
 */
public static Sequence[] apply(Transducer model, Sequence input, int k) {

	Sequence[] answers;
	if (k == 1) {
		answers = new Sequence[1];
		answers[0] = model.transduce (input);
	}
	else {
		MaxLatticeDefault lattice =
			new MaxLatticeDefault (model, input, null, cacheSizeOption.value());

		answers = lattice.bestOutputSequences(k).toArray(new Sequence[0]);
	}

	return answers;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:26,代码来源:SimpleTagger.java

示例14: transitionIterator

import cc.mallet.types.Sequence; //导入依赖的package包/类
public Transducer.TransitionIterator transitionIterator (Sequence inputSequence,
																												 int inputPosition)
{
	int inputIndex = inputAlphabet.lookupIndex (inputSequence.get(inputPosition), false);
	if (inputIndex == -1)
		throw new IllegalArgumentException ("Input not in dictionary.");
	return transitionIterator (inputIndex);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:FeatureTransducer.java

示例15: pipe

import cc.mallet.types.Sequence; //导入依赖的package包/类
public Instance pipe(Instance carrier)
{
  StringBuffer sb = new StringBuffer();
  String source = (String) carrier.getSource();
  Sequence as = (Sequence) carrier.getTarget();
  //int startLabelIndex = as.getAlphabet().lookupIndex("start");
  for (int i = 0; i < source.length(); i++) {
    System.out.println("target[" + i + "]=" + as.get(i).toString());
    if (as.get(i).toString().equals("start") && i != 0)
      sb.append(' ');
    sb.append(source.charAt(i));
  }
  carrier.setSource(sb.toString());
  System.out.println("carrier.getSource() = " + carrier.getSource());
  return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:TestMEMM.java


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