/** * This function assumes a LinearCliquePotentialFunction is used for wrapping the weights * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(double[] weights, double wscale, int[][] weightIndices, int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { factorTables[i] = getFactorTable(weights, wscale, weightIndices, data[i], labelIndices, numClasses); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); factorTables[i].multiplyInFront(messages[i - 1]); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); factorTables[i].multiplyInEnd(summedOut); } return new CRFCliqueTree<>(factorTables, classIndex, backgroundSymbol); }
/** * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol, CliquePotentialFunction cliquePotentialFunc, double[][][] featureVals) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { double[][] featureValByCliqueSize = null; if (featureVals != null) featureValByCliqueSize = featureVals[i]; factorTables[i] = getFactorTable(data[i], labelIndices, numClasses, cliquePotentialFunc, featureValByCliqueSize, i); // log.info("before calibration,FT["+i+"] = " + factorTables[i].toProbString()); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); // log.info("forward message, message["+(i-1)+"] = " + messages[i-1].toProbString()); factorTables[i].multiplyInFront(messages[i - 1]); // log.info("after forward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); // log.info("backward summedOut, summedOut= " + summedOut.toProbString()); factorTables[i].multiplyInEnd(summedOut); // log.info("after backward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } return new CRFCliqueTree<>(factorTables, classIndex, backgroundSymbol); }
/** * This function assumes a LinearCliquePotentialFunction is used for wrapping the weights * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(double[] weights, double wscale, int[][] weightIndices, int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { factorTables[i] = getFactorTable(weights, wscale, weightIndices, data[i], labelIndices, numClasses); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); factorTables[i].multiplyInFront(messages[i - 1]); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); factorTables[i].multiplyInEnd(summedOut); } return new CRFCliqueTree<>(factorTables, classIndex, backgroundSymbol); }
/** * @return a new CRFCliqueTree for the weights on the data */ public static CRFCliqueTree getCalibratedCliqueTree(double[][] weights, int[][][] data, Index[] labelIndices, int numClasses, Index classIndex, String backgroundSymbol) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { factorTables[i] = getFactorTable(weights, data[i], labelIndices, numClasses); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); factorTables[i].multiplyInFront(messages[i - 1]); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); factorTables[i].multiplyInEnd(summedOut); } return new CRFCliqueTree(factorTables, classIndex, backgroundSymbol); }
/** * This function assumes a LinearCliquePotentialFunction is used for wrapping the weights * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(double[] weights, double wscale, int[][] weightIndices, int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { factorTables[i] = getFactorTable(weights, wscale, weightIndices, data[i], labelIndices, numClasses); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); factorTables[i].multiplyInFront(messages[i - 1]); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); factorTables[i].multiplyInEnd(summedOut); } return new CRFCliqueTree<E>(factorTables, classIndex, backgroundSymbol); }
/** * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol, CliquePotentialFunction cliquePotentialFunc, double[][][] featureVals) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { double[][] featureValByCliqueSize = null; if (featureVals != null) featureValByCliqueSize = featureVals[i]; factorTables[i] = getFactorTable(data[i], labelIndices, numClasses, cliquePotentialFunc, featureValByCliqueSize, i); // log.info("before calibration,FT["+i+"] = " + factorTables[i].toProbString()); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); // log.info("forward message, message["+(i-1)+"] = " + messages[i-1].toProbString()); factorTables[i].multiplyInFront(messages[i - 1]); // log.info("after forward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); // log.info("backward summedOut, summedOut= " + summedOut.toProbString()); factorTables[i].multiplyInEnd(summedOut); // log.info("after backward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } return new CRFCliqueTree<>(factorTables, classIndex, backgroundSymbol); }
/** * @return a new CRFCliqueTree for the weights on the data */ public static <E> CRFCliqueTree<E> getCalibratedCliqueTree(int[][][] data, List<Index<CRFLabel>> labelIndices, int numClasses, Index<E> classIndex, E backgroundSymbol, CliquePotentialFunction cliquePotentialFunc, double[][][] featureVals) { FactorTable[] factorTables = new FactorTable[data.length]; FactorTable[] messages = new FactorTable[data.length - 1]; for (int i = 0; i < data.length; i++) { double[][] featureValByCliqueSize = null; if (featureVals != null) featureValByCliqueSize = featureVals[i]; factorTables[i] = getFactorTable(data[i], labelIndices, numClasses, cliquePotentialFunc, featureValByCliqueSize, i); // System.err.println("before calibration,FT["+i+"] = " + factorTables[i].toProbString()); if (i > 0) { messages[i - 1] = factorTables[i - 1].sumOutFront(); // System.err.println("forward message, message["+(i-1)+"] = " + messages[i-1].toProbString()); factorTables[i].multiplyInFront(messages[i - 1]); // System.err.println("after forward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } } for (int i = factorTables.length - 2; i >= 0; i--) { FactorTable summedOut = factorTables[i + 1].sumOutEnd(); summedOut.divideBy(messages[i]); // System.err.println("backward summedOut, summedOut= " + summedOut.toProbString()); factorTables[i].multiplyInEnd(summedOut); // System.err.println("after backward calibration, FT["+i+"] = " + factorTables[i].toProbString()); } return new CRFCliqueTree<E>(factorTables, classIndex, backgroundSymbol); }
factorTables[i].multiplyInFront(messages[i - 1]);