Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Neural Network OCR

, 11 Aug 2005 GPL3
Some ideas about optical character recognition using neural networks.
neuroocr_demo.zip
AForge.Imaging.dll
AForge.Math.dll
AForge.NeuralNet.dll
NeuroOCR.exe
SourceGrid2.dll
SourceLibrary.dll
neuroocr_src.zip
AForge
Math
Math.csproj.user
NeuralNet
Learning
NeuralNet.csproj.user
NeuroOCR
App.ico
NeuroOCR.csproj.user
References
AForge.Imaging.dll
SourceGrid2.dll
SourceLibrary.dll
// AForge Neural Net Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.NeuralNet
{
	using System;

	/// <summary>
	/// ActivationFunction interface
	/// </summary>
	public interface IActivationFunction
	{
		// Calculate function value
		float Output(float input);

		// Calculate differential of the function value
		float OutputPrime(float input);

		// Calculate differential of the function value
		// using function value as input
		float OutputPrime2(float input);
	}

	// Sigmoid activation function
	//
	//                1
	// f(x) = ------------------
	//        1 + exp(-alfa * x)
	//
	// Outpur range: [0, 1]
	//
	public class SigmoidFunction : IActivationFunction
	{
		private float alfa = 2;

		// Alfa property
		public float Alfa
		{
			get { return alfa; }
			set { alfa = value; }
		}

		// Constructors
		public SigmoidFunction()
		{ }
		public SigmoidFunction(float alfa)
		{
			this.alfa = alfa;
		}

		
		// Calculate function value
		public float Output(float x)
		{
			return (float) (1 / (1 + Math.Exp(-alfa * x)));
		}

		// Calculate differential of the function value
		public float OutputPrime(float x)
		{
			float y = Output(x);

			return (float) (alfa * y * (1 - y));
		}

		// Calculate differential of the function value
		// using function value as input
		public float OutputPrime2(float y)
		{
			return (float) (alfa * y * (1 - y));
		}
	}


	// Bipolar Sigmoid activation function
	//
	//                1
	// f(x) = ------------------ - 0.5
	//        1 + exp(-alfa * x)
	//
	// Outpur range: [-0.5, 0.5]
	//
	public class BipolarSigmoidFunction : IActivationFunction
	{
		private float alfa = 2;

		// Alfa property
		public float Alfa
		{
			get { return alfa; }
			set { alfa = value; }
		}

		// Constructors
		public BipolarSigmoidFunction()
		{ }
		public BipolarSigmoidFunction(float alfa)
		{
			this.alfa = alfa;
		}

		
		// Calculate function value
		public float Output(float x)
		{
			return (float) ((1 / (1 + Math.Exp(-alfa * x))) - 0.5);
		}

		// Calculate differential of the function value
		public float OutputPrime(float x)
		{
			float y = Output(x);

			return (float) (alfa * (0.25 - y * y));
		}

		// Calculate differential of the function value
		// using function value as input
		public float OutputPrime2(float y)
		{
			return (float) (alfa * (0.25 - y * y));
		}
	}


	// Hyperbolic Tangens activation function
	//
	//                         exp(alfa * x) - exp(-alfa * x)
	// f(x) = tanh(alfa * x) = ------------------------------
	//                         exp(alfa * x) + exp(-alfa * x)
	//
	// Outpur range: [-1, 1]
	//
	public class HyperbolicTangensFunction : IActivationFunction
	{
		private float alfa = 1;

		// Alfa property
		public float Alfa
		{
			get { return alfa; }
			set { alfa = value; }
		}

		// Constructors
		public HyperbolicTangensFunction()
		{ }
		public HyperbolicTangensFunction(float alfa)
		{
			// dividing alfa by two gives us the same function
			// as sigmoid function
			this.alfa = alfa;
		}

		// Calculate function value
		public float Output(float x)
		{
			return (float) (Math.Tanh(alfa * x));
		}

		// Calculate differential of the function value
		public float OutputPrime(float x)
		{
			float y = Output(x);

			return (float) (alfa * (1 - y * y));
		}

		// Calculate differential of the function value
		// using function value as input
		public float OutputPrime2(float y)
		{
			return (float) (alfa * (1 - y * 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 | Mobile
Web01 | 2.8.141022.2 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid