本文整理汇总了Java中cc.mallet.fst.SumLatticeDefault类的典型用法代码示例。如果您正苦于以下问题:Java SumLatticeDefault类的具体用法?Java SumLatticeDefault怎么用?Java SumLatticeDefault使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SumLatticeDefault类属于cc.mallet.fst包,在下文中一共展示了SumLatticeDefault类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeExpectations
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
/**
* Resets, computes and fills expectations from all instances, also updating
* the entropy value. <p>
*
* Analogous to <tt>CRFOptimizableByLabelLikelihood.getExpectationValue<tt>.
*/
public void computeExpectations() {
expectations.zero();
// now, update the expectations due to each instance for entropy reg.
for (int ii = 0; ii < data.size(); ii++) {
FeatureVectorSequence input = (FeatureVectorSequence) data.get(ii).getData();
SumLattice lattice = new SumLatticeDefault(crf,input, true);
// udpate the expectations
EntropyLattice entropyLattice = new EntropyLattice(
input, lattice.getGammas(), lattice.getXis(), crf,
incrementor, scalingFactor);
cachedValue += entropyLattice.getEntropy();
}
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:22,代码来源:CRFOptimizableByEntropyRegularization.java
示例2: gatherConstraints
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
protected void gatherConstraints() {
// Set the constraints by running forward-backward with the *output
// label sequence provided*, thus restricting it to only those
// paths that agree with the label sequence.
// Zero the constraints[]
// Reset constraints[] to zero before we fill them again
assert (constraints.structureMatches(crf.parameters));
constraints.zero();
for (Instance instance : sourceInstances) {
FeatureVectorSequence input = (FeatureVectorSequence) instance
.getData();
FeatureSequence output = (FeatureSequence) instance.getTarget();
double instanceWeight = sourceInstances.getInstanceWeight(instance);
// System.out.println
// ("Constraint-gathering on instance "+i+" of "+ilist.size());
Transducer.Incrementor incrementor = instanceWeight == 1.0 ? constraints.new Incrementor()
: constraints.new WeightedIncrementor(instanceWeight);
new SumLatticeDefault(this.crf, input, output, incrementor);
}
// System.out.println ("testing Value and Gradient");
// TestOptimizable.testValueAndGradientCurrentParameters (this);
}
示例3: getSourceExpectations
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
protected void getSourceExpectations() {
assert (sourceExpectations.structureMatches(crf.parameters));
sourceExpectations.zero();
for (Instance instance : sourceInstances) {
FeatureVectorSequence input = (FeatureVectorSequence) instance
.getData();
FeatureSequence output = (FeatureSequence) instance.getTarget();
double instanceWeight = sourceInstances.getInstanceWeight(instance);
Transducer.Incrementor incrementor = instanceWeight == 1.0 ? sourceExpectations.new Incrementor()
: sourceExpectations.new WeightedIncrementor(instanceWeight);
new SumLatticeDefault(this.crf, input, output, incrementor);
}
double factor = 1.0 / sourceInstances.size();
for (int i = 0; i < sourceExpectations.weights.length; i++) {
log(sourceExpectations.weights[i], factor);
}
}
示例4: getTargetExpectations
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
protected void getTargetExpectations() {
// Reset expectations to zero before we fill them again
assert (targetExpectations.structureMatches(crf.parameters));
targetExpectations.zero();
// Calculate the value of each instance, and also fill in expectations
for (Instance instance : targetInstances) {
FeatureVectorSequence input = (FeatureVectorSequence) instance
.getData();
double instanceWeight = targetInstances.getInstanceWeight(instance);
Transducer.Incrementor incrementor = instanceWeight == 1.0 ? targetExpectations.new Incrementor()
: targetExpectations.new WeightedIncrementor(instanceWeight);
new SumLatticeDefault(this.crf, input, null, incrementor);
}
double factor = 1.0 / targetInstances.size();
for (int i = 0; i < targetExpectations.weights.length; i++) {
log(targetExpectations.weights[i], factor);
}
}
示例5: annotate
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
public List<ReferenceLineAnnotation> annotate(List<String> linesWithLayout) throws IOException, AnalysisException {
StringBuilder lineStringBuilder = new StringBuilder();
for (String line : linesWithLayout) {
lineStringBuilder.append(line).append(System.lineSeparator());
}
BufferedReader lineReader = new BufferedReader(new StringReader(lineStringBuilder.toString()));
InstanceList inputInstances = new InstanceList(this.pipe);
inputInstances.addThruPipe(new LineGroupIterator(lineReader, Pattern.compile("^\\s*$"), true));
lineReader.close();
List<ReferenceLineAnnotation> referenceLineAnnotations = new ArrayList<ReferenceLineAnnotation>();
for (Instance instance : inputInstances) {
@SuppressWarnings("unchecked")
Sequence<String> inputSequence = (Sequence<String>) instance.getData();
SumLatticeDefault latticeDefault = new SumLatticeDefault(this.crf, inputSequence);
Alphabet outputAlphabet = this.crf.getOutputAlphabet();
if (linesWithLayout.size() != inputSequence.size()) {
throw new IllegalStateException("linesWithLayout.size()!=inputSequence.size()");
}
for (int i = 0; i < inputSequence.size(); i++) {
ReferenceLineAnnotation referenceLineAnnotation = new ReferenceLineAnnotation(
linesWithLayout.get(i).split("\\t")[0]);
for (int j = 1; j <= outputAlphabet.size(); j++) {
State state = this.crf.getState(j);
referenceLineAnnotation.addAnnotation(state.getName(),
latticeDefault.getGammaProbability(i + 1, state));
}
referenceLineAnnotations.add(referenceLineAnnotation);
}
}
return referenceLineAnnotations;
}
示例6: SumLatticeTask
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
public SumLatticeTask(CRF crf, InstanceList data, BitSet instancesWithConstraints, int start, int end) {
this.crf = crf;
this.data = data;
this.start = start;
this.end = end;
this.lattices = new ArrayList<SumLatticeDefault>();
this.instancesWithConstraints = instancesWithConstraints;
}
示例7: call
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
public Void call() throws Exception {
for (int ii = start; ii < end; ii++) {
if (instancesWithConstraints.get(ii)) {
Instance instance = data.get(ii);
SumLatticeDefault lattice = new SumLatticeDefault(
this.crf, (FeatureVectorSequence)instance.getData(),
null, null, true);
lattices.add(lattice);
}
else {
lattices.add(null);
}
}
return null;
}
示例8: testIncrement
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
public void testIncrement ()
{
transducer.setTrainable (true);
SumLatticeDefault lattice = new SumLatticeDefault (transducer, seq); // used to have third argument: true
double oldWeight = lattice.getTotalWeight ();
System.out.println ("State 0 transition estimator");
Multinomial.Estimator est
= ((FeatureTransducer.State)transducer.getState(0)).getTransitionEstimator();
est.print();
assertTrue (est.getCount(0) == 2.0);
assertTrue (est.getCount(1) == 1.0);
}
示例9: 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);
}
}
}
示例10: getStatistics
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
private void getStatistics(CRF crf, Instance inst,
Map<Instance, Double> entropyMap, Map<Instance, Double> probMap,
boolean setTarget) {
FeatureVectorSequence input = (FeatureVectorSequence) inst.getData();
MaxLatticeDefault maxLattice = new MaxLatticeDefault(crf, input);
Sequence output = maxLattice.bestOutputSequence();
double labeled = new SumLatticeDefault(crf, input, output)
.getTotalWeight();
SumLattice lattice = new SumLatticeDefault(crf, input, true);
double unlabeled = lattice.getTotalWeight();
EntropyLattice entropyLattice = new EntropyLattice(input,
lattice.getGammas(), lattice.getXis(), crf, null, 1);
double entropy = -entropyLattice.getEntropy();
double prob = Math.exp(labeled - unlabeled);
entropyMap.put(inst, entropy);
probMap.put(inst, prob);
if (setTarget) {
inst.unLock();
int n = output.size();
LabelSequence seq = new LabelSequence(
(LabelAlphabet) crf.getOutputAlphabet(), n);
for (int i = 0; i < output.size(); i++) {
seq.add(output.get(i));
}
inst.setTarget(seq);
inst.lock();
}
}
示例11: ignoretestIncrement
import cc.mallet.fst.SumLatticeDefault; //导入依赖的package包/类
public void ignoretestIncrement ()
{
transducer.setTrainable (true);
SumLatticeDefault lattice = new SumLatticeDefault (transducer, seq); // used to have third argument: true
double oldWeight = lattice.getTotalWeight ();
System.out.println ("State 0 transition estimator");
Multinomial.Estimator est
= ((FeatureTransducer.State)transducer.getState(0)).getTransitionEstimator();
est.print();
assertTrue (est.getCount(0) == 2.0);
assertTrue (est.getCount(1) == 1.0);
}