ActivationFunctions { public static final float tanhPrime(final float y) { return (1-y*y); } private  ActivationFunctions(); static final float calc(final ActivationType type, final float x); static final float prime(ActivationType type, float y); static final float sigmoid(final float x); static final float sigmoidPrime(final float y); static final float tanh(final float x); static final float tanhPrime(final float y); static final float relu(final float x); static final float reluPrime(final float y); static final float linear(final float x); static final float linearPrime(final float y);  }
@Test public void testTanhPrime() { float[] x = {-0.999998f, -0.999998f, -0.999997f, -0.999997f, -0.999996f, -0.999995f, -0.999994f, -0.999993f, -0.999992f, -0.99999f, -0.999988f, -0.999985f, -0.999982f, -0.999978f, -0.999973f, -0.999967f, -0.999959f, -0.99995f, -0.999939f, -0.999926f, -0.999909f, -0.999889f, -0.999865f, -0.999835f, -0.999798f, -0.999753f, -0.999699f, -0.999632f, -0.99955f, -0.999451f, -0.999329f, -0.999181f, -0.999f, -0.998778f, -0.998508f, -0.998178f, -0.997775f, -0.997283f, -0.996682f, -0.995949f, -0.995055f, -0.993963f, -0.992631f, -0.991007f, -0.989027f, -0.986614f, -0.983675f, -0.980096f, -0.975743f, -0.970452f, -0.964028f, -0.956237f, -0.946806f, -0.935409f, -0.921669f, -0.905148f, -0.885352f, -0.861723f, -0.833655f, -0.800499f, -0.761594f, -0.716298f, -0.664037f, -0.604368f, -0.53705f, -0.462117f, -0.379949f, -0.291313f, -0.197375f, -0.099668f, -2.4869e-14f, 0.099668f, 0.197375f, 0.291313f, 0.379949f, 0.462117f, 0.53705f, 0.604368f, 0.664037f, 0.716298f, 0.761594f, 0.800499f, 0.833655f, 0.861723f, 0.885352f, 0.905148f, 0.921669f, 0.935409f, 0.946806f, 0.956237f, 0.964028f, 0.970452f, 0.975743f, 0.980096f, 0.983675f, 0.986614f, 0.989027f, 0.991007f, 0.992631f, 0.993963f, 0.995055f, 0.995949f, 0.996682f, 0.997283f, 0.997775f, 0.998178f, 0.998508f, 0.998778f, 0.999f, 0.999181f, 0.999329f, 0.999451f, 0.99955f, 0.999632f, 0.999699f, 0.999753f, 0.999798f, 0.999835f, 0.999865f, 0.999889f, 0.999909f, 0.999926f, 0.999939f, 0.99995f, 0.999959f, 0.999967f, 0.999973f, 0.999978f, 0.999982f, 0.999985f, 0.999988f, 0.99999f, 0.999992f, 0.999993f, 0.999994f, 0.999995f, 0.999996f, 0.999997f, 0.999997f, 0.999998f, 0.999998f}; float[] y = {3.32611e-06f, 4.06252e-06f, 4.96197e-06f, 6.06056e-06f, 7.40238e-06f, 9.04128e-06f, 1.1043e-05f, 1.3488e-05f, 1.64742e-05f, 2.01216e-05f, 2.45765e-05f, 3.00178e-05f, 3.66637e-05f, 4.47809e-05f, 5.46953e-05f, 6.68046e-05f, 8.15947e-05f, 9.96591e-05f, 0.000121723f, 0.00014867f, 0.000181583f, 0.000221782f, 0.000270878f, 0.000330842f, 0.000404076f, 0.000493517f, 0.000602751f, 0.000736152f, 0.000899065f, 0.00109801f, 0.00134095f, 0.0016376f, 0.0019998f, 0.00244202f, 0.00298189f, 0.00364088f, 0.00444519f, 0.0054267f, 0.0066242f, 0.00808487f, 0.00986604f, 0.0120372f, 0.0146827f, 0.0179042f, 0.0218248f, 0.0265922f, 0.0323838f, 0.0394111f, 0.0479253f, 0.058223f, 0.0706508f, 0.0856099f, 0.103558f, 0.12501f, 0.150527f, 0.180707f, 0.216152f, 0.257433f, 0.30502f, 0.359201f, 0.419974f, 0.486917f, 0.559055f, 0.63474f, 0.711578f, 0.786448f, 0.855639f, 0.915137f, 0.961043f, 0.990066f, 1.0f, 0.990066f, 0.961043f, 0.915137f, 0.855639f, 0.786448f, 0.711578f, 0.63474f, 0.559055f, 0.486917f, 0.419974f, 0.359201f, 0.30502f, 0.257433f, 0.216152f, 0.180707f, 0.150527f, 0.12501f, 0.103558f, 0.0856099f, 0.0706508f, 0.058223f, 0.0479253f, 0.0394111f, 0.0323838f, 0.0265922f, 0.0218248f, 0.0179042f, 0.0146827f, 0.0120372f, 0.00986604f, 0.00808487f, 0.0066242f, 0.0054267f, 0.00444519f, 0.00364088f, 0.00298189f, 0.00244202f, 0.0019998f, 0.0016376f, 0.00134095f, 0.00109801f, 0.000899065f, 0.000736152f, 0.000602751f, 0.000493517f, 0.000404076f, 0.000330842f, 0.000270878f, 0.000221782f, 0.000181583f, 0.00014867f, 0.000121723f, 9.96591e-05f, 8.15947e-05f, 6.68046e-05f, 5.46953e-05f, 4.47809e-05f, 3.66637e-05f, 3.00178e-05f, 2.45765e-05f, 2.01216e-05f, 1.64742e-05f, 1.3488e-05f, 1.1043e-05f, 9.04128e-06f, 7.40238e-06f, 6.06056e-06f, 4.96197e-06f, 4.06252e-06f, 3.32611e-06f}; for (int i = 0; i < x.length; i++) { float expResult = y[i]; float result = ActivationFunctions.tanhPrime(x[i]); assertEquals(expResult, result, 1e-6); } }