Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Neural Networks on C#

, 19 Nov 2006 GPL3
The articles describes a C# library for neural network computations, and their application for several problem solving.
neuro_demo.zip
neuro_demo
Back Propagation
Approximation
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Approximation.exe
Data Samples
sample1.csv
sample2.csv
TimeSeries
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
TimeSeries.exe
XORProblem
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
XORProblem.exe
Simple
Delta Rule Learning
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
and.csv
cube.csv
or.csv
sample1.csv
sample2.csv
One-Layer Perceptron Classifier
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
sample1.csv
sample2.csv
Perceptron Classifier
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Classifier.exe
Data Samples
and.csv
cube.csv
or.csv
SOM
2DOrganizing
2DOrganizing.exe
AForge.dll
AForge.Neuro.dll
Color
AForge.dll
AForge.Neuro.dll
Color.exe
TSP
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
TSP.exe
neuro_src.zip
neuro_src
Docs
AForge.Core.chm
AForge.Neuro.chm
Release
AForge.Controls.dll
AForge.dll
AForge.Neuro.dll
Samples
Neuro
Back Propagation
Approximation
App.ico
Data Samples
sample1.csv
sample2.csv
TimeSeries
App.ico
Data Samples
exponent.csv
growing sinusoid.csv
parabola.csv
sigmoid.csv
sinusoid.csv
XORProblem
App.ico
Simple
Delta Rule Learning
App.ico
Data Samples
and.csv
cube.csv
or.csv
sample1.csv
sample2.csv
One-Layer Perceptron Classifier
App.ico
Data Samples
sample1.csv
sample2.csv
Perceptron Classifier
App.ico
Data Samples
and.csv
cube.csv
or.csv
SOM
2DOrganizing
App.ico
Color
App.ico
TSP
App.ico
Sources
Controls
Core
Neuro
Activation Functions
Images
sigmoid.bmp
sigmoid_bipolar.bmp
threshold.bmp
Layers
Learning
Networks
Neurons
// AForge Neural Net Library
//
// Copyright � Andrew Kirillov, 2005-2006
// andrew.kirillov@gmail.com
//

namespace AForge.Neuro
{
	using System;

	/// <summary>
	/// Sigmoid activation function
	/// </summary>
	///
	/// <remarks>The class represents sigmoid activation function with
	/// the next expression:<br />
	/// <code>
	///                1
	/// f(x) = ------------------
	///        1 + exp(-alpha * x)
	///
	///           alpha * exp(-alpha * x )
	/// f'(x) = ---------------------------- = alpha * f(x) * (1 - f(x))
	///           (1 + exp(-alpha * x))^2
	/// </code>
	/// Output range of the function: <b>[0, 1]</b><br /><br />
	/// Functions graph:<br />
	/// <img src="sigmoid.bmp" width="242" height="172" />
	/// </remarks>
	public class SigmoidFunction : IActivationFunction
	{
		// sigmoid's alpha value
		private double alpha = 2;

		/// <summary>
		/// Sigmoid's alpha value
		/// </summary>
		/// 
		/// <remarks>The value determines steepness of the function. Default value: <b>2</b>.
		/// </remarks>
		public double Alpha
		{
			get { return alpha; }
			set { alpha = value; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="SigmoidFunction"/> class
		/// </summary>
		public SigmoidFunction( ) { }

		/// <summary>
		/// Initializes a new instance of the <see cref="SigmoidFunction"/> class
		/// </summary>
		/// 
		/// <param name="alpha">Sigmoid's alpha value</param>
		public SigmoidFunction( double alpha )
		{
			this.alpha = alpha;
		}


		/// <summary>
		/// Calculates function value
		/// </summary>
		///
		/// <param name="x">Function input value</param>
		/// 
		/// <returns>Function output value, <i>f(x)</i></returns>
		///
		/// <remarks>The method calculates function value at point <b>x</b>.</remarks>
		///
		public double Function( double x )
		{
			return ( 1 / ( 1 + Math.Exp( -alpha * x ) ) );
		}

		/// <summary>
		/// Calculates function derivative
		/// </summary>
		/// 
		/// <param name="x">Function input value</param>
		/// 
		/// <returns>Function derivative, <i>f'(x)</i></returns>
		/// 
		/// <remarks>The method calculates function derivative at point <b>x</b>.</remarks>
		///
		public double Derivative( double x )
		{
			double y = Function( x );

			return ( alpha * y * ( 1 - y ) );
		}

		/// <summary>
		/// Calculates function derivative
		/// </summary>
		/// 
		/// <param name="y">Function output value - the value, which was obtained
		/// with the help of <see cref="Function"/> method</param>
		/// 
		/// <returns>Function derivative, <i>f'(x)</i></returns>
		/// 
		/// <remarks>The method calculates the same derivative value as the
		/// <see cref="Derivative"/> method, but it takes not the input <b>x</b> value
		/// itself, but the function value, which was calculated previously with
		/// the help of <see cref="Function"/> method. <i>(Some applications require as
		/// function value, as derivative value, so they can seve the amount of
		/// calculations using this method to calculate derivative)</i></remarks>
		/// 
		public double Derivative2( double y )
		{
			return ( alpha * y * ( 1 - y ) );
		}	
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Andrew Kirillov
Software Developer (Senior) Cisco Systems
United Kingdom United Kingdom
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET.
 
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 19 Nov 2006
Article Copyright 2006 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid