/* Copyright (c) 2005-2007 Joseph Gleason Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Current versions of this and other code can be downloaded at: http://gleason.cc/ */ package cc.glsn.v15.neuralnet; /** * Implementation of the sigmoid function for neural network activation. * * This is a common function to use for neural networks and recommended * if you don't know which one to pick. * * Note: the sigmoid function can only return between 0 and 1. And near the edges of that, * it takes an extreme input to get that. I may be doing something majorly wrong, but I'd recommend * expecting outputs in the area of 0.25 - 0.75. If you are expecting boolean outputs, * I'd do 0.25 = false, 0.75 = true or something like that. If you are expecting floating point output, * I'd map the things you care about to 0.25-0.75 range. This seems to work well for me, but * I'm no expert in neural networks or maths. * *
  • g(x)= 1/(1+e^(-x)) *
  • g'(x) = g(x) * (1 - g(x)) * * @author Joseph Gleason * */ public class SigmoidFunction implements NetFunction { private static final long serialVersionUID = -7019250332354066408L; public double functionG(double x) { return 1.0 / (1.0 + Math.exp(-x)); } public double functionGprime(double x) { //return Math.exp(x)/Math.pow(1.0 + Math.exp(x),2.0); double z=functionG(x); return z*(1-z); } }