// // PROB OF TAG AT SINGLE POSITION CONDITIONED ON PREVIOUS AND FOLLOWING // SEQUENCE OF LABELS // // public double condProbGivenPreviousAndNext(int position, int label, int[] // prevLabels, int[] nextLabels) { // } // // JOINT CONDITIONAL PROBS // /// <returns>a new CRFCliqueTree for the weights on the data</returns> public static Edu.Stanford.Nlp.IE.Crf.CRFCliqueTree <E> GetCalibratedCliqueTree <E>(int[][][] data, IList <IIndex <CRFLabel> > labelIndices, int numClasses, IIndex <E> classIndex, E backgroundSymbol, ICliquePotentialFunction 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_1 = factorTables.Length - 2; i_1 >= 0; i_1--) { FactorTable summedOut = factorTables[i_1 + 1].SumOutEnd(); summedOut.DivideBy(messages[i_1]); // log.info("backward summedOut, summedOut= " + summedOut.toProbString()); factorTables[i_1].MultiplyInEnd(summedOut); } // log.info("after backward calibration, FT["+i+"] = " + factorTables[i].toProbString()); return(new Edu.Stanford.Nlp.IE.Crf.CRFCliqueTree <E>(factorTables, classIndex, backgroundSymbol)); }
// static FactorTable getFactorTable(double[][] weights, int[][] data, List<Index<CRFLabel>> labelIndices, int numClasses, int posInSent) { // CliquePotentialFunction cliquePotentialFunc = new LinearCliquePotentialFunction(weights); // return getFactorTable(data, labelIndices, numClasses, cliquePotentialFunc, null, posInSent); // } internal static FactorTable GetFactorTable(int[][] data, IList <IIndex <CRFLabel> > labelIndices, int numClasses, ICliquePotentialFunction cliquePotentialFunc, double[][] featureValByCliqueSize, int posInSent) { FactorTable factorTable = null; for (int j = 0; j < sz; j++) { IIndex <CRFLabel> labelIndex = labelIndices[j]; FactorTable ft = new FactorTable(numClasses, j + 1); double[] featureVal = null; if (featureValByCliqueSize != null) { featureVal = featureValByCliqueSize[j]; } // ... and each possible labeling for that clique for (int k = 0; k < liSize; k++) { int[] label = labelIndex.Get(k).GetLabel(); double cliquePotential = cliquePotentialFunc.ComputeCliquePotential(j + 1, k, data[j], featureVal, posInSent); // for (int m = 0; m < data[j].length; m++) { // weight += weights[data[j][m]][k]; // } // try{ ft.SetValue(label, cliquePotential); } // } catch (Exception e) { // System.out.println("CRFCliqueTree::getFactorTable"); // System.out.println("NumClasses: " + numClasses + " j+1: " + (j+1)); // System.out.println("k: " + k+" label: " +label+" labelIndexSize: " + // labelIndex.size()); // throw new RunTimeException(e.toString()); // } if (j > 0) { ft.MultiplyInEnd(factorTable); } factorTable = ft; } return(factorTable); }
public virtual void SetWeights(double[][] weights) { this.weights = weights; cliquePotentialFunc = new LinearCliquePotentialFunction(weights); }