@Test public void testValueAtNonInitialPoint01() throws IOException { RealValueFileEventStream rvfes1 = new RealValueFileEventStream( "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt", StandardCharsets.UTF_8.name()); testDataIndexer.index(rvfes1); NegLogLikelihood objectFunction = new NegLogLikelihood(testDataIndexer); double[] nonInitialPoint = new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; double value = objectFunction.valueAt(nonInitialPoint); double expectedValue = 13.862943611198894; Assert.assertEquals(expectedValue, value, TOLERANCE01); }
public double valueAt(double[] x) { if (x.length != dimension) throw new IllegalArgumentException( "x is invalid, its dimension is not equal to domain dimension."); int ci, oi, ai, vectorIndex, outcome; double predValue, logSumOfExps; double negLogLikelihood = 0; for (ci = 0; ci < numContexts; ci++) { for (oi = 0; oi < numOutcomes; oi++) { tempSums[oi] = 0; for (ai = 0; ai < contexts[ci].length; ai++) { vectorIndex = indexOf(oi, contexts[ci][ai]); predValue = values != null ? values[ci][ai] : 1.0; tempSums[oi] += predValue * x[vectorIndex]; } } logSumOfExps = ArrayMath.logSumOfExps(tempSums); outcome = outcomeList[ci]; negLogLikelihood -= (tempSums[outcome] - logSumOfExps) * numTimesEventsSeen[ci]; } return negLogLikelihood; }
NegLogLikelihood implements Function { public double valueAt(double[] x) { if (x.length != dimension) throw new IllegalArgumentException( "x is invalid, its dimension is not equal to domain dimension."); int ci, oi, ai, vectorIndex, outcome; double predValue, logSumOfExps; double negLogLikelihood = 0; for (ci = 0; ci < numContexts; ci++) { for (oi = 0; oi < numOutcomes; oi++) { tempSums[oi] = 0; for (ai = 0; ai < contexts[ci].length; ai++) { vectorIndex = indexOf(oi, contexts[ci][ai]); predValue = values != null ? values[ci][ai] : 1.0; tempSums[oi] += predValue * x[vectorIndex]; } } logSumOfExps = ArrayMath.logSumOfExps(tempSums); outcome = outcomeList[ci]; negLogLikelihood -= (tempSums[outcome] - logSumOfExps) * numTimesEventsSeen[ci]; } return negLogLikelihood; } }
NegLogLikelihood implements Function { public double valueAt(double[] x) { if (x.length != dimension) throw new IllegalArgumentException( "x is invalid, its dimension is not equal to domain dimension."); int ci, oi, ai, vectorIndex, outcome; double predValue, logSumOfExps; double negLogLikelihood = 0; for (ci = 0; ci < numContexts; ci++) { for (oi = 0; oi < numOutcomes; oi++) { tempSums[oi] = 0; for (ai = 0; ai < contexts[ci].length; ai++) { vectorIndex = indexOf(oi, contexts[ci][ai]); predValue = values != null ? values[ci][ai] : 1.0; tempSums[oi] += predValue * x[vectorIndex]; } } logSumOfExps = ArrayMath.logSumOfExps(tempSums); outcome = outcomeList[ci]; negLogLikelihood -= (tempSums[outcome] - logSumOfExps) * numTimesEventsSeen[ci]; } return negLogLikelihood; } NegLogLikelihood(DataIndexer indexer); }
NegLogLikelihood implements Function { public double valueAt(double[] x) { if (x.length != dimension) throw new IllegalArgumentException( "x is invalid, its dimension is not equal to domain dimension."); int ci, oi, ai, vectorIndex, outcome; double predValue, logSumOfExps; double negLogLikelihood = 0; for (ci = 0; ci < numContexts; ci++) { for (oi = 0; oi < numOutcomes; oi++) { tempSums[oi] = 0; for (ai = 0; ai < contexts[ci].length; ai++) { vectorIndex = indexOf(oi, contexts[ci][ai]); predValue = values != null ? values[ci][ai] : 1.0; tempSums[oi] += predValue * x[vectorIndex]; } } logSumOfExps = ArrayMath.logSumOfExps(tempSums); outcome = outcomeList[ci]; negLogLikelihood -= (tempSums[outcome] - logSumOfExps) * numTimesEventsSeen[ci]; } return negLogLikelihood; } NegLogLikelihood(DataIndexer indexer); int getDimension(); double[] getInitialPoint(); double valueAt(double[] x); double[] gradientAt(double[] x); }
NegLogLikelihood implements Function { public double valueAt(double[] x) { if (x.length != dimension) throw new IllegalArgumentException( "x is invalid, its dimension is not equal to domain dimension."); int ci, oi, ai, vectorIndex, outcome; double predValue, logSumOfExps; double negLogLikelihood = 0; for (ci = 0; ci < numContexts; ci++) { for (oi = 0; oi < numOutcomes; oi++) { tempSums[oi] = 0; for (ai = 0; ai < contexts[ci].length; ai++) { vectorIndex = indexOf(oi, contexts[ci][ai]); predValue = values != null ? values[ci][ai] : 1.0; tempSums[oi] += predValue * x[vectorIndex]; } } logSumOfExps = ArrayMath.logSumOfExps(tempSums); outcome = outcomeList[ci]; negLogLikelihood -= (tempSums[outcome] - logSumOfExps) * numTimesEventsSeen[ci]; } return negLogLikelihood; } NegLogLikelihood(DataIndexer indexer); int getDimension(); double[] getInitialPoint(); double valueAt(double[] x); double[] gradientAt(double[] x);  }