I am trying to create a Neural network project to do some basic tasks, and have created some structures which I am implimenting. However my problem comes when I try to loop through and populate the data. I am doing this with a For Each loop which seems to work but it seems to be populating a temporary copy of the structure in memory and not the structure being implimented
The code below shows my structures which i initially had as individual structures in a seperate module but then i nested them which seems to work the same, is there anyhting wrong with nesting the structures like this.
This code is where im having the probelm with instancing the structures into my project. Within the SetUpRandoms() sub routine the Inputs.Value is not being bpopulated within the instance of the Network.
Please help i dont understand what im doing wrong, i think it has something to do with the NEW keyword either being used or not used incorrectly.
Madaxe
The code below shows my structures which i initially had as individual structures in a seperate module but then i nested them which seems to work the same, is there anyhting wrong with nesting the structures like this.
VB.NET:
Public Structure NeuralNetwork
Public LayerCount As Integer
Public Layers() As Layer
Public Structure Layer
Public NeuronCount As Integer
Public Neurons() As Neuron
Public Structure Neuron
Public InputsCount As Integer
Public Value As Integer
Public Threshold As Double
Public Sumation As Double
Public ErrorValue As Double
Public ErrorCorrection As Double
Public LearningRate As Double
Public Inputs() As Input
Public InputBias As Bias
Public Structure Input
Public Value As Integer
Public Weight As Double
End Structure
Public Structure Bias
Public Value As Integer
Public Weight As Double
End Structure
End Structure
End Structure
End Structure
This code is where im having the probelm with instancing the structures into my project. Within the SetUpRandoms() sub routine the Inputs.Value is not being bpopulated within the instance of the Network.
Please help i dont understand what im doing wrong, i think it has something to do with the NEW keyword either being used or not used incorrectly.
Madaxe
VB.NET:
Public Class Form1
Public NumberOfLayers As Integer = 1
Public NumberOfNeurons As Integer = 1
Public NumberOfInputs As Integer = 16
Public LearningRate As Double = 0.2
Public Threshold As Double = 0.5
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NoLayers As Integer = NumberOfLayers - 1
Dim NoNeurons As Integer = NumberOfNeurons - 1
Dim NoInputs As Integer = NumberOfInputs - 1
Dim MyNetwork As New NeuralNetwork
Dim MyLayers() As NeuralNetwork.Layer = MyNetwork.Layers
ReDim MyNetwork.Layers(NoLayers)
MyNetwork.LayerCount = NumberOfLayers
ReDim MyNetwork.Layers(NoLayers).Neurons(NoNeurons)
MyNetwork.Layers(NoLayers).NeuronCount = NumberOfNeurons
ReDim MyNetwork.Layers(NoLayers).Neurons(NoNeurons).Inputs(NoInputs)
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).InputsCount = NumberOfInputs
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).LearningRate = LearningRate
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).Threshold = Threshold
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).InputBias.Value = 1
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).InputBias.Weight = 0.5
MyNetwork.Layers(NoLayers).Neurons(NoNeurons).Value = SumateData()
SetUpRandoms(MyNetwork)
End Sub
Private Sub SetUpRandoms(ByVal MyNetwork As NeuralNetwork)
For Each Layer In MyNetwork.Layers
For Each Neuron In Layer.Neurons
For Each Inputs In Neuron.Inputs
[B][I][U] Inputs.Weight = RandomWeight()[/U][/I][/B]
Next
Next
Next
End Sub
Private Function RandomWeight() As Double
Dim MyRandom As New Random(System.DateTime.Now.Millisecond)
Dim MyMin As Integer = -100
Dim MyMax As Integer = 100
Return (MyRandom.Next(MyMin, MyMax)) / 100
End Function
End Class