Example #1
0
 private void CreateNetwork(NeuralLayer connectingFrom, NeuralLayer connectingTo)
 {
     foreach (var to in connectingTo.Neurons)
     {
         foreach (var from in connectingFrom.Neurons)
         {
             to.dendrites.Add(new Dendrite()
             {
                 InputPulse = to.pulseOutput, SynapticWeight = connectingTo.Weight
             });
         }
     }
 }
Example #2
0
        public void AddLayer(NeuralLayer layer)
        {
            int denriteCount = 1;

            if (layers.Count > 0)
            {
                denriteCount = layers[layers.Count - 1].Neurons.Count;
            }

            foreach (var element in layer.Neurons)
            {
                for (int i = 0; i < denriteCount; i++)
                {
                    element.dendrites.Add(new Dendrite());
                }
            }
        }
Example #3
0
        // Create a neural net, optionally specifying a seed for the Random object.
        // This can be useful for using the same seed repeatedly to get repeated
        //identical results.
        public NeuralNetwork(int inputNeuronCount, int hiddenNeuronCount, int outputNeuronCount, double learningRate, int?randomSeed = null)
        {
            rand = randomSeed.HasValue ? new Random(randomSeed.Value) : new Random();

            this.learningRate = learningRate;

            InputLayer  = new NeuralLayer();
            HiddenLayer = new NeuralLayer();
            OutputLayer = new NeuralLayer();

            // Create the neurons for each layer
            for (int i = 0; i < inputNeuronCount; i++)
            {
                InputLayer.Add(new Neuron(0)); // Input neurons do not have a bias
            }
            for (int i = 0; i < hiddenNeuronCount; i++)
            {
                HiddenLayer.Add(new Neuron(rand.NextDouble())); // A random bias, will be improved during training
            }
            for (int i = 0; i < outputNeuronCount; i++)
            {
                OutputLayer.Add(new Neuron(rand.NextDouble())); // A random bias, will be improved during training
            }
            // Wire up the input layer to the hidden layer
            for (int i = 0; i < hiddenNeuronCount; i++)
            {
                for (int j = 0; j < inputNeuronCount; j++)
                {
                    HiddenLayer[i].InputSignals.Add(InputLayer[j].OutputSignal, new NeuralFactor(CalcInitWeight(inputNeuronCount)));
                }
            }

            // Wire up the hidden layer to the output layer
            for (int i = 0; i < outputNeuronCount; i++)
            {
                for (int j = 0; j < hiddenNeuronCount; j++)
                {
                    OutputLayer[i].InputSignals.Add(HiddenLayer[j].OutputSignal, new NeuralFactor(CalcInitWeight(hiddenNeuronCount)));
                }
            }
        }