Esempio n. 1
0
        public void Learn(NeuralLayer fromLayer)
        {
            for (int i = 0; i < Neurons.Count; i++)
            {
                var valueDerivatives = Activate.SoftMaxDer(Neurons[i].OutputDendrites.Select(d => d.Signal.Value).ToArray());
                for (int d = 0; d < Neurons[i].OutputDendrites.Count; d++)
                {
                    var currentDendrite = Neurons[i].OutputDendrites[d];
                    foreach (var fromNeuron in fromLayer.Neurons)
                    {
                        foreach (var fromDendrite in fromNeuron.InputDendrites)
                        {
                            currentDendrite.Gamma += fromDendrite.Gamma * currentDendrite.Weight;
                        }
                    }

                    currentDendrite.Gamma *= ActivationType == ActivationType.SoftMax
                        ? valueDerivatives[d]
                        : Activate.GetActivationDer(ActivationType, currentDendrite.Signal.Value);

                    currentDendrite.UpdateWeightAndBias();
                }

                //foreach (var fromNeuron in fromLayer.Neurons)
                //{
                //    Neurons[i].Gamma += fromNeuron.Gamma * Neurons[i].Weight;
                //}

                //var averageDendriteOutput = Neurons[i].OutputDendrites.Average(d => d.Signal.Value);
                //Neurons[i].Gamma *= Activate.GetActivationDer(ActivationType, averageDendriteOutput);
                //Neurons[i].UpdateWeightAndBias();
            }
        }
Esempio n. 2
0
        // Feedforward
        public void Fire()
        {
            if (ActivationType == ActivationType.SoftMax)
            {
                var dendriteValues = new double[InputDendrites.Count];
                for (int i = 0; i < InputDendrites.Count; i++)
                {
                    dendriteValues[i] = (InputDendrites[i].Signal.Value * InputDendrites[i].Weight) + InputDendrites[i].Bias;
                }
                var output = Activate.SoftMax(dendriteValues);
                for (int i = 0; i < OutputDendrites.Count; i++)
                {
                    OutputDendrites[i].Signal.Value = output[i];
                }
            }
            else
            {
                var coalescedValue = GetCoalescedSignal();

                foreach (var output in OutputDendrites)
                {
                    output.Signal.Value = Activate.GetActivation(ActivationType, coalescedValue);
                }
            }
        }
Esempio n. 3
0
        public void Learn(double[] expectedOutput)
        {
            for (int i = 0; i < Neurons.Count; i++)
            {
                if (ActivationType == ActivationType.SoftMax)
                {
                    var valueDerivatives = Activate.SoftMaxDer(Neurons[i].OutputDendrites.Select(d => d.Signal.Value).ToArray());
                    for (int d = 0; d < Neurons[i].OutputDendrites.Count; d++)
                    {
                        Neurons[i].OutputDendrites[d].Gamma = (Neurons[i].OutputDendrites[d].Signal.Value - expectedOutput[d]) * valueDerivatives[d];
                        Neurons[i].OutputDendrites[d].UpdateWeightAndBias();
                    }
                }
                else
                {
                    //foreach (var dendrite in Neurons[i].OutputDendrites)
                    //{
                    //    Neurons[i].Gamma += (dendrite.Signal.Value - expectedOutput[i]) * Activate.GetActivationDer(ActivationType, dendrite.Signal.Value);
                    //}

                    for (int d = 0; d < Neurons[i].OutputDendrites.Count; d++)
                    {
                        var signal = Neurons[i].OutputDendrites[d].Signal;
                        var value  = (signal.Value - expectedOutput[d]) * Activate.GetActivationDer(ActivationType, signal.Value);
                        Neurons[i].OutputDendrites[d].Gamma = value;
                        Neurons[i].OutputDendrites[d].UpdateWeightAndBias();
                    }
                }


                //var averageDendriteOutput = Neurons[i].OutputDendrites.Average(d => d.Signal.Value);

                //Neurons[i].Gamma =
                //    (averageDendriteOutput - expectedOutput[i]) *
                //        Activate.GetActivationDer(ActivationType, averageDendriteOutput);

                //Neurons[i].UpdateWeightAndBias();
            }
        }