Пример #1
0
        //Forward Propagate this Neuron
        public void ForwardPropag(vNeuron[,] nn)
        {
            if (this.layer != 0)
            {
                this.GetInputs(nn);
            }

            this.output          = Enumerable.Repeat(0d, this.inputs[0].Count).ToList();
            this.postActOutput   = Enumerable.Repeat(0d, this.inputs[0].Count).ToList();
            this.handedDownDelta = main.createNewMatrix(inputs[0].Count, inputs[0].Count);

            for (int i = 0; i < this.inputs.Count; i++)
            {
                List <double>         curInput = this.inputs[i];
                List <List <double> > result   = MyMath.matMulti(this.weights[i], MyMath.makeVertiColMat(curInput));
                this.output = MyMath.transposeMat(MyMath.matAdd(MyMath.makeVertiColMat(this.output), result))[0];
            }

            if (this.actFunc == actFuncType.logistic)
            {
                for (int j = 0; j < this.output.Count; j++)
                {
                    this.postActOutput[j] = MyMath.logisticFunc(this.output[j], beta[j]);
                }
            }
            else if (this.actFunc == actFuncType.identity)
            {
                for (int j = 0; j < this.output.Count; j++)
                {
                    this.postActOutput[j] = MyMath.identityFunc(this.output[j], beta[j]);
                }
            }
        }
Пример #2
0
        //Back Propagate for Hidden Neuron
        public void BackPropag(mNeuron[,] net, double learnRate, double bLearnRate)
        {
            List <List <double> > fPrime = new List <List <double> >();

            if (this.actFunc == actFuncType.logistic)
            {
                for (int i = 0; i < this.output.Count; i++)
                {
                    fPrime.Add(new List <double>());
                    for (int j = 0; j < this.output[0].Count; j++)
                    {
                        fPrime[i].Add(MyMath.logisticPrimeFunc(this.output[i][j]));
                    }
                }
            }
            else if (this.actFunc == actFuncType.identity)
            {
                for (int i = 0; i < this.output.Count; i++)
                {
                    fPrime.Add(new List <double>());
                    for (int j = 0; j < this.output[0].Count; j++)
                    {
                        fPrime[i].Add(1d);
                    }
                }
            }

            for (int i = 0; i < this.inputNeurons.Count; i++)
            {
                List <List <double> > error = MyMath.matMulti(MyMath.transposeMat(this.weights[i]), this.handedDownDelta);

                List <List <double> > result = MyMath.pointwiseMatMulti(error, fPrime);
                this.delta = result;
                this.beta  = MyMath.matSub(this.beta, MyMath.scalarProd(bLearnRate, this.delta));

                int m = inputNeurons[i][0];
                int n = inputNeurons[i][1];

                net[m, n].handedDownDelta = MyMath.matAdd(net[m, n].handedDownDelta, this.delta);

                List <List <double> > matrix   = this.weights[i];
                List <List <double> > gradient = MyMath.matMulti(this.delta, MyMath.transposeMat(this.inputs[i]));
                this.newWeights.Add(MyMath.matSub(matrix, MyMath.scalarProd(learnRate, gradient)));
            }
        }
Пример #3
0
        //Back Propagate for Hidden Neuron
        public void BackPropag(vNeuron[,] net, int mPos, double learnRate, double bLearnRate)
        {
            for (int i = 0; i < this.inputNeurons.Count; i++)
            {
                List <List <double> > error = MyMath.matMulti(MyMath.transposeMat(this.weights[i]), MyMath.makeVertiColMat(this.handedDownDelta[0]));

                List <double> fPrime = new List <double>();
                if (this.actFunc == actFuncType.logistic)
                {
                    for (int j = 0; j < this.output.Count; j++)
                    {
                        fPrime.Add(MyMath.logisticPrimeFunc(this.output[j]));
                    }
                }
                else if (this.actFunc == actFuncType.identity)
                {
                    for (int j = 0; j < this.output.Count; j++)
                    {
                        fPrime.Add(1d);
                    }
                }

                List <List <double> > result = MyMath.transposeMat(MyMath.pointwiseMatMulti(error, MyMath.makeVertiColMat(fPrime)));
                this.delta = result[0];
                this.beta  = MyMath.matSub(MyMath.makeHorizonColMat(this.beta), MyMath.scalarProd(bLearnRate, MyMath.makeHorizonColMat(this.delta)))[0];

                int m = inputNeurons[i][0];
                int n = inputNeurons[i][1];

                if (net[m, n].handedDownDelta.Count > 0)
                {
                    net[m, n].handedDownDelta[0] /*.Add(this.delta);*/ = MyMath.colAdd(net[m, n].handedDownDelta[0], this.delta);
                }
                else
                {
                    net[m, n].handedDownDelta.Add(Enumerable.Repeat(0d, delta.Count).ToList());
                    net[m, n].handedDownDelta[0] /*.Add(this.delta);*/ = MyMath.colAdd(net[m, n].handedDownDelta[0], this.delta);
                }

                List <List <double> > matrix = this.weights[i];
                this.newWeights.Add(MyMath.matSub(matrix, MyMath.scalarProd(learnRate, MyMath.matMulti(MyMath.makeVertiColMat(this.delta), MyMath.makeHorizonColMat(this.inputs[i])))));
            }
        }
Пример #4
0
        //Forward Propagate this Neuron
        public void ForwardPropag(mNeuron[,] nn)
        {
            if (this.layer != 0)
            {
                this.GetInputs(nn);
            }

            this.output          = main.createNewMatrix(this.inputs[0].Count, this.inputs[0][0].Count);
            this.postActOutput   = main.createNewMatrix(this.inputs[0].Count, this.inputs[0][0].Count);
            this.handedDownDelta = main.createNewMatrix(this.inputs[0].Count, this.inputs[0][0].Count);

            for (int i = 0; i < this.inputs.Count; i++)
            {
                List <List <double> > curInput = this.inputs[i];
                List <List <double> > result   = MyMath.matMulti(this.weights[i], curInput);
                this.output = MyMath.matAdd(this.output, result);
            }

            if (this.actFunc == actFuncType.logistic)
            {
                for (int m = 0; m < output.Count; m++)
                {
                    for (int n = 0; n < output[0].Count; n++)
                    {
                        this.postActOutput[m][n] = MyMath.logisticFunc(this.output[m][n], this.beta[m][n]);
                    }
                }
            }
            else if (this.actFunc == actFuncType.identity)
            {
                for (int m = 0; m < output.Count; m++)
                {
                    for (int n = 0; n < output[0].Count; n++)
                    {
                        this.postActOutput[m][n] = MyMath.identityFunc(this.output[m][n], this.beta[m][n]);
                    }
                }
            }
        }