public ArrayList<Double> getPosteriorDecodingScores( SingleDPMatrix fMatrix, SingleDPMatrix bMatrix) { ArrayList<Double> pdScores = new ArrayList<Double>(); State states[] = fMatrix.states(); double fScore = fMatrix.getScore(); double fMatrixScores[][] = fMatrix.scores; double bMatrixScores[][] = bMatrix.scores; int numberOfObservations = fMatrixScores.length; int numberOfStates = states.length; for (int i = 1; i < numberOfObservations - 1; i++) { double sum = 0; double g = Double.MIN_VALUE; for (int s = 0; s < numberOfStates; s++) { g = getWeight(states[s].getName()); /* if( states[s].getName().equals("M")){ g=0; } else { g=1; } */ double probOfOneState = Math.exp(fMatrixScores[i][s] + bMatrixScores[i][s] - fScore); sum = sum + (probOfOneState * g); } pdScores.add(sum); } return pdScores; } /*getPosteriorDecodingScores*/
public ArrayList<String> getPosteriorDecodingPath( SingleDPMatrix fMatrix, SingleDPMatrix bMatrix) { ArrayList<String> pdPath = new ArrayList<String>(); State states[] = fMatrix.states(); double fScore = fMatrix.getScore(); double fMatrixScores[][] = fMatrix.scores; double bMatrixScores[][] = bMatrix.scores; int numberOfObservations = fMatrixScores.length; int numberOfStates = states.length; for (int i = 1; i < numberOfObservations - 1; i++) { ArrayList<Double> probOfStates = new ArrayList<Double>(); for (int s = 0; s < numberOfStates; s++) { double probOfOneState = Math.exp(fMatrixScores[i][s] + bMatrixScores[i][s] - fScore); probOfStates.add(probOfOneState); } Object max_obj = Collections.max(probOfStates); int maxValueIndex = probOfStates.indexOf(max_obj); State topScoredState = states[maxValueIndex]; pdPath.add(topScoredState.getName()); // System.out.print(topScoredState.getName()); } // System.out.println(); // System.out.println("\n number of rows is " + numberOfObservations); // System.out.println("\n length of posterior decoding path is " + pdPath.size()); return pdPath; } /*getPosteriorDecodingPath*/