/* * File: LinearFunction.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 LinearFunction class, which implements a linear * activation function. * * Copyright: Justin Basilico (2001). */ /** * LinearFunction class * * This class implements an ActivationFunction which is a just a linear * activation function. Given an input x, the function just returns 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 LinearFunctions, you should just use the static * LinearFunction.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 LinearFunction.INSTANCE * @see LinearFunction.getUnitActivation(double) */ public class LinearFunction extends Object implements ActivationFunction { /** INSTANCE * This is an instance of a LinearFunction. Since the LinearFunction has * no internal data, only one instance of it needs to exist in memory. * This is it. */ public static LinearFunction INSTANCE = new LinearFunction(); /** * LinearFunction default constructor * * Creates new LinearFunction. Since there is no internal data, you should * probably use the LinearFunction.INSTANCE instead. * * @see LinearFunction.INSTANCE */ public LinearFunction() { } /** * 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 just returns the input value because it is a * linear function. * * @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 input value. return input; } }