/** {@inheritDoc} */ public double density(double x) { final double logDensity = logDensity(x); return logDensity == Double.NEGATIVE_INFINITY ? 0 : FastMath.exp(logDensity); }
/** {@inheritDoc} */ public double density(double x) { final double logDensity = logDensity(x); return logDensity == Double.NEGATIVE_INFINITY ? 0 : Math.exp(logDensity); }
/** {@inheritDoc} */ public double density(double x) { final double logDensity = logDensity(x); return logDensity == Double.NEGATIVE_INFINITY ? 0 : FastMath.exp(logDensity); }
@Test public void logProbMatchesKnownLogDensityOfVector() { ExponentialDistribution distribution = new ExponentialDistribution(1.0); double expectedLogDensity = distribution.logDensity(0.25) + distribution.logDensity(.75); ExponentialVertex ndExponentialVertex = new ExponentialVertex(1); ProbabilisticDoubleTensorContract.matchesKnownLogDensityOfVector(ndExponentialVertex, new double[]{0.25, .75}, expectedLogDensity); }
@Test public void logProbMatchesKnownLogDensityOfScalar() { ExponentialDistribution distribution = new ExponentialDistribution(1.5); ExponentialVertex tensorExponentialVertex = new ExponentialVertex(1.5); double expectedDensity = distribution.logDensity(2.0); ProbabilisticDoubleTensorContract.matchesKnownLogDensityOfScalar(tensorExponentialVertex, 2.0, expectedDensity); }
@Test public void logProbGraphMatchesKnownLogDensityOfVector() { DoubleVertex rate = ConstantVertex.of(1.0, 1.0); ExponentialVertex tensorExponentialVertex = new ExponentialVertex(rate); LogProbGraph logProbGraph = tensorExponentialVertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, rate, rate.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, tensorExponentialVertex, DoubleTensor.create(0.25, 0.75)); ExponentialDistribution distribution = new ExponentialDistribution(1.0); double expectedDensity = distribution.logDensity(0.25) + distribution.logDensity(0.75); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedDensity); }
@Test public void logProbGraphMatchesKnownLogDensityOfScalar() { DoubleVertex rate = ConstantVertex.of(1.5); ExponentialVertex tensorExponentialVertex = new ExponentialVertex(rate); LogProbGraph logProbGraph = tensorExponentialVertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, rate, rate.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, tensorExponentialVertex, DoubleTensor.scalar(2.0)); ExponentialDistribution distribution = new ExponentialDistribution(1.5); double expectedDensity = distribution.logDensity(2.0); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedDensity); }