Logistic implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { public double value(double x) { return value(m - x, k, b, q, a, oneOverN); } Logistic(double k,
                    double m,
                    double b,
                    double q,
                    double a,
                    double n); double value(double x); @Deprecated UnivariateFunction derivative(); DerivativeStructure value(final DerivativeStructure t);  }
@Test public void testCompareSigmoid() { final UnivariateFunction sig = new Sigmoid(); final UnivariateFunction sigL = new Logistic(1, 0, 1, 1, 0, 1); final double min = -2; final double max = 2; final int n = 100; final double delta = (max - min) / n; for (int i = 0; i < n; i++) { final double x = min + i * delta; Assert.assertEquals("x=" + x, sig.value(x), sigL.value(x), EPS); } }
@Test public void testSomeValues() { final double k = 4; final double m = 5; final double b = 2; final double q = 3; final double a = -1; final double n = 2; final UnivariateFunction f = new Logistic(k, m, b, q, a, n); double x; x = m; Assert.assertEquals("x=" + x, a + (k - a) / FastMath.sqrt(1 + q), f.value(x), EPS); x = Double.NEGATIVE_INFINITY; Assert.assertEquals("x=" + x, a, f.value(x), EPS); x = Double.POSITIVE_INFINITY; Assert.assertEquals("x=" + x, k, f.value(x), EPS); }
@Test public void testCompareDerivativeSigmoid() { final double k = 3; final double a = 2; final Logistic f = new Logistic(k, 0, 1, 1, a, 1); final Sigmoid g = new Sigmoid(a, k); final double min = -10; final double max = 10; final double n = 20; final double delta = (max - min) / n; for (int i = 0; i < n; i++) { final DerivativeStructure x = new DerivativeStructure(1, 5, 0, min + i * delta); for (int order = 0; order <= x.getOrder(); ++order) { Assert.assertEquals("x=" + x.getValue(), g.value(x).getPartialDerivative(order), f.value(x).getPartialDerivative(order), 3.0e-15); } } }
@Test(expected=NullArgumentException.class) public void testParametricUsage1() { final Logistic.Parametric g = new Logistic.Parametric(); g.value(0, null); }
@Test(expected=DimensionMismatchException.class) public void testParametricUsage2() { final Logistic.Parametric g = new Logistic.Parametric(); g.value(0, new double[] {0}); }
@Test(expected=NotStrictlyPositiveException.class) public void testParametricUsage5() { final Logistic.Parametric g = new Logistic.Parametric(); g.value(0, new double[] {1, 0, 1, 1, 0 ,0}); }