/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0, throws a RuntimeException. * If the total is Double.NEGATIVE_INFINITY, then it replaces the * array with a normalized uniform distribution. CDM: This last bit is * weird! Do we really want that? */ public static void logNormalize(double[] a) { double logTotal = logSum(a); if (logTotal == Double.NEGATIVE_INFINITY) { // to avoid NaN values double v = -Math.log(a.length); for (int i = 0; i < a.length; i++) { a[i] = v; } return; } addInPlace(a, -logTotal); // subtract log total from each value }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Merge the given {@code Cost} data with the data in this * instance. * * @param otherCost */ public void merge(Cost otherCost) { this.cost += otherCost.getCost(); this.percentCorrect += otherCost.getPercentCorrect(); ArrayMath.addInPlace(gradW1, otherCost.getGradW1()); ArrayMath.pairwiseAddInPlace(gradb1, otherCost.getGradb1()); ArrayMath.addInPlace(gradW2, otherCost.getGradW2()); ArrayMath.addInPlace(gradE, otherCost.getGradE()); }
private double[] getApproximateScores(History h) { String[] tags = stringTagsAt(h.current - h.start + leftWindow()); double[] scores = getHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: int nDefault = maxentTagger.ySize - tags.length; double logScore = ArrayMath.logSum(scores); double logScoreInactiveTags = maxentTagger.getInactiveTagDefaultScore(nDefault); double logTotal = SloppyMath.logAdd(logScore, logScoreInactiveTags); ArrayMath.addInPlace(scores, -logTotal); return scores; }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0, throws a RuntimeException. * If the total is Double.NEGATIVE_INFINITY, then it replaces the * array with a normalized uniform distribution. CDM: This last bit is * weird! Do we really want that? */ public static void logNormalize(double[] a) { double logTotal = logSum(a); if (logTotal == Double.NEGATIVE_INFINITY) { // to avoid NaN values double v = -Math.log(a.length); for (int i = 0; i < a.length; i++) { a[i] = v; } return; } addInPlace(a, -logTotal); // subtract log total from each value }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0, throws a RuntimeException. * If the total is Double.NEGATIVE_INFINITY, then it replaces the * array with a normalized uniform distribution. CDM: This last bit is * weird! Do we really want that? */ public static void logNormalize(double[] a) { double logTotal = logSum(a); if (logTotal == Double.NEGATIVE_INFINITY) { // to avoid NaN values double v = -Math.log(a.length); for (int i = 0; i < a.length; i++) { a[i] = v; } return; } addInPlace(a, -logTotal); // subtract log total from each value }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0, throws a RuntimeException. * If the total is Double.NEGATIVE_INFINITY, then it replaces the * array with a normalized uniform distribution. CDM: This last bit is * weird! Do we really want that? */ public static void logNormalize(double[] a) { double logTotal = logSum(a); if (logTotal == Double.NEGATIVE_INFINITY) { // to avoid NaN values double v = -Math.log(a.length); for (int i = 0; i < a.length; i++) { a[i] = v; } return; } addInPlace(a, -logTotal); // subtract log total from each value }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0, throws a RuntimeException. * If the total is Double.NEGATIVE_INFINITY, then it replaces the * array with a normalized uniform distribution. CDM: This last bit is * weird! Do we really want that? */ public static void logNormalize(double[] a) { double logTotal = logSum(a); if (logTotal == Double.NEGATIVE_INFINITY) { // to avoid NaN values double v = -Math.log(a.length); for (int i = 0; i < a.length; i++) { a[i] = v; } return; } addInPlace(a, -logTotal); // subtract log total from each value }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws an RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) throw new RuntimeException("Can't standardize array whose mean is NaN"); double s = stdev(a); if(s == 0.0 || Double.isNaN(s)) throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Merge the given {@code Cost} data with the data in this * instance. * * @param otherCost */ public void merge(Cost otherCost) { this.cost += otherCost.getCost(); this.percentCorrect += otherCost.getPercentCorrect(); ArrayMath.addInPlace(gradW1, otherCost.getGradW1()); ArrayMath.pairwiseAddInPlace(gradb1, otherCost.getGradb1()); ArrayMath.addInPlace(gradW2, otherCost.getGradW2()); ArrayMath.addInPlace(gradE, otherCost.getGradE()); }
/** * Merge the given {@code Cost} data with the data in this * instance. * * @param otherCost */ public void merge(Cost otherCost) { this.cost += otherCost.getCost(); this.percentCorrect += otherCost.getPercentCorrect(); ArrayMath.addInPlace(gradW1, otherCost.getGradW1()); ArrayMath.pairwiseAddInPlace(gradb1, otherCost.getGradb1()); ArrayMath.addInPlace(gradW2, otherCost.getGradW2()); ArrayMath.addInPlace(gradE, otherCost.getGradE()); }
private double[] getApproximateScores(History h) { String[] tags = stringTagsAt(h.current - h.start + leftWindow()); double[] scores = getHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: double nDefault = maxentTagger.ySize - tags.length; double logScore = ArrayMath.logSum(scores); double logScoreInactiveTags = Math.log(nDefault*maxentTagger.defaultScore); double logTotal = ArrayMath.logSum(new double[] {logScore, logScoreInactiveTags}); ArrayMath.addInPlace(scores, -logTotal); return scores; }
private double[] getApproximateScores(History h) { String[] tags = stringTagsAt(h.current - h.start + leftWindow()); double[] scores = getHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: int nDefault = maxentTagger.ySize - tags.length; double logScore = ArrayMath.logSum(scores); double logScoreInactiveTags = maxentTagger.getInactiveTagDefaultScore(nDefault); double logTotal = SloppyMath.logAdd(logScore, logScoreInactiveTags); ArrayMath.addInPlace(scores, -logTotal); return scores; }
private double[] getApproximateScores(History h) { String[] tags = stringTagsAt(h.current - h.start + leftWindow()); double[] scores = getHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: int nDefault = maxentTagger.ySize - tags.length; double logScore = ArrayMath.logSum(scores); double logScoreInactiveTags = maxentTagger.getInactiveTagDefaultScore(nDefault); double logTotal = SloppyMath.logAdd(logScore, logScoreInactiveTags); ArrayMath.addInPlace(scores, -logTotal); return scores; }
private double[] getApproximateScores(History h) { String[] tags = stringTagsAt(h.current - h.start + leftWindow()); double[] scores = getHistories(tags, h); // log score for each active tag, unnormalized // Number of tags that get assigned a default score: int nDefault = maxentTagger.ySize - tags.length; double logScore = ArrayMath.logSum(scores); double logScoreInactiveTags = maxentTagger.getInactiveTagDefaultScore(nDefault); double logTotal = SloppyMath.logAdd(logScore, logScoreInactiveTags); ArrayMath.addInPlace(scores, -logTotal); return scores; }