⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmgate.vb

📁 neural networks applications
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -