Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

assoziativer Speicher

Uploader:Mitgliedchutullu
Datum/Zeit:20.12.2007 14:45:25

***********************************************************************************
/' Assoziativer Speicher

 
  Syntax :
    init (sizeOfInput, sizeOfOutput)   - Größer des Input & Output Layers festlegen
    learn ()                           - Input & Output Muster lernen
    work  ()                           - aus einem Inputmuster ein Outputmuster
                                         assoziieren
    resetAll ()                        - interne Methode
    resetIn ()                         - Eingabemuster löschen
    resetOut ()                        - Ausgabemuster löschen
    resetWeights ()                    - Gewichte löschen
    
'/

Type ddouble
  dd As Double Ptr
End Type
Type assocMemory
  sizeInput  As Short
  sizeOutput As Short


  InValue    As Double Ptr
  OutValue   As Double Ptr
  weights    As ddouble Ptr

  Declare Constructor ()
  Declare Constructor (ByVal As Short, ByVal As Short)
  Declare Destructor ()
  Declare Sub init (ByVal As Short, ByVal As Short)
  Declare Sub learn ()
  Declare Sub work  ()
  Declare Sub resetAll ()
  Declare Sub resetIn ()
  Declare Sub resetOut ()
  Declare Sub resetWeights ()
End Type
Constructor assocMemory ()
  'Standartwerte festlegen
  With this
     .sizeInput  = 10
     .sizeOutput = 10
     .resetAll ()
  End With
End Constructor
Constructor assocMemory (ByVal sizeOfInput As Short, ByVal sizeOfOutput As Short)
  With this
     .sizeInput = sizeOfInput
     .sizeOutput = sizeOfOutput
     .resetAll ()
  End With
End Constructor
Destructor assocMemory ()
  With this
     DeAllocate (.InValue)
     DeAllocate (.OutValue)
     DeAllocate (.weights)
  End With
End Destructor
Sub assocMemory.init (ByVal sizeOfInput As Short, ByVal sizeOfOutput As Short)
  With this
     .sizeInput = sizeOfInput
     .sizeOutput = sizeOfOutput
     .resetAll ()
  End With
End Sub
Sub assocMemory.learn ()
  Dim a As Short
  Dim b As Short
  With this
    For a = 0 To sizeInput - 1
       For b = 0 To sizeOutput - 1
          .weights[a].dd[b] += (.InValue[a] * 2 - 1) * (.OutValue[b] * 2 - 1)
       Next
    Next
  End With
End Sub
Sub assocMemory.work ()
  Dim a As Short
  Dim b As Short
  Dim sum As Double
  With this
    For a = 0 To .sizeOutput - 1
      sum = 0
      For b = 0 To .sizeInput - 1
        sum += .InValue[b] * .weights[b].dd[a]
      Next
      If sum > 0 Then
        .outValue[a] = 1
      Else
        .outValue[a] = 0
      EndIf
    Next
  End With
End Sub
Sub assocMemory.resetAll ()
  With this
     .resetIn()
     .resetOut()
     .resetWeights()
  End With
End Sub
Sub assocMemory.resetIn ()
  With this
      DeAllocate (.InValue)
      .InValue  = Callocate (SizeOf(Double) * .sizeInput)
  End With
End Sub
Sub assocMemory.resetOut ()
  With this
     DeAllocate (.OutValue)
     .OutValue  = Callocate (SizeOf(Double) * .sizeInput)
  End With
End Sub
Sub assocMemory.resetWeights ()
  Dim a As Short
  With this
    .weights  = Callocate (SizeOf(ddouble) * .sizeInput)
    For a = 0 To .sizeInput - 1
      .weights[a].dd = Callocate (SizeOf(Double) * sizeOutput)
    Next
  End With
End Sub


Dim t  As assocMemory = assocMemory(3,3)
Dim a As Short


t.InValue[0] = 1
t.InValue[1] = 0
t.InValue[2] = 1

t.OutValue[0] = 0
t.OutValue[1] = 1
t.OutValue[2] = 0

t.learn ()
t.resetIn ()
t.resetOut ()

t.InValue[0] = 1
t.InValue[1] = 0
t.InValue[2] = 1
t.work ()

For a = 0 To 2
  Print t.OutValue[a]
Next


Sleep