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
Some ideas about optical character recognition using neural networks.
// AForge Neural Net Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.NeuralNet
{
	using System;

	/// <summary>
	/// Network - represent a collection of connected layers
	/// </summary>
	public class Network
	{
		protected int	inputsCount;	// inputs count of the net
		protected int	layersCount;	// layers count in the net
		protected float[]	output;		// network output

		protected Layer[]	layers;

		// Layers count property
		public int LayersCount
		{
			get { return layersCount; }
		}
		// Get layer at the specified index
		public Layer this[int index]
		{
			get { return (layers[index]); }
		}
		// Get network output
		public float[] Output
		{
			get { return output; }
		}

		// Constructors
		public Network(int inputsCount, params int[] neuronsCountPerLayer)
			: this(new SigmoidFunction(), inputsCount, neuronsCountPerLayer)
		{ }
		public Network(IActivationFunction function, int inputsCount, params int[] neuronsCountPerLayer)
		{
			this.inputsCount = Math.Max(1, inputsCount);
			this.layersCount = neuronsCountPerLayer.Length;

			// create collection of layers
			layers = new Layer[layersCount];
			// create each layer
			for (int i = 0; i < layersCount; i++)
			{
				layers[i] = new Layer(
					neuronsCountPerLayer[i],
					(i == 0) ? inputsCount : neuronsCountPerLayer[i - 1],
					function);
			}
		}


		// Compute the output value of the net
		public float[] Compute(float[] input)
		{
			output = input;

			// compute each layer
			for (int i = 0; i < layersCount; i++)
			{
				output = layers[i].Compute(output);
			}

			return output;
		}

		// Randomize the network
		public void Randomize()
		{
			foreach (Layer layer in layers)
				layer.Randomize();
		}
	}
}

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
Web03 | 2.8.140827.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid