// NeuralNetwork.cs
//
// Copyright (C) 2004 Kingsley Tagbo
//
// LICENSE:
// You have my permission to use this software, redistribute it and/or
// modify it under the terms of the GNU General Public License
// (SEE HTTP://WWW.FSF.ORG OR THE COPY OF THE GNU PUBLIC LICENSE BELOW)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version
// AS LONG AS YOU INCLUDE A REFERENCE TO KINGSLEY TAGBO -
// HTTP://WWW.VISUAL-BASIC-DATA-MINING.NET AS THE ORIGINAL AUTHOR
// OF THIS PROGRAM AND YOU DO NOT REMOVE THE COPYRIGHT AND LICENSE
// NOTICES IN THIS FREE SOFTWARE
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
//C# NEURAL NETWORK MULTILAYER FEEDFORWARD BACKPROPAGATION ALGORITHM VERSION 1.0
//DATE : OCTOBER 25, 2004 4:38 AM
//AUTHOR : KINGSLEY TAGBO
//LICENSE : DISTRIBUTED UNDER GNU GENERAL PUBLIC LICENSE VERSION 2, JUNE 1991 (SEE WWW.FSF.ORG)
// : YOU CAN ALSO READ THE LICENSE INCLUDED BELOW AFTER THE SOURCE CODE
//VERSION : 1.0
//COPYRIGHT : KINGSLEY TAGBO - HTTP://WWW.KDKEYS.NET
//RELEASE: : GOLD
SOURCE CODE DOCUMENTATION
NeuralNetwork
Artificial MiultiLayer FeedForward Neural Network With BackPropagation Algorithm
rand field
Static variable for random numbers
input_count field
Static variable for number of neurons or cells in INPUT LAYER
hidden_count field
Static variable for number of neurons or cells in HIDDEN LAYER
output_count field
Static variable for number of neurons or cells in OUTPUT LAYER
iterations field
Static variable for the number of processing cycles of the Neural Network
learning_rate field
Represents the LEARNING RATE used in gradient descent to prevent weights from converging at sub-optimal solutions.
input_data field
A two dimensional array of input data from a training sample An INPUT represented as double [,] inputDataArray = new Double [,] {{0.20, 0.80}, {0.80, 0.4}} would represent 2 training instances for an INPUT LAYER with 2 NEURONS or CELLS
output_data field
A two dimensional array of output data from a training sample An OUTPUT represented as double [,] outputDataArray = new Double [,] {{0}, {1}} would represent 2 training instances for an OUTPUT LAYER with 1 NEURON or CELL
input field
A collection of neurons representing the input layer
hidden field
A collection of neurons representing the hidden layer
output field
A collection of neurons representing the output layer
Initialize(Double[0:,0:],Double[0:,0:],Int32) method
Initializes the LAYERS in the NEURAL NETWORK
Parameters
- inputData
- INPUTS data for the NEURONS in the INPUT LAYER
- outputData
- OUTPUT data for the NEURONS in the OUTPUT LAYER
- hidden_layer_count
- The number of neurons in the HIDDEN LAYER
FeedForward(Int32) method
Initializes the NEURAL NETWORK with training data input or a real world data input for classification. FeedForward feeds the INPUT to the INPUT LAYER neurons FeedForward feeds the OUTPUT from the INPUT LAYER to the HIDDEN LAYER FeedForward feeds the OUTPUT from the HIDDEN LAYER to the OUTPUT LAYER FeedForward uses the Sigmoid Function or Logistic Function to calculate the OUTPUT from the INPUT in the HIDDEN and OUTPUT LAYERS
Parameters
- sampleNumber
- A numeric ordered value representing the training or classification instance. If the dataset contains 10 instances or rows, the first row has a sampleNumber = 0 and the last row or instance has a sample number = 9
BackPropagate() method
Recalculates the BIAS and ERROR in the HIDDEN LAYER and OUTPUT LAYER. Adjustes the WEIGHTS between the OUTPUT LAYER and HIDDEN LAYER and between the HIDDEN LAYER and the INPUT LAYER using the derivative of the Sigmoid Function or Logistic Function
Main() method
Executes a Neural Network MultiLayer FeedForward BackPropagation Algorithm for Learning or Classification
Random property
Generates random double values between -1.0 and +1.0
NeuralNetwork.Neuron
A Neuron is the basic building block of a Neural Network
Neuron(Int32,Int32) constructor
Public constructor for initializing a neuron
Parameters
- layer
- Input Layer = 0, Hidden Layer = 1 and Output Layer = 2
- index
- A number assigned to a cell for ordering the cell or identifying it
player field
Internal storage for Neuron.Layer public property
pindex field
Internal storage for Neuron.Index public property
pinput field
Internal storage for Neuron.Input public property
poutput field
Internal storage for Neuron.Output public property
poutputTraining field
Internal storage for Neutron.OutputTraining public property
pweight field
Internal storage for Network.Weight public property
pbias field
Internal storage for Network.Bias public property
perror field
Internal storage for Network.Error public property
LogisticFunction(Double) method
Sigmoid Function or Logistic Function or Activation Function is applied to the INPUT to a NETWORK LAYER to get an OUTPUT
Parameters
- val
- The value to calculate a Sigmoid or Logistic Function for
Returns
System.Double datatype of the Logistic or Sigmoid Function result
LogisticFunctionDerivative(Double) method
Derivative of the Sigmoid Function or Logistic Function or Activation Function
Parameters
- val
- The value to calculate the derivative of the Sigmoid Function for
Returns
System.Double datatype of the numeric result
Layer property
INPUT LAYER = 0, HIDDEN LAYER = 1, OUTPUT LAYER = 2
Index property
Identifies a Neuron or the position of a Neuron in a LAYER
Input property
Input data fed to the Neural Network
Output property
Calculated Ouput from the INPUT, HIDDEN or OUTPUT LAYER
OutputTraining property
Expected or Target or Learning output for a neutron in the OUPUT LAYER
Weight property
Storage for array of weights from OUTPUT to HIDDEN LAYER and from HIDDENLAYER TO INPUT LAYER. Each Neuron in the OUTPUT and HIDDEN LAYER is connected to an array of Neurons
Bias property
Varies the OUTPUT of a Neuronin a HIDDEN or OUTPUT LAYER
Error property
Error = (ACTUALOUTPUT * (1 - ACTUALOUTPUT) * (EXPECTEDOUTPUT - ACTUALOUTPUT))
NeuralNetwork.Neurons
A Neural Network Layer or collection of cells or neurons
Add(Neuron) method
Adds a neuron to a Neural Network Layer or collection of cells
Parameters
- newNeuron
- The neuron to add to a Neural Network Layer
Insert(Int32,Neuron) method
Adds a neuron to a Neural Network Layer at a specific position
Parameters
- index
- The position where a neuron will be inserted
- newNeuron
- The neuron to add to a Neural Network Layer
this[Int32] indexer
ReadOnly indexer - retrieves the neuron at a specific position orlocation in the Neural Network Layer or Neural Network Collection