private boolean[][] labelConnectionsIn(InstanceList trainingSet) { int numLabels = outputAlphabet.size(); boolean[][] connections = new boolean[numLabels][numLabels]; for (Instance instance : trainingSet) { FeatureSequence output = (FeatureSequence) instance.getTarget(); for (int j = 1; j < output.size(); j++) { int sourceIndex = outputAlphabet.lookupIndex(output.get(j - 1)); int destIndex = outputAlphabet.lookupIndex(output.get(j)); assert (sourceIndex >= 0 && destIndex >= 0); connections[sourceIndex][destIndex] = true; } } return connections; }
public TransitionIterator( State source, FeatureSequence inputSeq, int inputPosition, String output, HMM hmm) { this.source = source; this.hmm = hmm; this.inputSequence = inputSeq; this.inputFeature = new Integer(inputSequence.getIndexAtPosition(inputPosition)); this.inputPos = inputPosition; this.weights = new double[source.destinations.length]; for (int transIndex = 0; transIndex < source.destinations.length; transIndex++) { if (output == null || output.equals(source.labels[transIndex])) { weights[transIndex] = 0; // xxx should this be emission of the _next_ observation? // double logEmissionProb = // hmm.emissionMultinomial[source.getIndex()].logProbability // (inputSeq.get (inputPosition)); int destIndex = source.getDestinationState(transIndex).getIndex(); double logEmissionProb = hmm.emissionMultinomial[destIndex].logProbability(inputSeq.get(inputPosition)); double logTransitionProb = hmm.transitionMultinomial[source.getIndex()].logProbability( source.destinationNames[transIndex]); // weight = logProbability weights[transIndex] = (logEmissionProb + logTransitionProb); assert (!Double.isNaN(weights[transIndex])); } else weights[transIndex] = IMPOSSIBLE_WEIGHT; } nextIndex = 0; while (nextIndex < source.destinations.length && weights[nextIndex] == IMPOSSIBLE_WEIGHT) nextIndex++; }