/* * File: SigmoidFunction.java * Author: Justin Basilico * Course: PO CS 152: Neural Networks * Assignment: Final Project * Updated: 2001.12.18 * Created: 2001.12.04 * * Description: * This file contains the SigmoidFunction class, which implements a sigmoid * activation function. * * Copyright: Justin Basilico (2001). */ /** * SigmoidFunction class * * This class implements an ActivationFunction which is a sigmoid activation * function. The sigmoid function in an input x calculates * * 1 / ( 1 + e^-x ) * * The method for calculating the activation for an unit based on the total * input to the unit is the getUnitActivation(double) method. * * Since there is no internal data in this class, rather than creating new * instances of SigmoidFunctions, you should just use the static * SigmoidFunction.INSTANCE, which is just an instance of the class that can * be used statically for calculating values with this ActivationFunction. * * @author Justin Basilico * @version 2001.12.18 * @see ActivationFunction * @see SigmoidFunction.INSTANCE * @see SigmoidFunction.getUnitActivation(double) */ public class SigmoidFunction extends Object implements ActivationFunction { /** INSTANCE * This is an instance of a SigmoidFunction. Since the SigmoidFunction has * no internal data, only one instance of it needs to exist in memory. * This is it. */ public static SigmoidFunction INSTANCE = new SigmoidFunction(); /** * SigmoidFunction default constructor * * Creates new SigmoidFunction instance. You should probably just use the * SigmodFunction.INSTANCE because it has no internal data. * * @see SigmoidFunction.INSTANCE */ public SigmoidFunction() { } /** * getUnitActivation * * This method takes a double input that is the total input to a unit in a * neural network and returns the double activation value for that unit * from the given input. * * This activation function returns the sigmoid value of the input which * is defined for input x as: * * 1 / ( 1 + e^-x ) * * @param input The value of the input to a unit, as a double. * @return The activation for the unit given the input value, as a double. * @see ActivationFunction.getUnitActivation(double) */ public double getUnitActivation( double input) // Total input to unit. { // Return the sigmoid function applied to the input. return 1 / (1 + Math.exp(-input)); } }