예제 #1
0
        public static NeuronRelation SetupNeuronRelation(Neuron neuronOfCurrLayer, int currIndex, Neuron neuronOfNextLayer, int nextIndex)
        {
            var relation = new NeuronRelation
            {
                _id = Interlocked.Increment(ref _idSource),
                _neuronFromPreviousLayer = neuronOfCurrLayer,
                _neuronFromNextLayer     = neuronOfNextLayer,
                _prevIndex = currIndex,
                _nextIndex = nextIndex
            };

            relation.Weight = (decimal)_random.NextDouble(); // - 0.5m;
            // relation.Weight =  0.5m;

            neuronOfCurrLayer.RelationsToNextLayer.Add(nextIndex, relation);
            neuronOfNextLayer.RelationsToPrevLayer.Add(currIndex, relation);

            return(relation);
        }
예제 #2
0
 public Perception(int[] neuronsInLayer)
 {
     layers = neuronsInLayer.Select(Layer.GetNeuron).ToArray();
     for (int i = 0; i < layers.Length; i++)
     {
         Layer currLayer = layers[i];
         if (i + 1 < layers.Length)
         {
             Layer nextLayer = layers[i + 1];
             for (int j = 0; j < layers[i].Count; j++)
             {
                 var relation = new NeuronRelation();
                 currLayer[j].NeuronRelationsPrev.Add(relation);
                 for (int k = 0; k < nextLayer.Count; k++)
                 {
                     nextLayer[k].NeuronRelationsPrev.Add(relation);
                 }
             }
         }
     }
 }
예제 #3
0
        public Perceptron(int[] neuronsInLayer, decimal learningRate)
        {
            _learningRate = learningRate;
            _layers       = neuronsInLayer.Select(Layer.GetNeuron).ToArray();

            for (int i = 0; i < _layers.Length; i++)
            {
                Layer currLayer = _layers[i];
                if (i + 1 < _layers.Length)
                {
                    Layer nextLayer = _layers[i + 1];
                    for (int j = 0; j < _layers[i].Count; j++)
                    {
                        for (int k = 0; k < nextLayer.Count; k++)
                        {
                            var relation = NeuronRelation.SetupNeuronRelation(currLayer[j], j, nextLayer[k], k);
                        }
                    }
                }
            }
        }