Click here to Skip to main content
15,885,881 members
Articles / Programming Languages / XML

Brainnet - Introducing a declarative neural network library

Rate me:
Please Sign up or sign in to vote.
4.74/5 (117 votes)
4 Apr 2007CPOL18 min read 401.4K   9.4K   410  
This article is expected to (0) Introduce Brainnet, a declarative neural network library we developed (1) Demonstrate some practical uses neural network programming (2) Give you a fair idea regarding neurons, neural networks and their applications (3) Introduce BrainNet library - an open source
Public Class frmGate
    Inherits System.Windows.Forms.Form

    'Our variable to hold the gate
    Private gate As DigitalNeuralGate


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents out1 As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents out2 As System.Windows.Forms.TextBox
    Friend WithEvents out3 As System.Windows.Forms.TextBox
    Friend WithEvents out4 As System.Windows.Forms.TextBox
    Friend WithEvents cmdTrain1000 As System.Windows.Forms.Button
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents cmdRun As System.Windows.Forms.Button
    Friend WithEvents llAND As System.Windows.Forms.LinkLabel
    Friend WithEvents llOR As System.Windows.Forms.LinkLabel
    Friend WithEvents llXOR As System.Windows.Forms.LinkLabel
    Friend WithEvents cmdRestart As System.Windows.Forms.Button
    Friend WithEvents cmdClose As System.Windows.Forms.Button
    Friend WithEvents lblTrainInfo As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents inp42 As System.Windows.Forms.TextBox
    Friend WithEvents inp41 As System.Windows.Forms.TextBox
    Friend WithEvents inp32 As System.Windows.Forms.TextBox
    Friend WithEvents inp31 As System.Windows.Forms.TextBox
    Friend WithEvents inp22 As System.Windows.Forms.TextBox
    Friend WithEvents inp21 As System.Windows.Forms.TextBox
    Friend WithEvents inp12 As System.Windows.Forms.TextBox
    Friend WithEvents inp11 As System.Windows.Forms.TextBox
    Friend WithEvents rout1 As System.Windows.Forms.TextBox
    Friend WithEvents rinp12 As System.Windows.Forms.TextBox
    Friend WithEvents rinp11 As System.Windows.Forms.TextBox
    Friend WithEvents rout2 As System.Windows.Forms.TextBox
    Friend WithEvents rinp22 As System.Windows.Forms.TextBox
    Friend WithEvents rinp21 As System.Windows.Forms.TextBox
    Friend WithEvents rout3 As System.Windows.Forms.TextBox
    Friend WithEvents rinp32 As System.Windows.Forms.TextBox
    Friend WithEvents rinp31 As System.Windows.Forms.TextBox
    Friend WithEvents rout4 As System.Windows.Forms.TextBox
    Friend WithEvents rinp42 As System.Windows.Forms.TextBox
    Friend WithEvents rinp41 As System.Windows.Forms.TextBox
    Friend WithEvents cmdTrainOnce As System.Windows.Forms.Button
    Friend WithEvents cmdSave As System.Windows.Forms.Button
    Friend WithEvents cmdLoad As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.cmdTrainOnce = New System.Windows.Forms.Button()
        Me.lblTrainInfo = New System.Windows.Forms.Label()
        Me.llXOR = New System.Windows.Forms.LinkLabel()
        Me.llOR = New System.Windows.Forms.LinkLabel()
        Me.llAND = New System.Windows.Forms.LinkLabel()
        Me.out4 = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.inp42 = New System.Windows.Forms.TextBox()
        Me.inp41 = New System.Windows.Forms.TextBox()
        Me.out3 = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.inp32 = New System.Windows.Forms.TextBox()
        Me.inp31 = New System.Windows.Forms.TextBox()
        Me.out2 = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.inp22 = New System.Windows.Forms.TextBox()
        Me.inp21 = New System.Windows.Forms.TextBox()
        Me.out1 = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.inp12 = New System.Windows.Forms.TextBox()
        Me.inp11 = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.cmdTrain1000 = New System.Windows.Forms.Button()
        Me.Panel2 = New System.Windows.Forms.Panel()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.rout4 = New System.Windows.Forms.TextBox()
        Me.rinp42 = New System.Windows.Forms.TextBox()
        Me.rinp41 = New System.Windows.Forms.TextBox()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.rout3 = New System.Windows.Forms.TextBox()
        Me.rinp32 = New System.Windows.Forms.TextBox()
        Me.rinp31 = New System.Windows.Forms.TextBox()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.rout2 = New System.Windows.Forms.TextBox()
        Me.rinp22 = New System.Windows.Forms.TextBox()
        Me.rinp21 = New System.Windows.Forms.TextBox()
        Me.cmdRun = New System.Windows.Forms.Button()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.rout1 = New System.Windows.Forms.TextBox()
        Me.rinp12 = New System.Windows.Forms.TextBox()
        Me.rinp11 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.cmdRestart = New System.Windows.Forms.Button()
        Me.cmdClose = New System.Windows.Forms.Button()
        Me.cmdSave = New System.Windows.Forms.Button()
        Me.cmdLoad = New System.Windows.Forms.Button()
        Me.Panel1.SuspendLayout()
        Me.Panel2.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.White
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdTrainOnce, Me.lblTrainInfo, Me.llXOR, Me.llOR, Me.llAND, Me.out4, Me.Label6, Me.inp42, Me.inp41, Me.out3, Me.Label5, Me.inp32, Me.inp31, Me.out2, Me.Label4, Me.inp22, Me.inp21, Me.out1, Me.Label3, Me.inp12, Me.inp11, Me.Label1, Me.cmdTrain1000})
        Me.Panel1.Location = New System.Drawing.Point(7, 12)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(309, 252)
        Me.Panel1.TabIndex = 0
        '
        'cmdTrainOnce
        '
        Me.cmdTrainOnce.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.cmdTrainOnce.Location = New System.Drawing.Point(147, 208)
        Me.cmdTrainOnce.Name = "cmdTrainOnce"
        Me.cmdTrainOnce.Size = New System.Drawing.Size(113, 25)
        Me.cmdTrainOnce.TabIndex = 23
        Me.cmdTrainOnce.Text = "Train Once"
        '
        'lblTrainInfo
        '
        Me.lblTrainInfo.Location = New System.Drawing.Point(20, 35)
        Me.lblTrainInfo.Name = "lblTrainInfo"
        Me.lblTrainInfo.Size = New System.Drawing.Size(298, 16)
        Me.lblTrainInfo.TabIndex = 22
        Me.lblTrainInfo.Text = "lblInfo"
        '
        'llXOR
        '
        Me.llXOR.Location = New System.Drawing.Point(190, 120)
        Me.llXOR.Name = "llXOR"
        Me.llXOR.Size = New System.Drawing.Size(104, 16)
        Me.llXOR.TabIndex = 21
        Me.llXOR.TabStop = True
        Me.llXOR.Text = "Truth Table of XOR"
        '
        'llOR
        '
        Me.llOR.Location = New System.Drawing.Point(190, 91)
        Me.llOR.Name = "llOR"
        Me.llOR.Size = New System.Drawing.Size(98, 16)
        Me.llOR.TabIndex = 20
        Me.llOR.TabStop = True
        Me.llOR.Text = "Truth Table of OR"
        '
        'llAND
        '
        Me.llAND.Location = New System.Drawing.Point(190, 63)
        Me.llAND.Name = "llAND"
        Me.llAND.Size = New System.Drawing.Size(104, 16)
        Me.llAND.TabIndex = 19
        Me.llAND.TabStop = True
        Me.llAND.Text = "Truth Table of AND"
        '
        'out4
        '
        Me.out4.Location = New System.Drawing.Point(131, 164)
        Me.out4.Name = "out4"
        Me.out4.Size = New System.Drawing.Size(33, 20)
        Me.out4.TabIndex = 16
        Me.out4.Text = ""
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(109, 169)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(15, 12)
        Me.Label6.TabIndex = 15
        Me.Label6.Text = "="
        '
        'inp42
        '
        Me.inp42.Location = New System.Drawing.Point(60, 164)
        Me.inp42.Name = "inp42"
        Me.inp42.ReadOnly = True
        Me.inp42.Size = New System.Drawing.Size(33, 20)
        Me.inp42.TabIndex = 14
        Me.inp42.Text = "1"
        '
        'inp41
        '
        Me.inp41.Location = New System.Drawing.Point(15, 164)
        Me.inp41.Name = "inp41"
        Me.inp41.ReadOnly = True
        Me.inp41.Size = New System.Drawing.Size(33, 20)
        Me.inp41.TabIndex = 13
        Me.inp41.Text = "1"
        '
        'out3
        '
        Me.out3.Location = New System.Drawing.Point(131, 129)
        Me.out3.Name = "out3"
        Me.out3.Size = New System.Drawing.Size(33, 20)
        Me.out3.TabIndex = 12
        Me.out3.Text = ""
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(108, 134)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(15, 12)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "="
        '
        'inp32
        '
        Me.inp32.Location = New System.Drawing.Point(60, 129)
        Me.inp32.Name = "inp32"
        Me.inp32.ReadOnly = True
        Me.inp32.Size = New System.Drawing.Size(33, 20)
        Me.inp32.TabIndex = 10
        Me.inp32.Text = "0"
        '
        'inp31
        '
        Me.inp31.Location = New System.Drawing.Point(15, 129)
        Me.inp31.Name = "inp31"
        Me.inp31.ReadOnly = True
        Me.inp31.Size = New System.Drawing.Size(33, 20)
        Me.inp31.TabIndex = 9
        Me.inp31.Text = "1"
        '
        'out2
        '
        Me.out2.Location = New System.Drawing.Point(131, 94)
        Me.out2.Name = "out2"
        Me.out2.Size = New System.Drawing.Size(33, 20)
        Me.out2.TabIndex = 8
        Me.out2.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(107, 99)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(15, 12)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "="
        '
        'inp22
        '
        Me.inp22.Location = New System.Drawing.Point(60, 94)
        Me.inp22.Name = "inp22"
        Me.inp22.ReadOnly = True
        Me.inp22.Size = New System.Drawing.Size(33, 20)
        Me.inp22.TabIndex = 6
        Me.inp22.Text = "1"
        '
        'inp21
        '
        Me.inp21.Location = New System.Drawing.Point(15, 94)
        Me.inp21.Name = "inp21"
        Me.inp21.ReadOnly = True
        Me.inp21.Size = New System.Drawing.Size(33, 20)
        Me.inp21.TabIndex = 5
        Me.inp21.Text = "0"
        '
        'out1
        '
        Me.out1.Location = New System.Drawing.Point(131, 59)
        Me.out1.Name = "out1"
        Me.out1.Size = New System.Drawing.Size(33, 20)
        Me.out1.TabIndex = 4
        Me.out1.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(106, 62)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(15, 12)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "="
        '
        'inp12
        '
        Me.inp12.Location = New System.Drawing.Point(60, 59)
        Me.inp12.Name = "inp12"
        Me.inp12.ReadOnly = True
        Me.inp12.Size = New System.Drawing.Size(33, 20)
        Me.inp12.TabIndex = 2
        Me.inp12.Text = "0"
        '
        'inp11
        '
        Me.inp11.Location = New System.Drawing.Point(15, 59)
        Me.inp11.Name = "inp11"
        Me.inp11.ReadOnly = True
        Me.inp11.Size = New System.Drawing.Size(33, 20)
        Me.inp11.TabIndex = 1
        Me.inp11.Text = "0"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.White
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(15, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(291, 17)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Step 1 : Train The Network Using Truth Table"
        '
        'cmdTrain1000
        '
        Me.cmdTrain1000.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.cmdTrain1000.Location = New System.Drawing.Point(9, 208)
        Me.cmdTrain1000.Name = "cmdTrain1000"
        Me.cmdTrain1000.Size = New System.Drawing.Size(113, 25)
        Me.cmdTrain1000.TabIndex = 18
        Me.cmdTrain1000.Text = "Train 1000 Times"
        '
        'Panel2
        '
        Me.Panel2.BackColor = System.Drawing.Color.White
        Me.Panel2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label10, Me.rout4, Me.rinp42, Me.rinp41, Me.Label9, Me.rout3, Me.rinp32, Me.rinp31, Me.Label8, Me.rout2, Me.rinp22, Me.rinp21, Me.cmdRun, Me.Label7, Me.rout1, Me.rinp12, Me.rinp11, Me.Label2})
        Me.Panel2.Location = New System.Drawing.Point(323, 12)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(299, 253)
        Me.Panel2.TabIndex = 1
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(120, 169)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(15, 12)
        Me.Label10.TabIndex = 30
        Me.Label10.Text = "="
        '
        'rout4
        '
        Me.rout4.Location = New System.Drawing.Point(147, 167)
        Me.rout4.Name = "rout4"
        Me.rout4.ReadOnly = True
        Me.rout4.Size = New System.Drawing.Size(140, 20)
        Me.rout4.TabIndex = 29
        Me.rout4.Text = ""
        '
        'rinp42
        '
        Me.rinp42.Location = New System.Drawing.Point(61, 165)
        Me.rinp42.Name = "rinp42"
        Me.rinp42.ReadOnly = True
        Me.rinp42.Size = New System.Drawing.Size(33, 20)
        Me.rinp42.TabIndex = 28
        Me.rinp42.Text = "1"
        '
        'rinp41
        '
        Me.rinp41.Location = New System.Drawing.Point(21, 165)
        Me.rinp41.Name = "rinp41"
        Me.rinp41.ReadOnly = True
        Me.rinp41.Size = New System.Drawing.Size(33, 20)
        Me.rinp41.TabIndex = 27
        Me.rinp41.Text = "1"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(120, 136)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(15, 12)
        Me.Label9.TabIndex = 26
        Me.Label9.Text = "="
        '
        'rout3
        '
        Me.rout3.Location = New System.Drawing.Point(147, 134)
        Me.rout3.Name = "rout3"
        Me.rout3.ReadOnly = True
        Me.rout3.Size = New System.Drawing.Size(140, 20)
        Me.rout3.TabIndex = 25
        Me.rout3.Text = ""
        '
        'rinp32
        '
        Me.rinp32.Location = New System.Drawing.Point(61, 132)
        Me.rinp32.Name = "rinp32"
        Me.rinp32.ReadOnly = True
        Me.rinp32.Size = New System.Drawing.Size(33, 20)
        Me.rinp32.TabIndex = 24
        Me.rinp32.Text = "0"
        '
        'rinp31
        '
        Me.rinp31.Location = New System.Drawing.Point(21, 132)
        Me.rinp31.Name = "rinp31"
        Me.rinp31.ReadOnly = True
        Me.rinp31.Size = New System.Drawing.Size(33, 20)
        Me.rinp31.TabIndex = 23
        Me.rinp31.Text = "1"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(120, 101)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(15, 12)
        Me.Label8.TabIndex = 22
        Me.Label8.Text = "="
        '
        'rout2
        '
        Me.rout2.Location = New System.Drawing.Point(147, 99)
        Me.rout2.Name = "rout2"
        Me.rout2.ReadOnly = True
        Me.rout2.Size = New System.Drawing.Size(140, 20)
        Me.rout2.TabIndex = 21
        Me.rout2.Text = ""
        '
        'rinp22
        '
        Me.rinp22.Location = New System.Drawing.Point(61, 97)
        Me.rinp22.Name = "rinp22"
        Me.rinp22.ReadOnly = True
        Me.rinp22.Size = New System.Drawing.Size(33, 20)
        Me.rinp22.TabIndex = 20
        Me.rinp22.Text = "1"
        '
        'rinp21
        '
        Me.rinp21.Location = New System.Drawing.Point(21, 97)
        Me.rinp21.Name = "rinp21"
        Me.rinp21.ReadOnly = True
        Me.rinp21.Size = New System.Drawing.Size(33, 20)
        Me.rinp21.TabIndex = 19
        Me.rinp21.Text = "0"
        '
        'cmdRun
        '
        Me.cmdRun.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.cmdRun.Location = New System.Drawing.Point(20, 210)
        Me.cmdRun.Name = "cmdRun"
        Me.cmdRun.Size = New System.Drawing.Size(118, 25)
        Me.cmdRun.TabIndex = 18
        Me.cmdRun.Text = "Run Network"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(120, 65)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(15, 12)
        Me.Label7.TabIndex = 8
        Me.Label7.Text = "="
        '
        'rout1
        '
        Me.rout1.Location = New System.Drawing.Point(147, 63)
        Me.rout1.Name = "rout1"
        Me.rout1.ReadOnly = True
        Me.rout1.Size = New System.Drawing.Size(140, 20)
        Me.rout1.TabIndex = 7
        Me.rout1.Text = ""
        '
        'rinp12
        '
        Me.rinp12.Location = New System.Drawing.Point(61, 61)
        Me.rinp12.Name = "rinp12"
        Me.rinp12.ReadOnly = True
        Me.rinp12.Size = New System.Drawing.Size(33, 20)
        Me.rinp12.TabIndex = 6
        Me.rinp12.Text = "0"
        '
        'rinp11
        '
        Me.rinp11.Location = New System.Drawing.Point(21, 61)
        Me.rinp11.Name = "rinp11"
        Me.rinp11.ReadOnly = True
        Me.rinp11.Size = New System.Drawing.Size(33, 20)
        Me.rinp11.TabIndex = 5
        Me.rinp11.Text = "0"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.White
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(17, 10)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(267, 14)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Step 2: Run The Network And See Results"
        '
        'cmdRestart
        '
        Me.cmdRestart.BackColor = System.Drawing.SystemColors.Control
        Me.cmdRestart.Location = New System.Drawing.Point(370, 273)
        Me.cmdRestart.Name = "cmdRestart"
        Me.cmdRestart.Size = New System.Drawing.Size(119, 25)
        Me.cmdRestart.TabIndex = 19
        Me.cmdRestart.Text = "Reset Gate"
        '
        'cmdClose
        '
        Me.cmdClose.BackColor = System.Drawing.SystemColors.Control
        Me.cmdClose.Location = New System.Drawing.Point(498, 273)
        Me.cmdClose.Name = "cmdClose"
        Me.cmdClose.Size = New System.Drawing.Size(119, 25)
        Me.cmdClose.TabIndex = 20
        Me.cmdClose.Text = "Close"
        '
        'cmdSave
        '
        Me.cmdSave.BackColor = System.Drawing.SystemColors.Control
        Me.cmdSave.Location = New System.Drawing.Point(8, 276)
        Me.cmdSave.Name = "cmdSave"
        Me.cmdSave.Size = New System.Drawing.Size(119, 25)
        Me.cmdSave.TabIndex = 21
        Me.cmdSave.Text = "Save Gate"
        '
        'cmdLoad
        '
        Me.cmdLoad.BackColor = System.Drawing.SystemColors.Control
        Me.cmdLoad.Location = New System.Drawing.Point(141, 277)
        Me.cmdLoad.Name = "cmdLoad"
        Me.cmdLoad.Size = New System.Drawing.Size(119, 25)
        Me.cmdLoad.TabIndex = 22
        Me.cmdLoad.Text = "Load Gate"
        '
        'frmGate
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(627, 308)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdLoad, Me.cmdSave, Me.cmdClose, Me.cmdRestart, Me.Panel2, Me.Panel1})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.Name = "frmGate"
        Me.Text = "Binary Gate Interface"
        Me.TopMost = True
        Me.Panel1.ResumeLayout(False)
        Me.Panel2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Event Handlers"

    Private Sub frmGate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Create a new gate
        gate = New DigitalNeuralGate()

        'Initialize with truth table of XOR

        'Set the outputs
        lblTrainInfo.Text = "Initialized with TT of XOR"


        'This is the TT of XOR
        Me.out1.Text = "0"
        Me.out2.Text = "1"
        Me.out3.Text = "1"
        Me.out4.Text = "0"


    End Sub

    Private Sub cmdRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRestart.Click
        'Create a new gate
        gate = New DigitalNeuralGate()

    End Sub

    Private Sub llAND_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llAND.LinkClicked
        'Set the outputs to match AND TT
        lblTrainInfo.Text = "Initialized with TT of AND"


        Me.out1.Text = "0"
        Me.out2.Text = "0"
        Me.out3.Text = "0"
        Me.out4.Text = "1"

    End Sub

    Private Sub llOR_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llOR.LinkClicked

        'Set the outputs to match OR TT
        lblTrainInfo.Text = "Initialized with TT of OR"


        Me.out1.Text = "0"
        Me.out2.Text = "1"
        Me.out3.Text = "1"
        Me.out4.Text = "1"
    End Sub

    Private Sub llXOR_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llXOR.LinkClicked

        'Set the outputs to match XOR TT
        lblTrainInfo.Text = "Initialized with TT of XOR"

        Me.out1.Text = "0"
        Me.out2.Text = "1"
        Me.out3.Text = "1"
        Me.out4.Text = "0"
    End Sub

    'Train the network 1000 times
    Private Sub cmdTrain1000_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTrain1000.Click
        Dim i As Integer
        Try
            'Call the TrainOnce function 1000 times
            For i = 0 To 1000
                TrainOnce()
            Next
        Catch ex As Exception
            MsgBox("Error. Check whether the input is valid - " + ex.Message)
        End Try
    End Sub

    'Run the network to get the output, and show it in the text boxes
    Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRun.Click
        Try
            'rout1, rinp11, rinp12 etc are textbox names
            rout1.Text = gate.Run(CLng(Me.rinp11.Text), CLng(Me.rinp12.Text))
            rout2.Text = gate.Run(CLng(Me.rinp21.Text), CLng(Me.rinp22.Text))
            rout3.Text = gate.Run(CLng(Me.rinp31.Text), CLng(Me.rinp32.Text))
            rout4.Text = gate.Run(CLng(Me.rinp41.Text), CLng(Me.rinp42.Text))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    'Train only once
    Private Sub cmdTrainOnce_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTrainOnce.Click

        Try
            TrainOnce()
        Catch ex As Exception
            MsgBox("Error. Check whether the input is valid - " + ex.Message)
        End Try
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.Close()
        End

    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        gate.Save("c:\test.xml")
    End Sub

    Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoad.Click
        gate.Load("c:\test.xml")
    End Sub


#End Region

#Region "Other Routines"
    'Train the  network once, by using the inputs and output
    Sub TrainOnce()

        'Train the network using the training data, by passing
        'inputs and outputs to the train function of the gate

        'inp11, inp12, out1 etc are textbox names
        gate.Train(CLng(Me.inp11.Text), CLng(Me.inp12.Text), CLng(Me.out1.Text))
        gate.Train(CLng(Me.inp21.Text), CLng(Me.inp22.Text), CLng(Me.out2.Text))
        gate.Train(CLng(Me.inp31.Text), CLng(Me.inp32.Text), CLng(Me.out3.Text))
        gate.Train(CLng(Me.inp41.Text), CLng(Me.inp42.Text), CLng(Me.out4.Text))

    End Sub

#End Region



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)


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions