class LogisticExciteFunctionTest(unittest.TestCase):


  def setUp(self):
    self.fcn = LogisticExciteFunction(xMidpoint=5, minValue=10, maxValue=20, steepness=1)


  def testExcite(self):

    inputs = numpy.array([0, 2, 4, 6, 8, 10])
    original = numpy.zeros(inputs.shape)
    afterExcitation = numpy.copy(original)
    for i in xrange(len(original)):
      afterExcitation[i] = self.fcn.excite(original[i], inputs[i])

    for i in xrange(len(original)-1):
      self.assertGreater(afterExcitation[i+1], original[i])


  def testExciteZeroInputs(self):
    """
    Test saturation with strong inputs
    """
    activation = numpy.array([0, 2, 4, 6, 8])
    original = numpy.copy(activation)
    inputs = 0

    self.fcn.excite(activation, inputs)

    for i in xrange(len(original)):
      self.assertAlmostEqual(activation[i], original[i]+self.fcn._minValue)


  def testExciteFullActivation(self):
    """
    Test saturation with strong inputs
    """
    activation = numpy.array([0, 2, 4, 6, 8])
    expected = numpy.copy(activation) + self.fcn._maxValue
    inputs = 1000000
    self.fcn.excite(activation, inputs)
    npt.assert_allclose(activation, expected)
Exemplo n.º 2
0
# ----------------------------------------------------------------------

from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import numpy
"""
This script plots different activation and decay functions and saves the 
resulting figures to a pdf document "excitation_decay_functions.pdf"
"""
with PdfPages('excitation_decay_functions.pdf') as pdf:

    plt.figure()
    plt.subplot(2, 2, 1)
    from union_temporal_pooling.activation.excite_functions.excite_functions_all import (
        LogisticExciteFunction)
    self = LogisticExciteFunction()
    self.plot()
    plt.xlabel('Predicted Input #')

    from union_temporal_pooling.activation.decay_functions.decay_functions_all import (
        ExponentialDecayFunction)

    plt.subplot(2, 2, 2)
    self = ExponentialDecayFunction(10.0)
    self.plot()
    pdf.savefig()
    plt.close()

    # from union_temporal_pooling.activation.decay_functions.logistic_decay_function import (
    #   LogisticDecayFunction)
 def setUp(self):
   self.fcn = LogisticExciteFunction(xMidpoint=5, minValue=10, maxValue=20, steepness=1)