public void Forward(NeuralLayer preLayer) { foreach (var neuron in Neurons) { neuron.Fire(preLayer); } }
public void Fire(NeuralLayer preLayer) { Output = Sum(preLayer); Output = ActivationFunction.Sigmoid(Output); // Console.WriteLine($"Activation: {Output}"); // Console.WriteLine(); }
public void AddLayer(NeuralLayer layer) { int dendriteCount = 1; if (Layers.Count > 0) { dendriteCount = Layers.Last().Neurons.Count; } foreach (var element in layer.Neurons) { for (int i = 0; i < dendriteCount; i++) { element.InputDendrites.Add(new Dendrite()); } } }
private double Sum(NeuralLayer preLayer) { double computeValue = 0.0f; for (int i = 0; i < preLayer.Neurons.Count; i++) { var neuron = preLayer.Neurons[i]; var dendrite = InputDendrites[i]; computeValue += neuron.Output * dendrite.Weight; // Console.WriteLine($"{neuron.Output} * {neuron.InputDendrites[0].Weight} = {neuron.Output * neuron.InputDendrites[0].Weight}"); } // Console.WriteLine($"Sum = {computeValue}"); return(computeValue); }
private void CreateNetwork(NeuralLayer connectingFrom, NeuralLayer connectingTo) { // Initial a rand weight for input layer var rand = new Random(); foreach (var to in connectingTo.Neurons) { int i = 0; to.InputDendrites = new List <Dendrite>(); foreach (var from in connectingFrom.Neurons) { i++; to.InputDendrites.Add(new Dendrite() { Pulse = from.Output, Weight = rand.NextDouble() // i / 10.0 + i / 100.0 }); } } }
/// <summary> /// Perform forward-pass through network and update node outputs /// </summary> private void ForwardPropagation(NDArray <double> data) { //Set the input data into the first layer Layers[0].Neurons.Select((x, i) => x.Output = data[i]).ToList(); NeuralLayer preLayer = null; foreach (var layer in Layers) { //Skip first layer as it is input if (preLayer == null) { preLayer = layer; continue; } layer.Forward(preLayer); preLayer = layer; } }