返回列表 上一主題 發帖

VBA 類神經運算 求助

回復 5# qwertyuio111
可否詳說, 類神經運算 公式的規律邏輯.
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 7# qwertyuio111


修改你的程式碼 試試看
  1. Option Explicit  '在模組層次中強迫每個在模組�堛瘍僂くㄔ眸楨�確的宣告
  2. Sub test()
  3.     Dim Sh As Worksheet, w(), i As Integer
  4.     Dim out As Single, ina1 As Single, inb1 As Single, ina2 As Single, outa2 As Single
  5.     Dim inc As Single, outc As Single, oute As Single, oute1 As Single, oute2 As Single
  6.     Dim inb2 As Single, outb2 As Single
  7.     Set Sh = Sheets("Sheet1")
  8.     out = Sh.Cells(1, 2)
  9.     ina1 = Sh.Cells(3, 2)
  10.     inb1 = Sh.Cells(5, 2)
  11.     w = Application.WorksheetFunction.Transpose(Sh.Range("b7").Resize(6))
  12.    
  13.     ina2 = (ina1 * w(3)) + (inb1 * w(4))
  14.     outa2 = 1 / (1 + Exp(-ina2))
  15.     inb2 = (ina1 * w(5)) + (inb1 * w(6))
  16.     outb2 = 1 / (1 + Exp(-inb2))
  17.     inc = (outa2 * w(1)) + (outb2 * w(2))
  18.     outc = 1 / (1 + Exp(-inc))
  19.     oute = (out - outc) * (1 - outc) * (outc)
  20.     w(1) = w(1) + (oute * outa2)
  21.     w(2) = w(2) + (oute * outb2)
  22.     oute1 = oute * w(1) * (1 - outa2) * outa2
  23.     oute2 = oute * w(2) * (1 - outb2) * outb2
  24.     w(3) = w(3) + (oute1 * ina1)
  25.     w(4) = w(4) + (oute1 * inb1)
  26.     w(5) = w(5) + (oute2 * ina1)
  27.     w(6) = w(6) + (oute2 * inb1)
  28. '***********************************************
  29.     For i = 2 To 300
  30.         ina2 = (ina1 * w(3)) + (inb1 * w(4))
  31.         outa2 = 1 / (1 + Exp(-ina2))
  32.         inb2 = (ina1 * w(5)) + (inb1 * w(6))
  33.         outb2 = 1 / (1 + Exp(-inb2))
  34.         inc = (outa2 * w(1)) + (outb2 * w(2))
  35.         outc = 1 / (1 + Exp(-inc))
  36.         oute = (out - outc) * (1 - outc) * (outc)
  37.         w(1) = w(1) + (oute * outa2)
  38.         w(2) = w(2) + (oute * outb2)
  39.         oute1 = oute * w(1) * (1 - outa2) * outa2
  40.         oute2 = oute * w(2) * (1 - outb2) * outb2
  41.         w(3) = w(3) + (oute1 * ina1)
  42.         w(4) = w(4) + (oute1 * inb1)
  43.         w(5) = w(5) + (oute2 * ina1)
  44.         w(6) = w(6) + (oute2 * inb1)
  45.     Next
  46.     ''''''''''''''''''''''''''''
  47.     With Sh
  48.         .Cells(14, 2) = ina2
  49.         .Cells(15, 2) = outa2
  50.         .Cells(17, 2) = inb2
  51.         .Cells(18, 2) = outb2
  52.         .Cells(20, 2) = inc
  53.         .Cells(21, 2) = outc
  54.         '''''''''''''''''''''''''''''
  55.         .Cells(23, 2) = oute
  56.         .Cells(25, 2) = w(1)
  57.         .Cells(26, 2) = w(2)
  58.         ''''''''''''''''''''''''
  59.         .Cells(29, 2) = oute1
  60.         .Cells(30, 2) = oute2
  61.         ''''''''''''''''''''
  62.         .Cells(32, 2) = w(3)
  63.         .Cells(33, 2) = w(4)
  64.         .Cells(34, 2) = w(5)
  65.         .Cells(35, 2) = w(6)
  66.     End With
  67. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題