Exemple #1
0
            /*************************************************************************
            Prepares HPC compuations  of  chunked  gradient with HPCChunkedGradient().
            You  have to call this function  before  calling  HPCChunkedGradient() for
            a new set of weights. You have to call it only once, see example below:

            HOW TO PROCESS DATASET WITH THIS FUNCTION:
                Grad:=0
                HPCPrepareChunkedGradient(Weights, WCount, NTotal, NOut, Buf)
                foreach chunk-of-dataset do
                    HPCChunkedGradient(...)
                HPCFinalizeChunkedGradient(Buf, Grad)

            *************************************************************************/
            public static void hpcpreparechunkedgradient(double[] weights,
                int wcount,
                int ntotal,
                int nin,
                int nout,
                mlpbuffers buf)
            {
                int i = 0;
                int batch4size = 0;
                int chunksize = 0;

                chunksize = 4;
                batch4size = 3 * chunksize * ntotal + chunksize * (2 * nout + 1);
                if (alglib.ap.rows(buf.xy) < chunksize || alglib.ap.cols(buf.xy) < nin + nout)
                {
                    buf.xy = new double[chunksize, nin + nout];
                }
                if (alglib.ap.rows(buf.xy2) < chunksize || alglib.ap.cols(buf.xy2) < nin + nout)
                {
                    buf.xy2 = new double[chunksize, nin + nout];
                }
                if (alglib.ap.len(buf.xyrow) < nin + nout)
                {
                    buf.xyrow = new double[nin + nout];
                }
                if (alglib.ap.len(buf.x) < nin)
                {
                    buf.x = new double[nin];
                }
                if (alglib.ap.len(buf.y) < nout)
                {
                    buf.y = new double[nout];
                }
                if (alglib.ap.len(buf.desiredy) < nout)
                {
                    buf.desiredy = new double[nout];
                }
                if (alglib.ap.len(buf.batch4buf) < batch4size)
                {
                    buf.batch4buf = new double[batch4size];
                }
                if (alglib.ap.len(buf.hpcbuf) < wcount)
                {
                    buf.hpcbuf = new double[wcount];
                }
                if (alglib.ap.len(buf.g) < wcount)
                {
                    buf.g = new double[wcount];
                }
                if (!hpcpreparechunkedgradientx(weights, wcount, buf.hpcbuf))
                {
                    for (i = 0; i <= wcount - 1; i++)
                    {
                        buf.hpcbuf[i] = 0.0;
                    }
                }
                buf.wcount = wcount;
                buf.ntotal = ntotal;
                buf.nin = nin;
                buf.nout = nout;
                buf.chunksize = chunksize;
            }
Exemple #2
0
            /*************************************************************************
            Finalizes HPC compuations  of  chunked gradient with HPCChunkedGradient().
            You  have to call this function  after  calling  HPCChunkedGradient()  for
            a new set of weights. You have to call it only once, see example below:

            HOW TO PROCESS DATASET WITH THIS FUNCTION:
                Grad:=0
                HPCPrepareChunkedGradient(Weights, WCount, NTotal, NOut, Buf)
                foreach chunk-of-dataset do
                    HPCChunkedGradient(...)
                HPCFinalizeChunkedGradient(Buf, Grad)

            *************************************************************************/
            public static void hpcfinalizechunkedgradient(mlpbuffers buf,
                double[] grad)
            {
                int i = 0;

                if (!hpcfinalizechunkedgradientx(buf.hpcbuf, buf.wcount, grad))
                {
                    for (i = 0; i <= buf.wcount - 1; i++)
                    {
                        grad[i] = grad[i] + buf.hpcbuf[i];
                    }
                }
            }
Exemple #3
0
 public override alglib.apobject make_copy()
 {
     mlpbuffers _result = new mlpbuffers();
     _result.chunksize = chunksize;
     _result.ntotal = ntotal;
     _result.nin = nin;
     _result.nout = nout;
     _result.wcount = wcount;
     _result.batch4buf = (double[])batch4buf.Clone();
     _result.hpcbuf = (double[])hpcbuf.Clone();
     _result.xy = (double[,])xy.Clone();
     _result.xy2 = (double[,])xy2.Clone();
     _result.xyrow = (double[])xyrow.Clone();
     _result.x = (double[])x.Clone();
     _result.y = (double[])y.Clone();
     _result.desiredy = (double[])desiredy.Clone();
     _result.e = e;
     _result.g = (double[])g.Clone();
     _result.tmp0 = (double[])tmp0.Clone();
     return _result;
 }