ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

VBA Ãþ¯«¸g¹Bºâ ¨D§U

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2015-11-24 11:32 ½s¿è

¦^´_ 7# qwertyuio111
¸Õ¸Õ¬Ý (¨Ì¾Ú§Aªºµ{¦¡½X­×§ï)¡G
  1. Sub Ãþ¯«¸g¹Bºâ()
  2.     Dim lowerRange, upperRange, myRange, myCell As Range, cts As Integer, nxt As Integer
  3.     Dim rp5 As Integer, bf1 As Integer
  4.    
  5.     With Sheets("Sheet1")
  6.         Set lowerRange = .Range("C11")
  7.         Set upperRange = .Range("C10")
  8.         lowerRange.Name = "lowerbound"
  9.         upperRange.Name = "upperbound"
  10.         Set myRange = .Range("A13:J21")

  11.         For Each myCell In myRange
  12.             myCell.Formula = "=RANDBETWEEN(lowerbound,upperbound)/10"
  13.         Next
  14.    
  15.        .[A23] = "´`Àô¢å"
  16.            
  17.        For cts = 0 To 7     '  inta1 = (intA * w1) + (intB * w9) + (intc * w17) + (intD * w25) + (intE * w33)
  18.            .[D1].Offset(cts) = (.[B1] * .[A13].Offset(cts)) + (.[B2] * IIf(cts = 0, .[A21], .[B12].Offset(cts))) + (.[B3] * IIf(cts <= 1, .[B20], .[C11].Offset(cts)) + (.[B4] * IIf(cts <= 2, .[C19], .[D10].Offset(cts)))) + (.[B5] * IIf(cts <= 3, .[D18], .[E9].Offset(cts)))
  19.            .[F1].Offset(cts) = 1 / (1 + Exp(-.[D1].Offset(cts)))   '  outa1 = 1 / (1 + Exp(-inta1))
  20.        Next cts

  21.        For cts = 0 To 4     '  inti1 = (outa1 * w41) + (outb1 * w46) + (outc1 * w51) + (outd1 * w56) + (oute1 * w61) + (outf1 * w66) + (outg1 * w71) + (outh1 * w76)
  22.            .[H1].Offset(cts) = (.[F1] * .[E17].Offset(cts)) + (.[F2] * .[F13].Offset(cts)) + (.[F3] * IIf(cts = 4, .[G13], .[F18].Offset(cts))) + (.[F4] * .[G14].Offset(cts)) + (.[F5] * IIf(cts > 2, .[H10].Offset(cts), .[G19].Offset(cts))) + (.[F6] * .[H15].Offset(cts)) + (.[F7] * IIf(cts > 1, .[I11].Offset(cts), .[H20].Offset(cts))) + (.[F8] * .[I16].Offset(cts))
  23.            .[J1].Offset(cts) = 1 / (1 + Exp(-.[H1].Offset(cts)))     '  outi1 = 1 / (1 + Exp(-inti1))
  24.        Next cts
  25.    
  26.        For cts = 0 To 1     '  intn1 = (outi1 * w81) + (outj1 * w83) + (outk1 * w85) + (outl1 * w87) + (outm1 * w89)
  27.            .[L1].Offset(cts) = (.[J1] * IIf(cts = 0, .[I21], .[J13])) + (.[J2] * .[J14].Offset(cts)) + (.[J3] * .[J16].Offset(cts)) + (.[J4] * .[J18].Offset(cts)) + (.[J5] * .[J20].Offset(cts))
  28.            .[N1].Offset(cts) = 1 / (1 + Exp(-.[L1].Offset(cts)))     '  outn1 = 1 / (1 + Exp(-intn1))
  29.        Next cts
  30.       
  31.        For cts = 0 To 1     '  errn = outn1 * (1 - outn1) * (tarn - outn1) ,   erro = outo1 * (1 - outo1) * (taro - outo1)
  32.            .[N5].Offset(cts) = .[N1].Offset(cts) * (1 - .[N1].Offset(cts)) * (.[L6].Offset(cts) - .[N1].Offset(cts))
  33.        Next cts
  34.       
  35.        For cts = 0 To 4     '  erri = outi1 * (1 - outi1) * (errn * w81 + erro * w82)   ~   errm = outm1 * (1 - outm1) * (errn * w89 + erro * w90)
  36.            .[P5].Offset(cts) = .[J1].Offset(cts) * (1 - .[J1].Offset(cts)) * (.[N5] * IIf(cts = 0, .[I21], .[J9].Offset(cts * 2 + 1))) + (.[N6] * .[J11].Offset(cts * 2 + 2))
  37.        Next cts
  38.       
  39.        For cts = 0 To 7     '  erra = outa1 * (1 - outa1) * (erri * w41 + errj * w42 + errk * w43 + errl * w44 + errm * w45)
  40.             .Range("Z1:Z5").Clear    '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È
  41.             
  42.             If (cts = 7) Then       '  7
  43.                .[Z1] = .[I16]
  44.                .[Z2] = .[I17]
  45.             ElseIf (cts > 4) Then   '  5,6
  46.                .[Z1] = .[H15].Offset((cts - 5) * 5)
  47.                .[Z2] = .[H16].Offset((cts - 5) * 5)
  48.             ElseIf (cts > 2) Then   '  3,4
  49.                .[Z1] = .[G14].Offset((cts - 3) * 5)
  50.                .[Z2] = .[G15].Offset((cts - 3) * 5)
  51.             ElseIf (cts = 0) Then   '  0
  52.                .[Z1] = .[E17]
  53.                .[Z2] = .[E18]
  54.                .[Z3] = .[E19]
  55.             Else                    '  1,2
  56.                .[Z1] = .[F13].Offset((cts - 1) * 5)
  57.                .[Z2] = .[F14].Offset((cts - 1) * 5)
  58.             End If

  59.             If (cts > 5) Then       '  6,7
  60.                .[Z3] = .[I13].Offset((cts - 6) * 5)
  61.                .[Z4] = .[I14].Offset((cts - 6) * 5)
  62.                .[Z5] = .[I15].Offset((cts - 6) * 5)
  63.             ElseIf (cts = 5) Then   '  5
  64.                .[Z3] = .[H17]
  65.                .[Z4] = .[H13].Offset((cts - 5) * 5)
  66.                .[Z5] = .[H14].Offset((cts - 5) * 5)
  67.             ElseIf (cts > 3) Then    '  4
  68.                .[Z3] = .[G16].Offset((cts - 4) * 5)
  69.                .[Z4] = .[H13].Offset((cts - 4) * 5)
  70.                .[Z5] = .[H14].Offset((cts - 4) * 5)
  71.             ElseIf (cts = 3) Then    '  3
  72.                .[Z3] = .[G16].Offset((cts - 3) * 5)
  73.                .[Z4] = .[G15]
  74.                .[Z5] = .[H14].Offset((cts - 3) * 5)
  75.             ElseIf (cts > 1) Then    '  2
  76.                .[Z3] = .[F15].Offset((cts - 2) * 5)
  77.                .[Z4] = .[F16].Offset((cts - 2) * 5)
  78.                .[Z5] = .[G13].Offset((cts - 2) * 5)
  79.             ElseIf (cts = 0) Then    '  0
  80.                .[Z3] = .[E19]
  81.                .[Z4] = .[E20]
  82.                .[Z5] = .[E21]
  83.             Else                      '  1
  84.                .[Z3] = .[F15].Offset((cts - 1) * 5)
  85.                .[Z4] = .[F16].Offset((cts - 1) * 5)
  86.                .[Z5] = .[F17]
  87.             End If
  88.             
  89.             
  90.             .[R5].Offset(cts) = .[F1].Offset(cts) * (1 - .[F1].Offset(cts)) * (.[P5] * .[Z1] + .[P6] * .[Z2] + .[P7] * .[Z3] + .[P8] * .[Z4] + .[P9] * .[Z5])
  91.             '  ÀËÅç´ú¸Õµ²ªG
  92.             '  .[V10].Offset(cts) = .[Z1]
  93.             '  .[V10].Offset(cts, 1) = .[Z2]
  94.             '  .[V10].Offset(cts, 2) = .[Z3]
  95.             '  .[V10].Offset(cts, 3) = .[Z4]
  96.             '  .[V10].Offset(cts, 4) = .[Z5]
  97.        Next cts
  98.    
  99.        .Range("Z1:Z5").Clear         '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È
  100.        '  .Range("V10:Z17").Clear    '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È

  101.        rp5 = -1: bf1 = 0
  102.        For nxt = 0 To 9         '  neww1 = w1 + (erra * intA)   ~  neww54 = w54 + (errl * outc1)
  103.            For cts = 0 To 8
  104.                rp5 = rp5 + 1

  105.                If ((nxt * 9 + cts + 1) > 80) Then          '  neww81 = w81 + (errn * outi1) ~ neww90 = w90 + (erro * outm1)
  106.                    If ((nxt * 9 + cts + 1) = 81) Then
  107.                        rp5 = 0
  108.                        bf1 = 0
  109.                    End If
  110.                   
  111.                    .[A24].Offset(cts, nxt) = .[A13].Offset(cts) + (.[N5].Offset(rp5) * .[J1].Offset(bf1))
  112.                   
  113.                    If (rp5 = 1) Then
  114.                        rp5 = -1
  115.                        bf1 = bf1 + 1
  116.                    End If
  117.                ElseIf ((nxt * 9 + cts + 1) > 40) Then      '  neww41 = w41 + (erri * outa1) ~ neww80 = w80 + (errm * outh1)
  118.                    If ((nxt * 9 + cts + 1) = 41) Then
  119.                        rp5 = 0
  120.                        bf1 = 0
  121.                    End If
  122.                   
  123.                    .[A24].Offset(cts, nxt) = .[A13].Offset(cts) + (.[P5].Offset(rp5) * .[F1].Offset(bf1))
  124.                   
  125.                    If (rp5 = 4) Then
  126.                        rp5 = -1
  127.                        bf1 = bf1 + 1
  128.                    End If
  129.                Else                                        '  neww1 = w1 + (erra * intA) ~ neww40 = w40 + (errh * intE)
  130.                    .[A24].Offset(cts, nxt) = .[A13].Offset(cts) + (.[R5].Offset(rp5) * .[B1].Offset(bf1))
  131.                   
  132.                    If (rp5 = 7) Then
  133.                        rp5 = -1
  134.                        bf1 = bf1 + 1
  135.                    End If
  136.                End If
  137.            Next cts
  138.        Next nxt
  139.    End With
  140.   Ãþ¯«¸gÂX¥R°j°é¹Bºâ
  141. End Sub
½Æ»s¥N½X

TOP

¦^´_ 7# qwertyuio111
  1. Sub Ãþ¯«¸gÂX¥R°j°é¹Bºâ()
  2.     Dim cts As Integer, nxt As Integer
  3.     Dim rp5 As Integer, bf1 As Integer, i As Integer
  4.    
  5.     With Sheets("Sheet1")
  6.        For i = 2 To 150    ' 1500
  7.            .[A23] = "´`Àô¢å (" & i & ")"
  8.            For cts = 0 To 7     '  inta1 = (intA * neww1) + (intB * neww9) + (intc * neww17) + (intD * neww25) + (intE * neww33)
  9.                .[D1].Offset(cts) = (.[B1] * .[A24].Offset(cts)) + (.[B2] * IIf(cts = 0, .[A32], .[B23].Offset(cts))) + (.[B3] * IIf(cts <= 1, .[B31], .[C22].Offset(cts)) + (.[B4] * IIf(cts <= 2, .[C30], .[D21].Offset(cts)))) + (.[B5] * IIf(cts <= 3, .[D29], .[E20].Offset(cts)))
  10.                .[F1].Offset(cts) = 1 / (1 + Exp(-.[D1].Offset(cts)))   '  outa1 = 1 / (1 + Exp(-inta1))
  11.            Next cts

  12.            For cts = 0 To 4     '  inti1 = (outa1 * neww41) + (outb1 * neww46) + (outc1 * neww51) + (outd1 * neww56) + (oute1 * neww61) + (outf1 * neww66) + (outg1 * neww71) + (outh1 * neww76)
  13.            .[H1].Offset(cts) = (.[F1] * .[E28].Offset(cts)) + (.[F2] * .[F24].Offset(cts)) + (.[F3] * IIf(cts = 4, .[G24], .[F29].Offset(cts))) + (.[F4] * .[G25].Offset(cts)) + (.[F5] * IIf(cts > 2, .[H21].Offset(cts), .[G30].Offset(cts))) + (.[F6] * .[H26].Offset(cts)) + (.[F7] * IIf(cts > 1, .[I22].Offset(cts), .[H31].Offset(cts))) + (.[F8] * .[I27].Offset(cts))
  14.                .[J1].Offset(cts) = 1 / (1 + Exp(-.[H1].Offset(cts)))     '  outi1 = 1 / (1 + Exp(-inti1))
  15.            Next cts
  16.    
  17.            For cts = 0 To 1     '  intn1 = (outi1 * neww81) + (outj1 * neww83) + (outk1 * neww85) + (outl1 * neww87) + (outm1 * neww89)
  18.                .[L1].Offset(cts) = (.[J1] * IIf(cts = 0, .[I32], .[J24])) + (.[J2] * .[J25].Offset(cts)) + (.[J3] * .[J27].Offset(cts)) + (.[J4] * .[J29].Offset(cts)) + (.[J5] * .[J31].Offset(cts))
  19.                .[N1].Offset(cts) = 1 / (1 + Exp(-.[L1].Offset(cts)))     '  outn1 = 1 / (1 + Exp(-intn1))
  20.            Next cts
  21.       
  22.            For cts = 0 To 1     '  errn = outn1 * (1 - outn1) * (tarn - outn1) ,   erro = outo1 * (1 - outo1) * (taro - outo1)
  23.                .[N5].Offset(cts) = .[N1].Offset(cts) * (1 - .[N1].Offset(cts)) * (.[L6].Offset(cts) - .[N1].Offset(cts))
  24.            Next cts
  25.       
  26.            For cts = 0 To 4     '  erri = outi1 * (1 - outi1) * (errn * neww81 + erro * neww82)   ~   errm = outm1 * (1 - outm1) * (errn * neww89 + erro * neww90)
  27.                .[P5].Offset(cts) = .[J1].Offset(cts) * (1 - .[J1].Offset(cts)) * (.[N5] * IIf(cts = 0, .[I32], .[J20].Offset(cts * 2 + 1))) + (.[N6] * .[J22].Offset(cts * 2 + 2))
  28.            Next cts
  29.       
  30.            For cts = 0 To 7     '  erra = outa1 * (1 - outa1) * (erri * w41 + errj * w42 + errk * w43 + errl * w44 + errm * w45)
  31.                 .Range("Z1:Z5").Clear    '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È
  32.             
  33.                 If (cts = 7) Then       '  7
  34.                    .[Z1] = .[I27]
  35.                    .[Z2] = .[I28]
  36.                 ElseIf (cts > 4) Then   '  5,6
  37.                    .[Z1] = .[H26].Offset((cts - 5) * 5)
  38.                    .[Z2] = .[H27].Offset((cts - 5) * 5)
  39.                 ElseIf (cts > 2) Then   '  3,4
  40.                    .[Z1] = .[G25].Offset((cts - 3) * 5)
  41.                    .[Z2] = .[G26].Offset((cts - 3) * 5)
  42.                 ElseIf (cts = 0) Then   '  0
  43.                    .[Z1] = .[E28]
  44.                    .[Z2] = .[E29]
  45.                    .[Z3] = .[E30]
  46.                 Else                    '  1,2
  47.                    .[Z1] = .[F24].Offset((cts - 1) * 5)
  48.                    .[Z2] = .[F25].Offset((cts - 1) * 5)
  49.                 End If

  50.                 If (cts > 5) Then       '  6,7
  51.                    .[Z3] = .[I24].Offset((cts - 6) * 5)
  52.                    .[Z4] = .[I25].Offset((cts - 6) * 5)
  53.                    .[Z5] = .[I26].Offset((cts - 6) * 5)
  54.                 ElseIf (cts = 5) Then   '  5
  55.                    .[Z3] = .[H28]
  56.                    .[Z4] = .[H24].Offset((cts - 5) * 5)
  57.                    .[Z5] = .[H25].Offset((cts - 5) * 5)
  58.                 ElseIf (cts > 3) Then    '  4
  59.                    .[Z3] = .[G27].Offset((cts - 4) * 5)
  60.                    .[Z4] = .[H24].Offset((cts - 4) * 5)
  61.                    .[Z5] = .[H25].Offset((cts - 4) * 5)
  62.                 ElseIf (cts = 3) Then    '  3
  63.                    .[Z3] = .[G27].Offset((cts - 3) * 5)
  64.                    .[Z4] = .[G26]
  65.                    .[Z5] = .[H25].Offset((cts - 3) * 5)
  66.                 ElseIf (cts > 1) Then    '  2
  67.                    .[Z3] = .[F26].Offset((cts - 2) * 5)
  68.                    .[Z4] = .[F27].Offset((cts - 2) * 5)
  69.                    .[Z5] = .[G24].Offset((cts - 2) * 5)
  70.                 ElseIf (cts = 0) Then    '  0
  71.                    .[Z3] = .[E30]
  72.                    .[Z4] = .[E31]
  73.                    .[Z5] = .[E32]
  74.                 Else                      '  1
  75.                    .[Z3] = .[F26].Offset((cts - 1) * 5)
  76.                    .[Z4] = .[F27].Offset((cts - 1) * 5)
  77.                    .[Z5] = .[F28]
  78.                 End If
  79.             
  80.             
  81.                 .[R5].Offset(cts) = .[F1].Offset(cts) * (1 - .[F1].Offset(cts)) * (.[P5] * .[Z1] + .[P6] * .[Z2] + .[P7] * .[Z3] + .[P8] * .[Z4] + .[P9] * .[Z5])
  82.                 '  ÀËÅç´ú¸Õµ²ªG
  83.                 '  .[V10].Offset(cts) = .[Z1]
  84.                 '  .[V10].Offset(cts, 1) = .[Z2]
  85.                 '  .[V10].Offset(cts, 2) = .[Z3]
  86.                 '  .[V10].Offset(cts, 3) = .[Z4]
  87.                 '  .[V10].Offset(cts, 4) = .[Z5]
  88.            Next cts
  89.    
  90.            .Range("Z1:Z5").Clear         '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È
  91.            '  .Range("V10:Z17").Clear    '  ²M°£¶Ç¦s¹Bºâ¸ê®ÆÄ椧¤º®e­È

  92.            rp5 = -1: bf1 = 0
  93.            For nxt = 0 To 9         '  neww1 = neww1 + (erra * intA)   ~  neww54 = neww54 + (errl * outc1)
  94.                For cts = 0 To 8
  95.                    rp5 = rp5 + 1

  96.                    If ((nxt * 9 + cts + 1) > 80) Then          '  neww81 = neww81 + (errn * outi1) ~ neww90 = neww90 + (erro * outm1)
  97.                        If ((nxt * 9 + cts + 1) = 81) Then
  98.                            rp5 = 0
  99.                            bf1 = 0
  100.                        End If
  101.                   
  102.                        .[A24].Offset(cts, nxt) = .[A24].Offset(cts, nxt) + (.[N5].Offset(rp5) * .[J1].Offset(bf1))
  103.                   
  104.                        If (rp5 = 1) Then
  105.                            rp5 = -1
  106.                            bf1 = bf1 + 1
  107.                        End If
  108.                    ElseIf ((nxt * 9 + cts + 1) > 40) Then      '  neww41 = neww41 + (erri * outa1) ~ neww80 = neww80 + (errm * outh1)
  109.                        If ((nxt * 9 + cts + 1) = 41) Then
  110.                            rp5 = 0
  111.                            bf1 = 0
  112.                        End If
  113.                   
  114.                        .[A24].Offset(cts, nxt) = .[A24].Offset(cts, nxt) + (.[P5].Offset(rp5) * .[F1].Offset(bf1))
  115.                   
  116.                        If (rp5 = 4) Then
  117.                            rp5 = -1
  118.                            bf1 = bf1 + 1
  119.                        End If
  120.                    Else                                        '  neww1 = neww1 + (erra * intA) ~ neww40 = neww40 + (errh * intE)
  121.                        .[A24].Offset(cts, nxt) = .[A24].Offset(cts, nxt) + (.[R5].Offset(rp5) * .[B1].Offset(bf1))
  122.                        
  123.                        If (rp5 = 7) Then
  124.                            rp5 = -1
  125.                            bf1 = bf1 + 1
  126.                        End If
  127.                    End If
  128.                Next cts
  129.            Next nxt
  130.        Next i
  131.    End With
  132. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2015-11-30 20:09 ½s¿è

¦^´_ 13# qwertyuio111
¦b¼g¤J³]©w ¥Ø¼Ð­È(Target n¡ATarget o) »P ¿é¥X­È(Out n¡AOut o)¡A¬Ûµ¥«á·|°±¤î¡A¸õ¥X°j°é­pºâªº°ÝÃD¡C
¬O«ü Target n = Out n ©ÎªÌ¬O Target o = Out o ¶Ü¡H
¯uªº·|¬Ûµ¥¶Ü¡H©ÎµM²v¦³¦h°ª¡H

TOP

        ÀR«ä¦Û¦b : ®É®É¦n¤ß´N¬O®É®É¦n¤é¡C
ªð¦^¦Cªí ¤W¤@¥DÃD