public BpNeuron(int Layer, int NeuronNumber, NeuronClass NeuronType, ArtificialNetwork AINetwork) { this.Location = new Vector2(Layer, NeuronNumber); this.NeuronType = NeuronType; this.Bias = NeuralFunctions.NextDouble(MIN, MAX); this.AINetwork = AINetwork; }
public const double MAX = 1; //.6 for squash public void SetupNetwork(int NumberOfInputs, int NumberOfOutputs, List <double> Inputs) { if (this.Weights == null) { this.Weights = new List <List <double> >(); } if (this.Neurons == null) { this.Neurons = new List <List <BpNeuron> >(); } for (int i = 0; i <= this.HiddenLayers + 1; i++) { //input layer if (i == 0) { // add weights List <double> Weights = new List <double>(); Program.WriteLine("# of inputs: " + NumberOfInputs); Program.WriteLine("# of NPL" + this.NeuronsPerLayer); for (int x = 0; x < NumberOfInputs; x++) { for (int y = 0; y < this.NeuronsPerLayer; y++) { Weights.Add(NeuralFunctions.NextDouble(MIN, MAX)); } } Program.WriteLine("SizeOf Weights: " + Weights.Count); this.Weights.Add(Weights); } //output layer else if (i == this.HiddenLayers + 1) { //Add output neurons to final layer List <BpNeuron> NeuronLayer = new List <BpNeuron>(); for (int y = 0; y < NumberOfOutputs; y++) { NeuronLayer.Add(new BpNeuron(i, y, NeuronClass.OUTPUT, this)); } this.Neurons.Add(NeuronLayer); } //hidden layer else { //Add neurons to layer List <BpNeuron> NeuronLayer = new List <BpNeuron>(); for (int y = 0; y < this.NeuronsPerLayer; y++) { NeuronLayer.Add(new BpNeuron(i, y, NeuronClass.HIDDEN, this)); } this.Neurons.Add(NeuronLayer); //add weights inbound to next layer if (i < this.HiddenLayers) { List <double> Weights = new List <double>(); for (int x = 0; x < this.NeuronsPerLayer; x++) { for (int y = 0; y < this.NeuronsPerLayer; y++) { Weights.Add(NeuralFunctions.NextDouble(MIN, MAX)); } } this.Weights.Add(Weights); } else { List <double> Weights = new List <double>(); for (int x = 0; x < this.NeuronsPerLayer; x++) { for (int y = 0; y < NumberOfOutputs; y++) { Weights.Add(NeuralFunctions.NextDouble(MIN, MAX)); } } this.Weights.Add(Weights); } } } //finally, add input neurons to the END of the array List <BpNeuron> InputNeurons = new List <BpNeuron>(); for (int i = 0; i < NumberOfInputs; i++) { InputNeurons.Add(new BpNeuron(0, i, NeuronClass.INPUT, this)); InputNeurons[i].InputNeuronInput = Inputs[i]; } this.Neurons.Add(InputNeurons); }