Exemple #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]);
                }
            }
        }
Exemple #2
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])))));
            }
        }