#! /usr/bin/env python # def r8_sigmoid ( x ): #*****************************************************************************80 # ## R8_SIGMOID evaluates the sigmoid function. # # Discussion: # # An R8 is a double precision real value. # # The sigmoid function is useful for classification problems in # machine learning. Its value is always between 0 and 1. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 August 2018 # # Author: # # John Burkardt # # Parameters: # # Input, real X, the argument. # # Output, real VALUE, the value. # import numpy as np value = 1.0 / ( 1.0 + np.exp ( - x ) ) return value def r8_sigmoid_test ( ): #*****************************************************************************80 # ## R8_SIGMOID_TEST tests R8_SIGMOID. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 August 2018 # # Author: # # John Burkardt # import numpy as np import platform print ( '' ) print ( 'R8_SIGMOID_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' R8_SIGMOID evaluates the sigmoid function of R8.' ) print ( '' ) print ( ' X R8_SIGMOID(X)' ) print ( '' ) x_test = np.array ( [ -4.0, -2.0, -1.0, -0.5, -0.25, 0.0, 0.25, 0.50, 1.0, 2.0, 4.0 ] ) for i in range ( 0, 11 ): x = x_test[i] value = r8_sigmoid ( x ) print ( ' %10.6g %10.6g' % ( x, value ) ) # # Terminate. # print ( '' ) print ( 'R8_SIGMOID_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8_sigmoid_test ( ) timestamp ( )