diff --git a/src/test/java/com/syncleus/grail/neural/activation/GausianActivationFunctionTest.java b/src/test/java/com/syncleus/grail/neural/activation/GausianActivationFunctionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0c24414ae73e869763ef1465b0892c571b2d8b2d --- /dev/null +++ b/src/test/java/com/syncleus/grail/neural/activation/GausianActivationFunctionTest.java @@ -0,0 +1,86 @@ +/****************************************************************************** + * * + * Copyright: (c) Syncleus, Inc. * + * * + * You may redistribute and modify this source code under the terms and * + * conditions of the Open Source Community License - Type C version 1.0 * + * or any later version as published by Syncleus, Inc. at www.syncleus.com. * + * There should be a copy of the license included with this file. If a copy * + * of the license is not included you are granted no right to distribute or * + * otherwise use this file except through a legal and valid license. You * + * should also contact Syncleus, Inc. at the information below if you cannot * + * find a license: * + * * + * Syncleus, Inc. * + * 2604 South 12th Street * + * Philadelphia, PA 19148 * + * * + ******************************************************************************/ +package com.syncleus.grail.neural.activation; + +import junit.framework.Assert; +import org.junit.Test; + +public class GausianActivationFunctionTest { + private final static ActivationFunction ACTIVATION_FUNCTION = new GausianActivationFunction(); + private final static double[][] ACTIVATION_TRUTH_TABLE = new double[][]{ + {0.0, 1.0}, + {0.25, 0.9394130628134758}, + {1.0, 0.36787944117144233}, + {10.0, scientific(3.7200759760208555, -44.0)}, + {1000000.0, 0.0}, + {-0.25, 0.9394130628134758}, + {-1.0, 0.36787944117144233}, + {-10.0, scientific(3.7200759760208555, -44.0)}, + {-1000000.0, 0.0} }; + private final static double[][] DERIVATIVE_TRUTH_TABLE = new double[][]{ + {0.0, -0.0}, + {0.25, -0.20399095470386272}, + {1.0, -0.3195360226128187}, + {10.0, scientific(-3.231216937293423, -43)}, + {1000000.0, -0.0}, + {-0.25, 0.20399095470386272}, + {-1.0, 0.3195360226128187}, + {-10.0, scientific(-3.231216937293423, -43)}, + {-1000000.0, 0.0} }; + private final static boolean IS_BOUND = true; + private final static double UPPER_LIMIT = 1.0; + private final static double LOWER_LIMIT = 0.0; + + @Test + public void testActivation() { + for( int index = 0; index < ACTIVATION_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activate(ACTIVATION_TRUTH_TABLE[index][0]), ACTIVATION_TRUTH_TABLE[index][1])); + } + + @Test + public void testDerivative() { + for( int index = 0; index < DERIVATIVE_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activateDerivative(DERIVATIVE_TRUTH_TABLE[index][0]), DERIVATIVE_TRUTH_TABLE[index][1])); + } + + @Test + public void testIsBound() { + Assert.assertTrue(ACTIVATION_FUNCTION.isBound() == IS_BOUND); + } + + @Test + public void testUpperLimit() { + final double upperLimit = ACTIVATION_FUNCTION.getUpperLimit(); + Assert.assertTrue( checkResult(upperLimit, UPPER_LIMIT)); + } + + @Test + public void testLowerLimit() { + final double lowerLimit = ACTIVATION_FUNCTION.getLowerLimit(); + Assert.assertTrue( checkResult(lowerLimit, LOWER_LIMIT)); + } + + private static boolean checkResult(final double firstValue, final double secondValue) { + return (Math.abs(firstValue - secondValue) < 0.0000001); + } + + private static double scientific(final double value, final double exponent) { + return value * Math.pow(10.0, exponent); + } +} diff --git a/src/test/java/com/syncleus/grail/neural/activation/HyperbolicSecantActivationFunctionTest.java b/src/test/java/com/syncleus/grail/neural/activation/HyperbolicSecantActivationFunctionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..57ac3013ffc617a649f80c4604b8b99b782fb1d0 --- /dev/null +++ b/src/test/java/com/syncleus/grail/neural/activation/HyperbolicSecantActivationFunctionTest.java @@ -0,0 +1,82 @@ +/****************************************************************************** + * * + * Copyright: (c) Syncleus, Inc. * + * * + * You may redistribute and modify this source code under the terms and * + * conditions of the Open Source Community License - Type C version 1.0 * + * or any later version as published by Syncleus, Inc. at www.syncleus.com. * + * There should be a copy of the license included with this file. If a copy * + * of the license is not included you are granted no right to distribute or * + * otherwise use this file except through a legal and valid license. You * + * should also contact Syncleus, Inc. at the information below if you cannot * + * find a license: * + * * + * Syncleus, Inc. * + * 2604 South 12th Street * + * Philadelphia, PA 19148 * + * * + ******************************************************************************/ +package com.syncleus.grail.neural.activation; + +import junit.framework.Assert; +import org.junit.Test; + +public class HyperbolicSecantActivationFunctionTest { + private final static ActivationFunction ACTIVATION_FUNCTION = new HyperbolicSecantActivationFunction(); + private final static double[][] ACTIVATION_TRUTH_TABLE = new double[][]{ + {0.0, 1.0}, + {0.25, 0.9695436291402145}, + {1.0, 0.6480542736638853}, + {10.0, 0.00009079985933781724}, + {1000000.0, 0.0}, + {-0.25, 0.9695436291402145}, + {-1.0, 0.6480542736638853}, + {-10.0, 0.00009079985933781724}, + {-1000000.0, 0.0} }; + private final static double[][] DERIVATIVE_TRUTH_TABLE = new double[][]{ + {0.0, -0.0}, + {0.25, -0.23745932879105916}, + {1.0, -0.493554347564573}, + {10.0, -0.00009079985896351232}, + {1000000.0, -0.0}, + {-0.25, 0.23745932879105916}, + {-1.0, 0.493554347564573}, + {-10.0, 0.00009079985896351232}, + {-1000000.0, 0.0} }; + private final static boolean IS_BOUND = true; + private final static double UPPER_LIMIT = 1.0; + private final static double LOWER_LIMIT = 0.0; + + @Test + public void testActivation() { + for( int index = 0; index < ACTIVATION_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activate(ACTIVATION_TRUTH_TABLE[index][0]), ACTIVATION_TRUTH_TABLE[index][1])); + } + + @Test + public void testDerivative() { + for( int index = 0; index < DERIVATIVE_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activateDerivative(DERIVATIVE_TRUTH_TABLE[index][0]), DERIVATIVE_TRUTH_TABLE[index][1])); + } + + @Test + public void testIsBound() { + Assert.assertTrue(ACTIVATION_FUNCTION.isBound() == IS_BOUND); + } + + @Test + public void testUpperLimit() { + final double upperLimit = ACTIVATION_FUNCTION.getUpperLimit(); + Assert.assertTrue( checkResult(upperLimit, UPPER_LIMIT)); + } + + @Test + public void testLowerLimit() { + final double lowerLimit = ACTIVATION_FUNCTION.getLowerLimit(); + Assert.assertTrue( checkResult(lowerLimit, LOWER_LIMIT)); + } + + private static boolean checkResult(final double firstValue, final double secondValue) { + return (Math.abs(firstValue - secondValue) < 0.0000001); + } +} diff --git a/src/test/java/com/syncleus/grail/neural/activation/HyperbolicTangentActivationFunctionTest.java b/src/test/java/com/syncleus/grail/neural/activation/HyperbolicTangentActivationFunctionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9e533a12caad6415691ef0ca66e3e68f9c46042b --- /dev/null +++ b/src/test/java/com/syncleus/grail/neural/activation/HyperbolicTangentActivationFunctionTest.java @@ -0,0 +1,82 @@ +/****************************************************************************** + * * + * Copyright: (c) Syncleus, Inc. * + * * + * You may redistribute and modify this source code under the terms and * + * conditions of the Open Source Community License - Type C version 1.0 * + * or any later version as published by Syncleus, Inc. at www.syncleus.com. * + * There should be a copy of the license included with this file. If a copy * + * of the license is not included you are granted no right to distribute or * + * otherwise use this file except through a legal and valid license. You * + * should also contact Syncleus, Inc. at the information below if you cannot * + * find a license: * + * * + * Syncleus, Inc. * + * 2604 South 12th Street * + * Philadelphia, PA 19148 * + * * + ******************************************************************************/ +package com.syncleus.grail.neural.activation; + +import junit.framework.Assert; +import org.junit.Test; + +public class HyperbolicTangentActivationFunctionTest { + private final static ActivationFunction ACTIVATION_FUNCTION = new HyperbolicTangentActivationFunction(); + private final static double[][] ACTIVATION_TRUTH_TABLE = new double[][]{ + {0.0, 0.0}, + {0.25, 0.24491866240370913}, + {1.0, 0.7615941559557649}, + {10.0, 0.9999999958776927}, + {1000000.0, 1.0}, + {-0.25, -0.24491866240370913}, + {-1.0, -0.7615941559557649}, + {-10.0, -0.9999999958776927}, + {-1000000.0, -1.0} }; + private final static double[][] DERIVATIVE_TRUTH_TABLE = new double[][]{ + {0.0, 1.0}, + {0.25, 0.940014848806378}, + {1.0, 0.41997434161402614}, + {10.0, 0.000000008244614546626394}, + {1000000.0, 0.0}, + {-0.25, 0.940014848806378}, + {-1.0, 0.41997434161402614}, + {-10.0, 0.000000008244614546626394}, + {-1000000.0, 0.0} }; + private final static boolean IS_BOUND = true; + private final static double UPPER_LIMIT = 1.0; + private final static double LOWER_LIMIT = -1.0; + + @Test + public void testActivation() { + for( int index = 0; index < ACTIVATION_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activate(ACTIVATION_TRUTH_TABLE[index][0]), ACTIVATION_TRUTH_TABLE[index][1])); + } + + @Test + public void testDerivative() { + for( int index = 0; index < DERIVATIVE_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activateDerivative(DERIVATIVE_TRUTH_TABLE[index][0]), DERIVATIVE_TRUTH_TABLE[index][1])); + } + + @Test + public void testIsBound() { + Assert.assertTrue(ACTIVATION_FUNCTION.isBound() == IS_BOUND); + } + + @Test + public void testUpperLimit() { + final double upperLimit = ACTIVATION_FUNCTION.getUpperLimit(); + Assert.assertTrue( checkResult(upperLimit, UPPER_LIMIT)); + } + + @Test + public void testLowerLimit() { + final double lowerLimit = ACTIVATION_FUNCTION.getLowerLimit(); + Assert.assertTrue( checkResult(lowerLimit, LOWER_LIMIT)); + } + + private static boolean checkResult(final double firstValue, final double secondValue) { + return (Math.abs(firstValue - secondValue) < 0.0000001); + } +} diff --git a/src/test/java/com/syncleus/grail/neural/activation/IdentityActivationFunctionTest.java b/src/test/java/com/syncleus/grail/neural/activation/IdentityActivationFunctionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b63d146a309321d7286857fa68d8045b0426a127 --- /dev/null +++ b/src/test/java/com/syncleus/grail/neural/activation/IdentityActivationFunctionTest.java @@ -0,0 +1,82 @@ +/****************************************************************************** + * * + * Copyright: (c) Syncleus, Inc. * + * * + * You may redistribute and modify this source code under the terms and * + * conditions of the Open Source Community License - Type C version 1.0 * + * or any later version as published by Syncleus, Inc. at www.syncleus.com. * + * There should be a copy of the license included with this file. If a copy * + * of the license is not included you are granted no right to distribute or * + * otherwise use this file except through a legal and valid license. You * + * should also contact Syncleus, Inc. at the information below if you cannot * + * find a license: * + * * + * Syncleus, Inc. * + * 2604 South 12th Street * + * Philadelphia, PA 19148 * + * * + ******************************************************************************/ +package com.syncleus.grail.neural.activation; + +import junit.framework.Assert; +import org.junit.Test; + +public class IdentityActivationFunctionTest { + private final static ActivationFunction ACTIVATION_FUNCTION = new IdentityActivationFunction(); + private final static double[][] ACTIVATION_TRUTH_TABLE = new double[][]{ {0.0, 0.0}, + {0.25, 0.25}, + {1.0, 1.0}, + {10.0, 10.0}, + {1000000.0, 1000000.0}, + {-0.25, -0.25}, + {-1.0, -1.0}, + {-10.0, -10.0}, + {-1000000.0, -1000000.0} }; + private final static double[][] DERIVATIVE_TRUTH_TABLE = new double[][]{ {0.0, 1.0}, + {0.25, 1.0}, + {1.0, 1.0}, + {10.0, 1.0}, + {1000000.0, 1.0}, + {-0.25, 1.0}, + {-1.0, 1.0}, + {-10.0, 1.0}, + {-1000000.0, 1.0} }; + private final static boolean IS_BOUND = false; + private final static double UPPER_LIMIT = Double.MAX_VALUE; + private final static double LOWER_LIMIT = -1.0 * Double.MAX_VALUE; + + @Test + public void testActivation() { + for( int index = 0; index < ACTIVATION_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(IdentityActivationFunctionTest.checkResult(ACTIVATION_FUNCTION.activate(ACTIVATION_TRUTH_TABLE[index][0]), ACTIVATION_TRUTH_TABLE[index][1])); + } + + @Test + public void testDerivative() { + for( int index = 0; index < DERIVATIVE_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(IdentityActivationFunctionTest.checkResult(ACTIVATION_FUNCTION.activateDerivative(DERIVATIVE_TRUTH_TABLE[index][0]), DERIVATIVE_TRUTH_TABLE[index][1])); + } + + @Test + public void testIsBound() { + Assert.assertTrue(ACTIVATION_FUNCTION.isBound() == IS_BOUND); + } + + @Test + public void testUpperLimit() { + final double upperLimit = ACTIVATION_FUNCTION.getUpperLimit(); + Assert.assertTrue( upperLimit > 1.0 ); + Assert.assertTrue( IdentityActivationFunctionTest.checkResult(upperLimit, UPPER_LIMIT)); + } + + @Test + public void testLowerLimit() { + final double lowerLimit = ACTIVATION_FUNCTION.getLowerLimit(); + Assert.assertTrue( lowerLimit < -1.0 ); + Assert.assertTrue( IdentityActivationFunctionTest.checkResult(lowerLimit, LOWER_LIMIT)); + } + + private static boolean checkResult(final double firstValue, final double secondValue) { + return (Math.abs(firstValue - secondValue) < 0.0000001); + } +} diff --git a/src/test/java/com/syncleus/grail/neural/activation/SineActivationFunctionTest.java b/src/test/java/com/syncleus/grail/neural/activation/SineActivationFunctionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e2d9a8e7047a33ae4f15e4201692eccaf23b5548 --- /dev/null +++ b/src/test/java/com/syncleus/grail/neural/activation/SineActivationFunctionTest.java @@ -0,0 +1,82 @@ +/****************************************************************************** + * * + * Copyright: (c) Syncleus, Inc. * + * * + * You may redistribute and modify this source code under the terms and * + * conditions of the Open Source Community License - Type C version 1.0 * + * or any later version as published by Syncleus, Inc. at www.syncleus.com. * + * There should be a copy of the license included with this file. If a copy * + * of the license is not included you are granted no right to distribute or * + * otherwise use this file except through a legal and valid license. You * + * should also contact Syncleus, Inc. at the information below if you cannot * + * find a license: * + * * + * Syncleus, Inc. * + * 2604 South 12th Street * + * Philadelphia, PA 19148 * + * * + ******************************************************************************/ +package com.syncleus.grail.neural.activation; + +import junit.framework.Assert; +import org.junit.Test; + +public class SineActivationFunctionTest { + private final static ActivationFunction ACTIVATION_FUNCTION = new SineActivationFunction(); + private final static double[][] ACTIVATION_TRUTH_TABLE = new double[][]{ + {0.0, 0.0}, + {0.25, 0.24740395925452294}, + {1.0, 0.8414709848078965}, + {10.0, -0.5440211108893698}, + {1000000.0, -0.34999350217129294}, + {-0.25, -0.24740395925452294}, + {-1.0, -0.8414709848078965}, + {-10.0, 0.5440211108893698}, + {-1000000.0, 0.34999350217129294} }; + private final static double[][] DERIVATIVE_TRUTH_TABLE = new double[][]{ + {0.0, 1.0}, + {0.25, 0.9689124217106447}, + {1.0, 0.5403023058681398}, + {10.0, -0.8390715290764524}, + {1000000.0, 0.9367521275331447}, + {-0.25, 0.9689124217106447}, + {-1.0, 0.5403023058681398}, + {-10.0, -0.8390715290764524}, + {-1000000.0, 0.9367521275331447} }; + private final static boolean IS_BOUND = true; + private final static double UPPER_LIMIT = 1.0; + private final static double LOWER_LIMIT = -1.0; + + @Test + public void testActivation() { + for( int index = 0; index < ACTIVATION_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activate(ACTIVATION_TRUTH_TABLE[index][0]), ACTIVATION_TRUTH_TABLE[index][1])); + } + + @Test + public void testDerivative() { + for( int index = 0; index < DERIVATIVE_TRUTH_TABLE.length ; index++ ) + Assert.assertTrue(checkResult(ACTIVATION_FUNCTION.activateDerivative(DERIVATIVE_TRUTH_TABLE[index][0]), DERIVATIVE_TRUTH_TABLE[index][1])); + } + + @Test + public void testIsBound() { + Assert.assertTrue(ACTIVATION_FUNCTION.isBound() == IS_BOUND); + } + + @Test + public void testUpperLimit() { + final double upperLimit = ACTIVATION_FUNCTION.getUpperLimit(); + Assert.assertTrue( checkResult(upperLimit, UPPER_LIMIT)); + } + + @Test + public void testLowerLimit() { + final double lowerLimit = ACTIVATION_FUNCTION.getLowerLimit(); + Assert.assertTrue( checkResult(lowerLimit, LOWER_LIMIT)); + } + + private static boolean checkResult(final double firstValue, final double secondValue) { + return (Math.abs(firstValue - secondValue) < 0.0000001); + } +}