private void normalizeCosts () { // Normalize the next-state costs, so they are -(log-probabilities) // This is the heart of the difference between the locally-normalized MEMM // and the globally-normalized CRF sum = Transducer.IMPOSSIBLE_WEIGHT; for (int i = 0; i < weights.length; i++) sum = sumLogProb (sum, weights[i]); assert (!Double.isNaN (sum)); if (!Double.isInfinite (sum)) { for (int i = 0; i < weights.length; i++) weights[i] -= sum; } }
private void normalizeCosts () { // Normalize the next-state costs, so they are -(log-probabilities) // This is the heart of the difference between the locally-normalized MEMM // and the globally-normalized CRF sum = Transducer.IMPOSSIBLE_WEIGHT; for (int i = 0; i < weights.length; i++) sum = sumLogProb (sum, weights[i]); assert (!Double.isNaN (sum)); if (!Double.isInfinite (sum)) { for (int i = 0; i < weights.length; i++) weights[i] -= sum; } }
private void normalizeCosts () { // Normalize the next-state costs, so they are -(log-probabilities) // This is the heart of the difference between the locally-normalized MEMM // and the globally-normalized CRF sum = Transducer.IMPOSSIBLE_WEIGHT; for (int i = 0; i < weights.length; i++) sum = sumLogProb (sum, weights[i]); assert (!Double.isNaN (sum)); if (!Double.isInfinite (sum)) { for (int i = 0; i < weights.length; i++) weights[i] -= sum; } }
public void testSumLogProb() { double w1 = Math.log(.2); double w2 = Math.log(.8); double s1 = Math.log(.2 + .8); double s2 = Transducer.sumLogProb(w1, w2); assertEquals(s1, s2, 0.00001); w1 = Math.log(99999); w2 = Math.log(.0001); s1 = Math.log(99999.0001); s2 = Transducer.sumLogProb(w1, w2); assertEquals(s1, s2, 0.00001); }
public void testSumLogProb() { double w1 = Math.log(.2); double w2 = Math.log(.8); double s1 = Math.log(.2 + .8); double s2 = Transducer.sumLogProb(w1, w2); assertEquals(s1, s2, 0.00001); w1 = Math.log(99999); w2 = Math.log(.0001); s1 = Math.log(99999.0001); s2 = Transducer.sumLogProb(w1, w2); assertEquals(s1, s2, 0.00001); }
CSNLP[i] = lc; } else { CSNLP[i] = Transducer.sumLogProb(CSNLP[i-1], lc);
CSNLP[i] = lc; } else { CSNLP[i] = Transducer.sumLogProb(CSNLP[i-1], lc);
CSNLP[i] = lc; } else { CSNLP[i] = Transducer.sumLogProb(CSNLP[i-1], lc);
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
if (logger.isLoggable (Level.FINE)) logger.fine ("BEFORE update: destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); if (logger.isLoggable (Level.FINE)) logger.fine ("transitionWeight="+transitionWeight+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); double oldBeta = nodes[ip][i].beta; assert (!Double.isNaN(nodes[ip][i].beta)); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta)) : "dest.beta="+destinationNode.beta+" trans="+transitionWeight+" sum="+(destinationNode.beta+transitionWeight) + " oldBeta="+oldBeta;
+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha +" destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); continue; logger.fine ("Summing final lattice weight. state="+i+", alpha="+nodes[latticeLength-1][i].alpha + ", final weight = "+t.getState(i).getFinalWeight()); totalWeight = Transducer.sumLogProb (totalWeight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta))
+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha +" destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); continue; logger.fine ("Summing final lattice weight. state="+i+", alpha="+nodes[latticeLength-1][i].alpha + ", final weight = "+t.getState(i).getFinalWeight()); weight = Transducer.sumLogProb (weight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta))
+" nodes["+ip+"]["+i+"].alpha="+nodes[ip][i].alpha +" destinationNode.alpha="+destinationNode.alpha); destinationNode.alpha = Transducer.sumLogProb (destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); continue; logger.fine ("Summing final lattice weight. state="+i+", alpha="+nodes[latticeLength-1][i].alpha + ", final weight = "+t.getState(i).getFinalWeight()); weight = Transducer.sumLogProb (weight, (nodes[latticeLength-1][i].alpha + t.getState(i).getFinalWeight())); nodes[ip][i].beta = Transducer.sumLogProb (nodes[ip][i].beta, destinationNode.beta + transitionWeight); assert (!Double.isNaN(nodes[ip][i].beta))
double transitionWeight = iter.getWeight(); transitionWeight += auxModel.getWeight(index,ip,input,iter); destinationNode.alpha = Transducer.sumLogProb( destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); for (int i = 0; i < numStates; i++) { if (nodes[latticeLength-1][i] != null) { totalWeight = Transducer.sumLogProb(totalWeight, (nodes[latticeLength-1][i].alpha + transducer.getState(i).getFinalWeight())); transitionWeight += auxModel.getWeight(index,ip,input,iter); nodes[ip][i].beta = Transducer.sumLogProb( nodes[ip][i].beta, destinationNode.beta + transitionWeight);
double transitionWeight = iter.getWeight(); transitionWeight += auxModel.getWeight(index,ip,input,iter); destinationNode.alpha = Transducer.sumLogProb( destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); for (int i = 0; i < numStates; i++) { if (nodes[latticeLength-1][i] != null) { totalWeight = Transducer.sumLogProb(totalWeight, (nodes[latticeLength-1][i].alpha + transducer.getState(i).getFinalWeight())); transitionWeight += auxModel.getWeight(index,ip,input,iter); nodes[ip][i].beta = Transducer.sumLogProb( nodes[ip][i].beta, destinationNode.beta + transitionWeight);
double transitionWeight = iter.getWeight(); transitionWeight += auxModel.getWeight(index,ip,input,iter); destinationNode.alpha = Transducer.sumLogProb( destinationNode.alpha, nodes[ip][i].alpha + transitionWeight); for (int i = 0; i < numStates; i++) { if (nodes[latticeLength-1][i] != null) { totalWeight = Transducer.sumLogProb(totalWeight, (nodes[latticeLength-1][i].alpha + transducer.getState(i).getFinalWeight())); transitionWeight += auxModel.getWeight(index,ip,input,iter); nodes[ip][i].beta = Transducer.sumLogProb( nodes[ip][i].beta, destinationNode.beta + transitionWeight);