Sigmoid implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { public double value(double x) { return value(x, lo, hi); } Sigmoid();  Sigmoid(double lo,
                   double hi); @Deprecated UnivariateFunction derivative(); double value(double x); DerivativeStructure value(final DerivativeStructure t);  }
@Test public void testSomeValues() { final UnivariateFunction f = new Sigmoid(); Assert.assertEquals(0.5, f.value(0), EPS); Assert.assertEquals(0, f.value(Double.NEGATIVE_INFINITY), EPS); Assert.assertEquals(1, f.value(Double.POSITIVE_INFINITY), EPS); }
@Test public void testDerivativesHighOrder() { DerivativeStructure s = new Sigmoid(1, 3).value(new DerivativeStructure(1, 5, 0, 1.2)); Assert.assertEquals(2.5370495669980352859, s.getPartialDerivative(0), 5.0e-16); Assert.assertEquals(0.35578888129361140441, s.getPartialDerivative(1), 6.0e-17); Assert.assertEquals(-0.19107626464144938116, s.getPartialDerivative(2), 6.0e-17); Assert.assertEquals(-0.02396830286286711696, s.getPartialDerivative(3), 4.0e-17); Assert.assertEquals(0.21682059798981049049, s.getPartialDerivative(4), 3.0e-17); Assert.assertEquals(-0.19186320234632658055, s.getPartialDerivative(5), 2.0e-16); }
@Test public void testDerivativeLargeArguments() { final Sigmoid f = new Sigmoid(1, 2); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, Double.NEGATIVE_INFINITY)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, -Double.MAX_VALUE)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, -1e50)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, -1e3)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, 1e3)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, 1e50)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, Double.MAX_VALUE)).getPartialDerivative(1), 0); Assert.assertEquals(0, f.value(new DerivativeStructure(1, 1, 0, Double.POSITIVE_INFINITY)).getPartialDerivative(1), 0); }
@Test(expected=NullArgumentException.class) public void testParametricUsage1() { final Sigmoid.Parametric g = new Sigmoid.Parametric(); g.value(0, null); }
@Test(expected=DimensionMismatchException.class) public void testParametricUsage2() { final Sigmoid.Parametric g = new Sigmoid.Parametric(); g.value(0, new double[] {0}); }
@Test public void testParametricValue() { final double lo = 2; final double hi = 3; final Sigmoid f = new Sigmoid(lo, hi); final Sigmoid.Parametric g = new Sigmoid.Parametric(); Assert.assertEquals(f.value(-1), g.value(-1, new double[] {lo, hi}), 0); Assert.assertEquals(f.value(0), g.value(0, new double[] {lo, hi}), 0); Assert.assertEquals(f.value(2), g.value(2, new double[] {lo, hi}), 0); }