Пример #1
0
        public NeuralNetwork(IActivationFunction activationFunc, int layersQuantity, int neuronsPerLayer, Neuron bias = null)
        {
            if (ReferenceEquals(bias, null))
            {
                InputNeurons = new NeuralLayer(neuronsPerLayer, activationFunc);
                NeuralLayer prevLayer = InputNeurons;

                HiddenLayers = new List<NeuralLayer>(layersQuantity);
                for (int i = 0; i < layersQuantity; i++)
                {
                    HiddenLayers.Add(new NeuralLayer(neuronsPerLayer, activationFunc));
                    HiddenLayers[i].ConnectToMe(prevLayer);
                    prevLayer = HiddenLayers[i];
                }

                OutputNeurons = new NeuralLayer(neuronsPerLayer, activationFunc);
                OutputNeurons.ConnectToMe(prevLayer);
            }
            else
            {
                InputNeurons = new NeuralLayer(neuronsPerLayer, activationFunc);
                NeuralLayer prevLayer = InputNeurons;

                HiddenLayers = new List<NeuralLayer>(layersQuantity);
                for (int i = 0; i < layersQuantity; i++)
                {
                    HiddenLayers.Add(new NeuralLayer(neuronsPerLayer, activationFunc));
                    HiddenLayers[i].ConnectToMe(prevLayer);
                    HiddenLayers[i].ConnectToMe(bias);
                    prevLayer = HiddenLayers[i];
                }
                OutputNeurons = new NeuralLayer(neuronsPerLayer, activationFunc);
                OutputNeurons.ConnectToMe(prevLayer);
                OutputNeurons.ConnectToMe(bias);
            }

        }
Пример #2
0
 /// <summary>
 /// Connects target layer neurons to this layer 
 /// </summary>
 /// <param name="inputs">Target layer, that will be connected</param>
 public void ConnectToMe(NeuralLayer inputs)
 {
     if (ReferenceEquals(inputs, null))
         throw new ArgumentNullException(nameof(inputs));
     foreach (var neuron in Layer)
         neuron.ConnectToInput(inputs.Layer);
 }