Beispiel #1
0
            /*************************************************************************
            Serializer: unserialization

              -- ALGLIB --
                 Copyright 14.03.2011 by Bochkanov Sergey
            *************************************************************************/
            public static void mlpunserialize(alglib.serializer s,
                multilayerperceptron network)
            {
                int i0 = 0;
                int i1 = 0;
                int i = 0;
                int j = 0;
                int k = 0;
                int fkind = 0;
                double threshold = 0;
                double v0 = 0;
                double v1 = 0;
                int nin = 0;
                int nout = 0;
                bool issoftmax = new bool();
                int[] layersizes = new int[0];


                //
                // check correctness of header
                //
                i0 = s.unserialize_int();
                alglib.ap.assert(i0 == scodes.getmlpserializationcode(), "MLPUnserialize: stream header corrupted");
                i1 = s.unserialize_int();
                alglib.ap.assert(i1 == mlpfirstversion, "MLPUnserialize: stream header corrupted");

                //
                // Create network
                //
                issoftmax = s.unserialize_bool();
                apserv.unserializeintegerarray(s, ref layersizes);
                alglib.ap.assert((alglib.ap.len(layersizes) == 2 || alglib.ap.len(layersizes) == 3) || alglib.ap.len(layersizes) == 4, "MLPUnserialize: too many hidden layers!");
                nin = layersizes[0];
                nout = layersizes[alglib.ap.len(layersizes) - 1];
                if (alglib.ap.len(layersizes) == 2)
                {
                    if (issoftmax)
                    {
                        mlpcreatec0(layersizes[0], layersizes[1], network);
                    }
                    else
                    {
                        mlpcreate0(layersizes[0], layersizes[1], network);
                    }
                }
                if (alglib.ap.len(layersizes) == 3)
                {
                    if (issoftmax)
                    {
                        mlpcreatec1(layersizes[0], layersizes[1], layersizes[2], network);
                    }
                    else
                    {
                        mlpcreate1(layersizes[0], layersizes[1], layersizes[2], network);
                    }
                }
                if (alglib.ap.len(layersizes) == 4)
                {
                    if (issoftmax)
                    {
                        mlpcreatec2(layersizes[0], layersizes[1], layersizes[2], layersizes[3], network);
                    }
                    else
                    {
                        mlpcreate2(layersizes[0], layersizes[1], layersizes[2], layersizes[3], network);
                    }
                }

                //
                // Load neurons and weights
                //
                for (i = 1; i <= alglib.ap.len(layersizes) - 1; i++)
                {
                    for (j = 0; j <= layersizes[i] - 1; j++)
                    {
                        fkind = s.unserialize_int();
                        threshold = s.unserialize_double();
                        mlpsetneuroninfo(network, i, j, fkind, threshold);
                        for (k = 0; k <= layersizes[i - 1] - 1; k++)
                        {
                            v0 = s.unserialize_double();
                            mlpsetweight(network, i - 1, k, i, j, v0);
                        }
                    }
                }

                //
                // Load standartizator
                //
                for (j = 0; j <= nin - 1; j++)
                {
                    v0 = s.unserialize_double();
                    v1 = s.unserialize_double();
                    mlpsetinputscaling(network, j, v0, v1);
                }
                for (j = 0; j <= nout - 1; j++)
                {
                    v0 = s.unserialize_double();
                    v1 = s.unserialize_double();
                    mlpsetoutputscaling(network, j, v0, v1);
                }
            }