📄 bp算法.frm
字号:
VERSION 5.00
Begin VB.Form FrmBp
AutoRedraw = -1 'True
Caption = "Bp算法"
ClientHeight = 7005
ClientLeft = 60
ClientTop = 345
ClientWidth = 9465
FillColor = &H000000C0&
ForeColor = &H000000FF&
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 7005
ScaleWidth = 9465
Begin VB.TextBox Txt7
Height = 375
Left = 6840
TabIndex = 24
Top = 4800
Width = 1455
End
Begin VB.TextBox Text2
Enabled = 0 'False
Height = 375
Left = 2760
TabIndex = 22
Top = 5520
Width = 1935
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 405
Left = 2760
TabIndex = 19
Top = 4800
Width = 1935
End
Begin VB.TextBox Txt6
Height = 375
Left = 6840
TabIndex = 18
Top = 4200
Width = 1335
End
Begin VB.TextBox Txt5
Height = 375
Left = 6840
TabIndex = 17
Top = 3360
Width = 1335
End
Begin VB.TextBox Txt4
Height = 375
Left = 6840
TabIndex = 6
Top = 2760
Width = 1335
End
Begin VB.ListBox LstValueVar
Height = 3375
Left = 3120
TabIndex = 14
Top = 600
Width = 1695
End
Begin VB.CommandButton CmdSelect
Caption = "=>"
Height = 495
Left = 2160
TabIndex = 11
Top = 1680
Width = 735
End
Begin VB.ListBox LstAllVar
Height = 3570
Left = 240
TabIndex = 10
Top = 600
Width = 1695
End
Begin VB.CommandButton CmdCancel
Caption = "取消"
Height = 495
Left = 7080
TabIndex = 8
Top = 5880
Width = 1095
End
Begin VB.CommandButton CmdRun
Caption = "运行"
Height = 495
Left = 5400
TabIndex = 7
Top = 5880
Width = 1215
End
Begin VB.TextBox Txt3
Height = 375
Left = 6840
TabIndex = 4
Top = 2160
Width = 1335
End
Begin VB.TextBox Txt2
Height = 375
Left = 6840
TabIndex = 2
Top = 1440
Width = 1335
End
Begin VB.TextBox Txt1
Height = 375
Left = 6840
TabIndex = 12
Top = 600
Width = 1335
End
Begin VB.Label Lab11
Caption = "收敛误差精度"
Height = 495
Left = 5280
TabIndex = 23
Top = 4920
Width = 1215
End
Begin VB.Label Lab10
Caption = "输出终止时的全局误差:"
Height = 375
Left = 600
TabIndex = 21
Top = 5520
Width = 2175
End
Begin VB.Label Lab9
Caption = "输出终止时迭代次数:"
Height = 375
Left = 600
TabIndex = 20
Top = 4920
Width = 1815
End
Begin VB.Label Lab8
Caption = "学习算子b:"
Height = 495
Left = 5280
TabIndex = 16
Top = 4200
Width = 1215
End
Begin VB.Label Lab7
Caption = "动力矩a:"
Height = 375
Left = 5280
TabIndex = 15
Top = 3480
Width = 975
End
Begin VB.Label Lab1
Caption = "隐单元层数"
Height = 255
Left = 5280
TabIndex = 0
Top = 720
Width = 1095
End
Begin VB.Label Lab6
Caption = "入选的学习例子:"
Height = 375
Left = 3120
TabIndex = 13
Top = 240
Width = 1455
End
Begin VB.Label Lab5
Caption = "原始数据:"
Height = 375
Left = 360
TabIndex = 9
Top = 240
Width = 1335
End
Begin VB.Label Lab4
Caption = "隐单元层的单元数"
Height = 375
Left = 5280
TabIndex = 5
Top = 2760
Width = 1455
End
Begin VB.Label Lab3
Caption = "输出层的单元数"
Height = 375
Left = 5280
TabIndex = 3
Top = 2160
Width = 1455
End
Begin VB.Label Lab2
Caption = "输入层的单元数"
Height = 375
Left = 5280
TabIndex = 1
Top = 1440
Width = 1455
End
End
Attribute VB_Name = "FrmBp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim flag As Long
Private Sub CmdCancel_Click()
Unload FrmBp
End Sub
Private Sub CmdRun_Click()
'传递窗口值
text1.Text = ""
Text2.Text = ""
Dim m As Long
Dim i As Long
Dim ValueVarName() As String
m = LstValueVar.ListCount '所选变量的个数
If LstValueVar.ListCount = 0 Then
MsgBox ("请选择样本值!")
Exit Sub
End If
ReDim ValueVarName(m) As String
For i = 1 To m
ValueVarName(i) = LstValueVar.List(i - 1) '传递样本值所在的列数
Next i
Dim t As Integer '隐单元层数
Dim n As Integer '输入层的单元数
Dim q As Integer '输出层的单元数
Dim p As Integer '隐单元层的单元数
Dim a1 As Double
Dim b1 As Double
Dim StandardE As Double '收敛误差精度
If Txt1.Text = "" Then
MsgBox ("请输入隐单元层数!")
Exit Sub
End If
If Txt2.Text = "" Then
MsgBox ("请输入输入层的单元数!")
Exit Sub
End If
If Txt3.Text = "" Then
MsgBox ("请输入输出层的单元数!")
Exit Sub
End If
If Txt4.Text = "" Then
MsgBox ("请输入隐单元层的单元数!")
Exit Sub
End If
If Txt5.Text = "" Then
MsgBox ("请输入学习因子a1")
Exit Sub
End If
If Txt6.Text = "" Then
MsgBox ("请输入b1")
Exit Sub
End If
If Txt7.Text = "" Then
MsgBox ("请输入收敛误差精度!")
Exit Sub
End If
If IsNumeric(Txt1.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt2.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt3.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt4.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt5.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt6.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
If IsNumeric(Txt7.Text) = False Then
MsgBox ("必须为数字!")
Exit Sub
End If
t = Txt1.Text
n = Txt2.Text
q = Txt3.Text
p = Txt4.Text
a1 = Txt5.Text
b1 = Txt6.Text
StandardE = Txt7.Text
If t < 1 Then
MsgBox ("隐单元层数必须大于1")
Exit Sub
End If
If n < 1 Then
MsgBox ("输入层单元数必须大于1")
Exit Sub
End If
If q < 1 Then
MsgBox ("输出层单元数必须大于1")
Exit Sub
End If
If q < 1 Then
MsgBox ("隐单元层单元数必须大于1")
Exit Sub
End If
'调第一级,读数据
Call ReadData(ValueVarName(), m, t, n, q, p, a1, b1, StandardE)
' Unload Me
End Sub
'第一级
Function ReadData(ValueVarName() As String, m As Long, t As Integer, n As Integer, q As Integer, p As Integer, a1 As Double, b1 As Double, StandardE As Double)
Dim row As Long
Dim ValueVar() As String
Dim ValueNo() As Long
Dim i As Integer
Dim j As Integer
row = FrmData.DataTab.Rows - 6
If n + q > row Then
MsgBox ("输入输出层的单元数之和大于提供的数据!")
Txt2.Text = ""
Txt3.Text = ""
Exit Function
End If
ReDim ValueVar(1 To row, 1 To m)
ReDim ValueNo(m) As Long
For i = 1 To m
ValueNo(i) = FuncGetVarPosition(ValueVarName(i)) '样品的列号
Next i
For i = 1 To row
For j = 1 To m
ValueVar(i, j) = CStr(FrmData.DataTab1.TextMatrix(i, ValueNo(j)))
Next j
Next i
flag = 0
Call Bp(ValueVar(), m, t, n, q, p, a1, b1, StandardE)
If flag = 1 Then
Exit Function
End If
End Function
Function Bp(ValueVar() As String, m As Long, t As Integer, n As Integer, q As Integer, p As Integer, a1 As Double, b1 As Double, StandardE As Double)
Dim W() As Double '输入层至中间层的连接权
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -