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

📄 frmmain.frm

📁 这是一种利用bp神经网络来解决异或问题的算法.
💻 FRM
📖 第 1 页 / 共 2 页
字号:
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FFC0C0&
         Height          =   255
         Left            =   360
         TabIndex        =   19
         Top             =   1920
         Width           =   255
      End
      Begin VB.Label Label11 
         BackStyle       =   0  'Transparent
         Caption         =   "1"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FFC0C0&
         Height          =   255
         Left            =   720
         TabIndex        =   18
         Top             =   1920
         Width           =   255
      End
      Begin VB.Label Label12 
         BackStyle       =   0  'Transparent
         Caption         =   "0"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FFC0C0&
         Height          =   255
         Left            =   1080
         TabIndex        =   17
         Top             =   1920
         Width           =   255
      End
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00000000&
      Caption         =   "Network State"
      ForeColor       =   &H00FFC0C0&
      Height          =   4455
      Left            =   2400
      TabIndex        =   3
      Top             =   2280
      Width           =   2415
      Begin VB.PictureBox picOutputsDesired 
         BackColor       =   &H00C00000&
         Height          =   375
         Left            =   1320
         ScaleHeight     =   315
         ScaleWidth      =   795
         TabIndex        =   14
         Top             =   3840
         Width           =   855
      End
      Begin VB.PictureBox picOutputs 
         BackColor       =   &H00C00000&
         Height          =   375
         Left            =   1320
         ScaleHeight     =   315
         ScaleWidth      =   795
         TabIndex        =   12
         Top             =   3360
         Width           =   855
      End
      Begin VB.PictureBox picHiddens 
         BackColor       =   &H00C00000&
         Height          =   375
         Left            =   1320
         ScaleHeight     =   315
         ScaleWidth      =   795
         TabIndex        =   10
         Top             =   1920
         Width           =   855
      End
      Begin VB.PictureBox picInputs 
         BackColor       =   &H00C00000&
         Height          =   375
         Left            =   1320
         ScaleHeight     =   315
         ScaleWidth      =   795
         TabIndex        =   8
         Top             =   480
         Width           =   855
      End
      Begin VB.PictureBox picOutputWeights 
         BackColor       =   &H00C00000&
         Height          =   615
         Left            =   1320
         ScaleHeight     =   555
         ScaleWidth      =   795
         TabIndex        =   5
         Top             =   2520
         Width           =   855
      End
      Begin VB.PictureBox picHiddenWeights 
         BackColor       =   &H00C00000&
         Height          =   615
         Left            =   1320
         ScaleHeight     =   555
         ScaleWidth      =   795
         TabIndex        =   4
         Top             =   1080
         Width           =   855
      End
      Begin VB.Label Label18 
         BackStyle       =   0  'Transparent
         Caption         =   "Desired Outputs"
         ForeColor       =   &H00FFC0C0&
         Height          =   375
         Left            =   240
         TabIndex        =   15
         Top             =   3840
         Width           =   975
      End
      Begin VB.Label Label17 
         BackStyle       =   0  'Transparent
         Caption         =   "Output Units (2)"
         ForeColor       =   &H00FFC0C0&
         Height          =   375
         Left            =   240
         TabIndex        =   13
         Top             =   3360
         Width           =   975
      End
      Begin VB.Label Label16 
         BackStyle       =   0  'Transparent
         Caption         =   "Hidden Units (2)"
         ForeColor       =   &H00FFC0C0&
         Height          =   375
         Left            =   240
         TabIndex        =   11
         Top             =   1920
         Width           =   975
      End
      Begin VB.Label Label15 
         BackStyle       =   0  'Transparent
         Caption         =   "Input Units (2)"
         ForeColor       =   &H00FFC0C0&
         Height          =   375
         Left            =   240
         TabIndex        =   9
         Top             =   480
         Width           =   975
      End
      Begin VB.Label Label13 
         BackStyle       =   0  'Transparent
         Caption         =   "Output Layer Weights"
         ForeColor       =   &H00FFC0C0&
         Height          =   495
         Left            =   240
         TabIndex        =   7
         Top             =   2520
         Width           =   975
      End
      Begin VB.Label Label14 
         BackStyle       =   0  'Transparent
         Caption         =   "Hidden Layer Weights"
         ForeColor       =   &H00FFC0C0&
         Height          =   495
         Left            =   240
         TabIndex        =   6
         Top             =   1080
         Width           =   975
      End
   End
   Begin VB.TextBox txtCycles 
      Enabled         =   0   'False
      Height          =   285
      Left            =   3480
      TabIndex        =   2
      Text            =   "0"
      Top             =   960
      Width           =   1335
   End
   Begin VB.TextBox txtBPerror 
      Enabled         =   0   'False
      Height          =   285
      Left            =   3480
      TabIndex        =   1
      Text            =   "0"
      Top             =   1680
      Width           =   1335
   End
   Begin VB.CommandButton cmdTrain 
      Caption         =   "Begin Training"
      Height          =   615
      Left            =   240
      TabIndex        =   0
      Top             =   720
      Width           =   1455
   End
   Begin VB.Image Image1 
      Height          =   1980
      Left            =   240
      Picture         =   "frmMain.frx":0000
      Stretch         =   -1  'True
      Top             =   4800
      Width           =   2100
   End
   Begin VB.Label Label27 
      BackStyle       =   0  'Transparent
      Caption         =   "Random Noise"
      ForeColor       =   &H00FFC0C0&
      Height          =   255
      Left            =   1920
      TabIndex        =   39
      Top             =   1440
      Width           =   1335
   End
   Begin VB.Label Label26 
      BackStyle       =   0  'Transparent
      Caption         =   "Learning Rate"
      ForeColor       =   &H00FFC0C0&
      Height          =   255
      Left            =   1920
      TabIndex        =   37
      Top             =   720
      Width           =   1335
   End
   Begin VB.Label Label25 
      BackStyle       =   0  'Transparent
      Caption         =   "Network Error"
      ForeColor       =   &H00FFC0C0&
      Height          =   255
      Left            =   3480
      TabIndex        =   35
      Top             =   1440
      Width           =   1335
   End
   Begin VB.Label Label24 
      BackStyle       =   0  'Transparent
      Caption         =   "Training Itterations"
      ForeColor       =   &H00FFC0C0&
      Height          =   255
      Left            =   3480
      TabIndex        =   34
      Top             =   720
      Width           =   1335
   End
   Begin VB.Label Label23 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "Learning the XOR rule"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF8080&
      Height          =   495
      Left            =   120
      TabIndex        =   33
      Top             =   120
      Width           =   4815
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim bp As New ClassBackprop
Dim finished As Boolean
Const STATE_FALSE = 0.2
Const STATE_TRUE = 0.8


Private Sub cmdStop_Click()
 finished = True
End Sub

Private Sub cmdTrain_Click()
  Call trainXOR
End Sub

Private Sub trainXOR()
  Dim i As Long
  Dim j As Integer
  
  Randomize
  
  'set the learning rate
  bp.learningRate = txtLearningRate
  bp.randomness = txtRandomNoise
  
  j = 0
  finished = False
  While (Not finished)
    DoEvents
    
    Select Case j
      Case 0
        Call bp.setInput(0, STATE_FALSE)
        Call bp.setInput(1, STATE_FALSE)
        Call bp.setClassification(0)
      Case 1
        Call bp.setInput(0, STATE_FALSE)
        Call bp.setInput(1, STATE_TRUE)
        Call bp.setClassification(1)
      Case 2
        Call bp.setInput(0, STATE_TRUE)
        Call bp.setInput(1, STATE_FALSE)
        Call bp.setClassification(1)
      Case 3
        Call bp.setInput(0, STATE_TRUE)
        Call bp.setInput(1, STATE_TRUE)
        Call bp.setClassification(0)
    End Select
    
    'train
    Call bp.update
    txtBPerror = bp.BPerror
    txtBPerror.Refresh
    txtCycles = i
    txtCycles.Refresh
    
    lblOutput(j).Caption = bp.getClassification
    If (lblOutput(0).Caption = 0) And (lblOutput(1).Caption = 1) And (lblOutput(2).Caption = 1) And (lblOutput(3).Caption = 0) Then
      MsgBox "Learning Complete", , ""
      finished = True
    End If
    
    Call bp.showNeurons(picInputs, 0)
    Call bp.showWeights(picHiddenWeights, 1)
    Call bp.showNeurons(picHiddens, 1)
    Call bp.showWeights(picOutputWeights, 3)
    Call bp.showNeurons(picOutputs, 3)
    Call bp.showNeurons(picOutputsDesired, 4)
    
    j = j + 1
    If (j > 3) Then
      j = 0
    End If
    
    i = i + 1
  Wend
  
End Sub

Private Sub Form_Load()
  Call bp.init(2, 2, 2)
End Sub


Private Sub txtLearningRate_KeyPress(KeyAscii As Integer)
  If (KeyAscii = 13) Then
    If (txtLearningRate > 1) Then
      txtLearningRate = 1
    End If
    If (txtLearningRate < 0) Then
      txtLearningRate = 0
    End If
  End If
End Sub


Private Sub txtRandomNoise_KeyPress(KeyAscii As Integer)
  If (KeyAscii = 13) Then
    If (txtRandomNoise > 0.5) Then
      txtRandomNoise = 0.5
    End If
    If (txtRandomNoise < 0) Then
      txtRandomNoise = 0
    End If
  End If
End Sub

⌨️ 快捷键说明

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