Code-Beispiel
Assoziativer Speicher
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | chutullu | 20.12.2007 |
Simpler assoziativer Speicher. Dem Netzwerk werden Eingangswerte und die dazugehörigen Ausgangswerte vorgegeben. Nach dem Lernprozess kann das Netzwerk aus bereits gelernten Mustern das dazugehörige Ausgangsmuster assoziieren.
'***********************************************************************************
/' 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
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|