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

Designing And Implementing A Neural Network Library For Handwriting Detection, Image Analysis etc.- The BrainNet Library - Full Code, Simplified Theory, Full Illustration, And Examples

, 21 Oct 2009 CPOL
This article will explain the actual concepts and implementation of Backward Propagation Neural Networks very easily - see project code and samples, like a simple pattern detector, a hand writing detection pad, an xml based neural network processing language etc in the source zip.
brainnet_src.zip
BrainNetIntro
NeuralGate
NeuralGate.vbproj.user
PatternDetector
PatternDetector.vbproj.user
TestImages
a1.bmp
b1.bmp
b2.bmp
c1.bmp
c2.bmp
D.bmp
D1.bmp
D2.bmp
E1.bmp
E2.bmp
Thumbs.db
Framework
BrainNet.suo
NetworkDataModel
Network.xsx
NeuralXML.xsx
NetworkIO.xsx
NeuralFramework.vbproj.user
nxml
nxml.vbproj.user
BrainNet.suo
Doc
Documentation.chm
Samples
HandWriting
HandWriting.suo
HandWriting.vbproj.user
'Let us import the brainnet framework
Imports BrainNet.NeuralFramework

'<summary> Our simple digital neural gate class </summary>
Public Class DigitalNeuralGate

    'A variable to hold our network
    Private network As BrainNet.NeuralFramework.NeuralNetwork

    '<summary> This is the constructor. Here, we will create a 2-2-1 network </summary>
    Public Sub New()

        'Create the factory to create a Backward Propagation Neural Network
        'Backward Propagation neural network is a commonly used neural network model
        Dim factory As New BrainNet.NeuralFramework.BackPropNetworkFactory()

        'This is an arralist which holds the number of neurons in each layer
        Dim layers As New ArrayList()

        'We need 2 neurons in first layer
        layers.Add(2)
        'We need 2 neurons in the second layer (the second layer is the first
        'hidden layer)
        layers.Add(2)
        'We need one neuron in the output layer
        layers.Add(1)

        'Provide the arraylist as the parameter, to create a network
        network = factory.CreateNetwork(layers)

        'Now, network holds a 2-2-1 neural network object in it.

    End Sub


    '<summary> This is the function for training the network using
    'the brainnet library </summary>
    Public Sub Train(ByVal input1 As Long, ByVal input2 As Long, ByVal output As Long)

        'Create a training data object
        Dim td As New TrainingData()

        'Add inputs to the training data object
        td.Inputs.Add(input1)
        td.Inputs.Add(input2)

        'Add expected output to the training data object
        td.Outputs.Add(output)

        'Train the network one time
        network.TrainNetwork(td)

    End Sub

    '<summary> This is the function for running the network using the
    'brainnet library </summary>
    Public Function Run(ByVal input1 As Long, ByVal input2 As Long) As Double

        'Declare an arraylist to provide as input to the Run method
        Dim inputs As New ArrayList()

        'Add the first input
        inputs.Add(input1)
        'Add the second input
        inputs.Add(input2)

        'Get the output, by calling the network's RunNetwork method
        Dim outputs As ArrayList = network.RunNetwork(inputs)

        'As we have only one neuron in the output layer,
        'let us return its output
        Return outputs(0)

    End Function

    '<summary> This is the function is for saving this gate to 
    'an xml file </summary>
    Public Sub Save(ByVal file As String)
        Dim ser As New BrainNet.NeuralFramework.NetworkSerializer()
        ser.SaveNetwork(file, network)
    End Sub

    '<summary> This is the function is for loading this gate 
    'from an xml file </summary>
    Public Sub Load(ByVal file As String)
        Dim ser As New BrainNet.NeuralFramework.NetworkSerializer()
        ser.LoadNetwork(file, network)
    End Sub




End Class

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 Code Project Open License (CPOL)

Share

About the Author


| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 21 Oct 2009
Article Copyright 2006 by Anoop Madhusudanan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid