Esempio n. 1
0
        private void run()
        {
            FPA t1 = PA.Add(PA.InnerProduct(dinput, diwt), theta);             // summation and theta

            FPA ohidden = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t1)), 1.0f)); //applying sigmoid function

            FPA t2 = PA.Add(PA.InnerProduct(ohidden, dowt), tau);              // summation and tau

            FPA ooutput = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t2)), 1.0f));

            FPA oerror = PA.Subtract(doutput, ooutput);                                                                     //numpat no

            FPA herror = PA.Transpose(PA.InnerProduct(dowt, PA.Transpose(oerror, new int[] { 1, 0 })), new int[] { 1, 0 }); // doubtful transpose

            herror = PA.Multiply(PA.Multiply(PA.Subtract(1.0f, t1), t1), herror);

            FPA _owt = PA.Add(dowt, PA.Multiply(PA.InnerProduct(PA.Transpose(t1, new int[] { 1, 0 }), oerror), betao)); // orig no transpose


            FPA _iwt = PA.Multiply(PA.InnerProduct(PA.Transpose(dinput, new int[] { 1, 0 }), herror), betah); //original dinput herror and no transpose

            dtau = PA.Add(PA.Multiply(betao, oerror), dtau);

            dtheta = PA.Add(PA.Multiply(betah, herror), dtheta); //orig oerror

            PA.ToArray(_owt, out owt);
            PA.ToArray(_iwt, out iwt);

            cleanup();
            diwt = new DFPA(iwt);
            dowt = new DFPA(owt);
        }
Esempio n. 2
0
        private void run()
        {
            FPA t1 = PA.Add(PA.InnerProduct(dinput, diwt), theta);

            FPA ohidden = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t1)), 1.0f));

            FPA t2 = PA.Add(PA.InnerProduct(ohidden, dowt), tau);

            FPA ooutput = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t2)), 1.0f));

            FPA oerror = PA.Subtract(doutput, ooutput);



            FPA herror = PA.InnerProduct(dowt, PA.Transpose(oerror, new int[] { 1, 0 }));

            herror = PA.InnerProduct(PA.Multiply(PA.Subtract(1.0f, t1), t1), herror);

            FPA _owt = PA.Add(dowt, PA.Multiply(PA.InnerProduct(t1, oerror), betao));

            FPA _iwt = PA.Multiply(PA.InnerProduct(herror, dinput), betah); //original dinput herror

            dtau = PA.Add(PA.Multiply(betao, oerror), dtau);

            dtheta = PA.Add(PA.Multiply(betah, herror), dtheta); //orig herror

            PA.ToArray(_owt, out owt);
            PA.ToArray(_iwt, out iwt);

            diwt = new DFPA(owt);
            dowt = new DFPA(iwt);
        }
Esempio n. 3
0
        /*
         * Function which performs all the GPU operations
         */
        private void run()
        {
            /* Note : Inner product --- Matrix multiplication
             *        Multiply -- Element by element multiplication */

            FPA t1 = PA.Add(PA.InnerProduct(dinput, diwt), dtheta);

            /* ohidden is the output of hidden layer
             * Only Sigmoid function is used for timebeing */
            FPA ohidden = PA.Reciprocal(PA.Add(PA.Pow(new FPA(2.71828f, new int[] { numpat, nh }), PA.Negate(t1)), 1.0f));

            FPA t2 = PA.Add(PA.InnerProduct(ohidden, dowt), dtau);

            /* ooutput is the "actual" output of hidden layer
             * Only Sigmoid function is used for timebeing */
            FPA ooutput = PA.Reciprocal(PA.Add(PA.Pow(new FPA(2.71828f, new int[] { numpat, no }), PA.Negate(t2)), 1.0f));

            /* Error between expected and actual */
            FPA oerror = PA.Subtract(doutput, ooutput);

            /* Checking if error has fallen below 1% if so terminatinf further cycles */
            BoolParallelArray b = PA.All(PA.CompareGreater(derror, PA.Abs(oerror)), 1);

            b = PA.All(b);
            bool[] bt;
            PA.ToArray(b, out bt);
            if (bt[0] == true)
            {
                traincycles = 0;
            }

            /* herror is the error in the hidden layer */
            FPA herror = PA.Transpose(PA.InnerProduct(dowt, PA.Transpose(oerror, new int[] { 1, 0 })), new int[] { 1, 0 });

            herror = PA.Multiply(PA.Multiply(PA.Subtract(1.0f, ohidden), ohidden), herror);

            /* Weights between hidden  and output layer being updated */
            FPA _owt = PA.Add(PA.Multiply(PA.InnerProduct(PA.Transpose(ohidden, new int[] { 1, 0 }), oerror), betao), dowt);

            /* Weights between input  and hidden layer being updated */
            FPA _iwt = PA.Add(PA.Multiply(PA.InnerProduct(PA.Transpose(dinput, new int[] { 1, 0 }), herror), betah), diwt);

            /*Updating threshold for output layer */
            dtau = PA.Add(PA.Multiply(betao, oerror), dtau);

            /*Updating threshold for hidden layer */
            dtheta = PA.Add(PA.Multiply(betah, herror), dtheta);

            /* Casting the Parallel arrays to normal arrays */
            PA.ToArray(_owt, out owt);
            PA.ToArray(_iwt, out iwt);

            /* Rebuilding the disposable arrays from newly formed arrays */
            diwt = new DFPA(iwt);
            dowt = new DFPA(owt);
        }
Esempio n. 4
0
        public float[] Test(float[] iinput)
        {
            float[,] tinput = new float[1, ni];
            for (int i = 0; i < ni; i++)
            {
                tinput[0, i] = iinput[i];
            }

            dinput = new DFPA(tinput);
            diwt   = new DFPA(iwt);
            dowt   = new DFPA(owt);

            dtheta = PA.Section(dtheta, new Slice(0, 1), new Slice(0, nh));
            dtau   = PA.Section(dtau, new Slice(0, 1), new Slice(0, no));

            FPA t1      = PA.Add(PA.InnerProduct(dinput, diwt), dtheta);
            FPA ohidden = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t1)), 1.0f));
            FPA t2      = PA.Add(PA.InnerProduct(ohidden, dowt), dtau);

            FPA ooutput = PA.Reciprocal(PA.Add(PA.Pow2(PA.Negate(t2)), 1.0f));

            float[,] output;
            float[] routput = new float[no];
            PA.ToArray(ooutput, out output);

            for (int i = 0; i < no; i++)
            {
                routput[i] = output[0, i];
            }

            /*Disposable Floating arrays need to be explicitly "disposed" */
            dinput.Dispose();
            diwt.Dispose();
            dowt.Dispose();
            doutput.Dispose();

            /*Releasing all GPU Resources*/
            PA.UnInit();

            return(routput);
        }