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

📄 frmnet.frm

📁 VISUAL BASIC与MATLAB实现混合编程源代码
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      End
      Begin VB.VScrollBar VScroll1 
         Height          =   255
         Index           =   0
         Left            =   840
         TabIndex        =   2
         Top             =   600
         Width           =   255
      End
      Begin VB.TextBox txtNode 
         Height          =   285
         Index           =   0
         Left            =   120
         TabIndex        =   1
         Top             =   600
         Width           =   735
      End
      Begin VB.Label lblNode3 
         Caption         =   "输出层:"
         Height          =   255
         Index           =   1
         Left            =   2280
         TabIndex        =   12
         Top             =   360
         Width           =   615
      End
      Begin VB.Label lblNode2 
         Caption         =   "中间层:"
         Height          =   255
         Left            =   1200
         TabIndex        =   11
         Top             =   360
         Width           =   615
      End
      Begin VB.Label lblNode1 
         Caption         =   "输入层:"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   10
         Top             =   360
         Width           =   615
      End
   End
   Begin VB.Image Image1 
      Height          =   165
      Left            =   2040
      Picture         =   "frmNet.frx":289C
      Top             =   3120
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "数据项操作显示区"
      ForeColor       =   &H000000FF&
      Height          =   255
      Index           =   2
      Left            =   480
      TabIndex        =   46
      Top             =   3120
      Width           =   1575
   End
   Begin VB.Menu mnuNetwork 
      Caption         =   "网络(&N)"
      Begin VB.Menu mnuNew 
         Caption         =   "新建(&N)"
      End
      Begin VB.Menu mnuOpen 
         Caption         =   "打开(&O)"
      End
      Begin VB.Menu mnuSep 
         Caption         =   "-"
      End
      Begin VB.Menu mnuSave 
         Caption         =   "保存(&S)"
      End
      Begin VB.Menu mnuSaveas 
         Caption         =   "另存为(&A)"
      End
      Begin VB.Menu mnuSep2 
         Caption         =   "-"
      End
      Begin VB.Menu mnuExit 
         Caption         =   "退出(&E)"
      End
   End
   Begin VB.Menu mnuData 
      Caption         =   "数据(&D)"
      Begin VB.Menu mnuShowInTrainData 
         Caption         =   "显示输入样本数据(&I)"
      End
      Begin VB.Menu mnuShowOutTrainData 
         Caption         =   "显示输出样本数据(&O)"
      End
      Begin VB.Menu mnuShowTestData 
         Caption         =   "显示测试数据(&T)"
      End
      Begin VB.Menu mnuShowTestResult 
         Caption         =   "显示测试结果(&R)"
      End
      Begin VB.Menu mnuSep7 
         Caption         =   "-"
      End
      Begin VB.Menu mnuSaveData 
         Caption         =   "保存数据文件(&S)"
      End
   End
   Begin VB.Menu mnuTask 
      Caption         =   "任务(&T)"
      Begin VB.Menu mnuStartTrain 
         Caption         =   "开始训练(&S)"
      End
      Begin VB.Menu mnuStopTrain 
         Caption         =   "停止训练(&O)"
      End
      Begin VB.Menu mnuTest 
         Caption         =   "开始仿真(&M)"
      End
      Begin VB.Menu mnuSep3 
         Caption         =   "-"
      End
      Begin VB.Menu mnuUnitary 
         Caption         =   "归一化处理"
      End
   End
   Begin VB.Menu mnuView 
      Caption         =   "视图(&V)"
      Begin VB.Menu mnuErrorDis 
         Caption         =   "误差分析图(&C)"
      End
      Begin VB.Menu mnuSep5 
         Caption         =   "-"
      End
      Begin VB.Menu mnuOption 
         Caption         =   "选项(&O)"
      End
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "帮助(&H)"
      Begin VB.Menu mnuContent 
         Caption         =   "内容(&C)"
      End
      Begin VB.Menu mnuReg 
         Caption         =   "注册(R)"
      End
      Begin VB.Menu mnuSep6 
         Caption         =   "-"
      End
      Begin VB.Menu mnuAbout 
         Caption         =   "关于(A)"
      End
   End
End
Attribute VB_Name = "frmNetwork"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private OperIsNew As Boolean  '当前操作状态是否是新建网络模型
Private LmNet As nnToolKit.nnToolKit 'LmNet对象实例


Private Sub Form_Load()
    On Error GoTo Handle_Error
    Set LmNet = New nnToolKit.nnToolKit
    OperIsNew = True
    Exit Sub
Handle_Error:
    MsgBox (Err.Description)
End Sub

Private Sub mnuAbout_Click()
  frmAbout.Show
End Sub

Private Sub mnuExit_Click()
  Unload Me
End Sub


Private Sub mnuNew_Click()
  CBpnFile.Class_Initialize
  If OperIsNew <> True Then
    MsgBox ("是否保存现有的网络模型?")
  End If

  OperIsNew = True
  NetModel_Init
  If NetModel_Load() Then
    OperStatus_Show ("新建网络模型操作完成!")
  End If
End Sub

'打开现有网络文件
Private Sub mnuOpen_Click()
  Dim FileLength1 As String
  Dim FileLength2 As String
  
  On Error GoTo Handle_Error
  CBpnFile.Class_Initialize
  OperIsNew = False
  CommonDialog1.Filter = "神经网络模型文件(*.bpn)|*.bpn"
  CommonDialog1.ShowOpen
  BpnFileName = CommonDialog1.FileName
  FileName = CommonDialog1.FileTitle
  
  FileLength1 = Len(BpnFileName)
  FileLength2 = Len(FileName)
  FilePath = Left(BpnFileName, FileLength1 - FileLength2)
  FilePre = Left(FileName, FileLength2 - 4)
   
  '说明:下面文件中的"1"指的是当前模型编号为1,若用户要用到多个神经网络模型时,该外应该用一个变量来替代.
  InTrainFile = "input_para1.txt"
  OutTrainFile = "output_para1.txt"
  InSimuFile = "simu_data1.txt"
  OutSimuFile = "result1.dat"
  
  SpecifyBpn (BpnFileName)
  Nodes(0) = ReadInt("NetPara", "InputNum")
  Nodes(1) = ReadInt("NetPara", "OutputNum")
  Nodes(2) = ReadInt("NetPara", "MidNum")
  
  ModelNo = ReadInt("NetPara", "ModelNo")
  
  TrainSampleNum = ReadInt("OtherPara", "TrainSampleNum")
  SimuSampleNum = ReadInt("OtherPara", "SimuSampleNum")
  
  TransFunc(0) = ReadString("TrainPara", "inputFunc", 9)
  TransFunc(1) = ReadString("TrainPara", "outputFunc", 9)
  
  TrainPara(0) = ReadString("TrainPara", "df", 9)
  TrainPara(1) = ReadString("TrainPara", "me", 9)
  TrainPara(2) = ReadString("TrainPara", "eg", 9)
  TrainPara(3) = ReadString("TrainPara", "lr", 9)
  TrainPara(4) = ReadString("TrainPara", "lrInc", 9)
  TrainPara(5) = ReadString("TrainPara", "lrIdec", 9)
  TrainPara(6) = ReadString("TrainPara", "momConst", 9)
  TrainPara(7) = ReadString("TrainPara", "errRatio", 9)
  
  If NetModel_Load() Then
     OperStatus_Show ("打开现有网络模型操作完成!")
  Else
     ErrorMsg = "初始化神经网络模型失败!"
  End If
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuSave_Click()
  On Error GoTo Handle_Error
  If BpnFileName = vbNullString Then   '如果当前模型文件不存在
    CommonDialog1.Filter = "神经网络模型文件(*.bpn)|*.bpn"
    CommonDialog1.ShowSave
    BpnFileName = CommonDialog1.FileName
    NetFile_Create (BpnFileName)
  End If
  NetPara_Save
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub


Private Sub mnuSaveas_Click()
  On Error GoTo Handle_Error
  CommonDialog1.Filter = "神经网络模型文件(*.bpn)|*.bpn"
  CommonDialog1.ShowSave
  BpnFileName = CommonDialog1.FileName
  NetFile_Create (BpnFileName)
  NetPara_Save
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

'保存当前编辑的数据文件
Private Sub mnuSaveData_Click()
  On Error GoTo Handle_Error
  Dim fso As New FileSystemObject, fil As File
  fso.CreateTextFile FilePath + CurFileName
  rtxtShowResult.SaveFile CurFileName, rtfText
  MsgBox ("文件" + CurFileName + "保存成功!")
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuShowInTrainData_Click()
  On Error GoTo Handle_Error
  CurFileName = InTrainFile
  File_Show InTrainFile, "样本训练输入文件"
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuShowOutTrainData_Click()
  On Error GoTo Handle_Error
  CurFileName = OutTrainFile
  File_Show OutTrainFile, "样本训练输出文件"
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuShowTestData_Click()
  On Error GoTo Handle_Error
  CurFileName = InSimuFile
  File_Show InSimuFile, "测试数据文件"
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuShowTestResult_Click()
  File_Show FilePath + OutSimuFile, "仿真结果"
End Sub

Private Sub mnuStartTrain_Click()
  On Error GoTo Handle_Error
  '返回值
  Dim retstr As Variant
  '网络训练基本参数
  Dim NetTPara(4) As Double
  '模型编号
  Dim ModelNo As String
  '以下为示例参数,实际操作时要求从参数文件读出
  ModelNo = 1
  Nodes(0) = 7
  Nodes(1) = 1
  Nodes(2) = 28
  For i = 0 To 2
    NetTPara(i) = Nodes(i)
  Next
  NetTPara(3) = TrainSampleNum  '样本个数

  '网络训练调用参数说明
  '1,一个返回参数
  'retstr,返回值
  '网络模型基本参数,Variant
  '神经网络参数,Double,包括输入层节点数;输出层节点数;中间层节点数;网络训练样本个数。
  '神经网络训练参数,若为“-1”表示选择默认参数
  '网络仿真时输入层至中间层的传递函数
  '网络仿真时中间层至输出层的传递函数
  '程序运行时的当前目录
  Call LmNet.lmtrain(1, retstr, ModelNo, NetTPara, -1, TransFunc(0), TransFunc(1), FilePath)
  MsgBox ("训练完成,您现在可以进行仿真操作了!")
  OperStatus_Show ("训练完成,您现在可以进行仿真操作了!")
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

'网络仿真
Private Sub mnuTest_Click()
  '神经网络仿真参数
  Dim SimulatePara(7) As Double
  '模型编号
  Dim ModelNo As String
  ModelNo = "1"
  Dim fso As New FileSystemObject, fil As File, ts As TextStream
  On Error GoTo Handle_Error
  
  Set fil = fso.GetFile(FilePath + InSimuFile)
  Set ts = fil.OpenAsTextStream(ForReading)
  DataLine = ts.ReadLine
  DataLength = Len(DataLine)
  For i = 0 To Nodes(0) - 1
    SimulatePara(i) = Trim(Left(DataLine, 5))
    DataLength = Len(DataLine)
    DataLine = Trim(Right(DataLine, DataLength - 5))
    
  Next
  ts.Close
  
  'SimulatePara(0) = 0.9
  'SimulatePara(1) = 0.9
  'SimulatePara(2) = 0.063
  'SimulatePara(3) = 0.9
  'SimulatePara(4) = 0.025
  'SimulatePara(5) = 0.467
  'SimulatePara(6) = 0.9

  '网络仿真调用参数说明
  '1,一个返回参数
  'retstr,返回值
  '网络模型基本参数,Variant
  '神经网络参数,Double,包括输入层节点数;输出层节点数;中间层节点数
  '神经网络仿真参数,若为“-1”表示选择默认参数
  '网络仿真时输入层至中间层的传递函数
  '网络仿真时中间层至输出层的传递函数
  '程序运行时的当前目录
  Call LmNet.lmsimu(1, retstr, ModelNo, Nodes, SimulatePara, TransFunc(0), TransFunc(1), FilePath)
  OperStatus_Show ("仿真成功,点击‘数据/显示测试结果’查看仿真结果!")
  MsgBox ("仿真成功,点击‘数据/显示测试结果’查看仿真结果!")
  
  Exit Sub
Handle_Error:
  MsgBox (Err.Description)
End Sub

Private Sub mnuUnitary_Click()
  frmUnitary.cbNodeNo.AddItem "1", 0
  frmUnitary.cbNodeNo.AddItem "2", 1
  frmUnitary.cbChgFunc.AddItem "对数转换函数", 0
  frmUnitary.cbChgFunc.AddItem "反正切转换函数", 1
  
  
  frmUnitary.Show
End Sub


⌨️ 快捷键说明

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