/// <summary>
        /// </summary>
        /// <param name="dz"></param>
        /// <returns></returns>
        public List <double> backward(List <double> dz)
        {
            List <double> dw = new List <double>();
            List <double> dx = new List <double>();
            double        backward_signal = dz.Sum();

            if (this.activation.Equals("sigmoid"))
            {
                backward_signal = this.activation_node.backward(backward_signal);
            }
            else
            {
                backward_signal = this.activation_node2.backward(backward_signal);
            }

            List <double> backWard = this.sumNode.backward(backward_signal);

            for (int i = 0; i < this.multiplyNodes.Count; i++)
            {
                MultiplyNode  mn      = this.multiplyNodes[i];
                List <double> retVals = mn.backward(backWard[i]);
                dx.Add(retVals[0]);
                dw.Add(retVals[1]);
            }
            //https://en.wikipedia.org/wiki/Gradient_descent
            //df/dx1, df/dx2...
            this.gradients.Add(dw);

            return(dx);
        }
Exemple #2
0
        /// <summary>
        /// Greska se propagira u nazad kroz aktivacionu funkciju,
        /// preko sabiraca, do svakog pojedinacnog mnozaca
        /// </summary>
        /// <param name="dz"></param>
        /// <returns></returns>
        public List <double> backward(List <double> dz)
        {
            //greska svakog ulaza
            List <double> dw = new List <double>();
            List <double> dx = new List <double>();
            double        backward_signal = dz.Sum();

            //TODO 7: Izvrsiti propagaciju signala u nazad, prvo kroz aktivacionu funkciju,
            //        onda kroz sabirac pa kroz svaki pojedinacan mnozac
            backward_signal = this.activation_node.backward(backward_signal);

            //dobije se nazad lista gresaka po mnoziocima koje ulaze u sabirac
            //z = x + y ===> dx = dz && dy = dz, te se dobije samo lista dz-ova onoliko puta koliko ima sabiraoca
            List <double> sabiracListaGreska = this.sumNode.backward(backward_signal);

            //za svaki sabiraoc (koji je ustv mnozac), izracunati gresku po promenljivoj i po tezini
            for (int i = 0; i < sabiracListaGreska.Count; i++)
            {
                MultiplyNode  mn = this.multiplyNodes[i];
                List <double> parPromenljivaTezinaGreska = mn.backward(sabiracListaGreska[i]);
                dx.Add(parPromenljivaTezinaGreska[0]);
                dw.Add(parPromenljivaTezinaGreska[1]);
            }

            //https://en.wikipedia.org/wiki/Gradient_descent
            //df/dx1, df/dx2...
            this.gradients.Add(dw);

            return(dx);
        }