/** * Computes value of function for specified value of x (scaled by xScale) * only over samples indexed by batch. * NOTE: This function does not do regularization (regularization is done by the minimizer). * * @param x - unscaled weights * @param xScale - how much to scale x by when performing calculations * @param batch - indices of which samples to compute function over * @return value of function at specified x (scaled by xScale) for samples */ @Override public double valueAt(double[] x, double xScale, int[] batch) { double prob = 0.0; // the log prob of the sequence given the model, which is the negation of value at this point // int[][] wis = getWeightIndices(); to2D(x, xScale, weights); setWeights(weights); // iterate over all the documents for (int ind : batch) { prob += valueForADoc(ind); } if (Double.isNaN(prob)) { // shouldn't be the case throw new RuntimeException("Got NaN for prob in CRFLogConditionalObjectiveFunction.calculate()"); } value = -prob; return value; }
/** * Computes value of function for specified value of x (scaled by xScale) * only over samples indexed by batch. * NOTE: This function does not do regularization (regularization is done by the minimizer). * * @param x - unscaled weights * @param xScale - how much to scale x by when performing calculations * @param batch - indices of which samples to compute function over * @return value of function at specified x (scaled by xScale) for samples */ @Override public double valueAt(double[] x, double xScale, int[] batch) { double prob = 0.0; // the log prob of the sequence given the model, which is the negation of value at this point // int[][] wis = getWeightIndices(); to2D(x, xScale, weights); setWeights(weights); // iterate over all the documents for (int ind : batch) { prob += valueForADoc(ind); } if (Double.isNaN(prob)) { // shouldn't be the case throw new RuntimeException("Got NaN for prob in CRFLogConditionalObjectiveFunction.calculate()"); } value = -prob; return value; }
/** * Computes value of function for specified value of x (scaled by xScale) * only over samples indexed by batch. * NOTE: This function does not do regularization (regularization is done by the minimizer). * * @param x - unscaled weights * @param xScale - how much to scale x by when performing calculations * @param batch - indices of which samples to compute function over * @return value of function at specified x (scaled by xScale) for samples */ @Override public double valueAt(double[] x, double xScale, int[] batch) { double prob = 0.0; // the log prob of the sequence given the model, which is the negation of value at this point // int[][] wis = getWeightIndices(); to2D(x, xScale, weights); setWeights(weights); // iterate over all the documents for (int ind : batch) { prob += valueForADoc(ind); } if (Double.isNaN(prob)) { // shouldn't be the case throw new RuntimeException("Got NaN for prob in CRFLogConditionalObjectiveFunction.calculate()"); } value = -prob; return value; }