Esempio n. 1
0
 // save the dictionary to lists
 public void OnBeforeSerialize()
 {
     keys.Clear();
     values.Clear();
     serial.Clear();
     foreach (KeyValuePair <TKey, TValue> pair in this)
     {
         serializer s1 = new serializer();
         s1.add(pair.Key, pair.Value);
         serial.Add(s1);
         //keys.Add(pair.Key); values.Add(pair.Value);
     }
 }
Esempio n. 2
0
    public static void SaveCred(login_handler logindata)
    {
        string save_path = Application.persistentDataPath + "/login_cred.bin";

        if (!File.Exists(save_path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(save_path, FileMode.Create);

            serializer data = new serializer(logindata);
            formatter.Serialize(stream, data);
            stream.Close();
        }
    }
Esempio n. 3
0
    public static serializer LoadCred()
    {
        string save_path = Application.persistentDataPath + "/login_cred.bin";

        if (File.Exists(save_path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(save_path, FileMode.Open);

            serializer loadedData = formatter.Deserialize(stream) as serializer;
            stream.Close();

            return(loadedData);
        }
        else
        {
            return(null);
        }
    }
Esempio n. 4
0
    void Start()
    {
        serializer data = savesystem.LoadCred();

        if (data != null)
        {
            uid  = data.uid_ser;
            pass = data.pid_ser;

            if (uid != "" && pass != "")
            {
                WWWForm form = new WWWForm();
                form.AddField("uid", uid);
                form.AddField("pass", pass);
                form.AddField("mode", mode);
                UnityWebRequest link = UnityWebRequest.Post("https://bingox.herokuapp.com/signuphandler.php", form);
                StartCoroutine(login_routine(link));
            }
        }
    }
        /*************************************************************************
        Processing functions test
        *************************************************************************/
        private static void testprocessing(ref bool err)
        {
            int nvars = 0;
            int nclasses = 0;
            int nsample = 0;
            int ntrees = 0;
            int nfeatures = 0;
            int flags = 0;
            dforest.decisionforest df1 = new dforest.decisionforest();
            dforest.decisionforest df2 = new dforest.decisionforest();
            int npoints = 0;
            double[,] xy = new double[0,0];
            int pass = 0;
            int passcount = 0;
            int i = 0;
            int j = 0;
            bool allsame = new bool();
            int info = 0;
            dforest.dfreport rep = new dforest.dfreport();
            double[] x1 = new double[0];
            double[] x2 = new double[0];
            double[] y1 = new double[0];
            double[] y2 = new double[0];
            double v = 0;

            passcount = 100;
            
            //
            // Main cycle
            //
            for(pass=1; pass<=passcount; pass++)
            {
                
                //
                // initialize parameters
                //
                nvars = 1+math.randominteger(5);
                nclasses = 1+math.randominteger(3);
                ntrees = 1+math.randominteger(4);
                nfeatures = 1+math.randominteger(nvars);
                flags = 0;
                if( (double)(math.randomreal())>(double)(0.5) )
                {
                    flags = flags+2;
                }
                
                //
                // Initialize arrays and data
                //
                npoints = 10+math.randominteger(50);
                nsample = Math.Max(10, math.randominteger(npoints));
                x1 = new double[nvars-1+1];
                x2 = new double[nvars-1+1];
                y1 = new double[nclasses-1+1];
                y2 = new double[nclasses-1+1];
                xy = new double[npoints-1+1, nvars+1];
                for(i=0; i<=npoints-1; i++)
                {
                    for(j=0; j<=nvars-1; j++)
                    {
                        if( j%2==0 )
                        {
                            xy[i,j] = 2*math.randomreal()-1;
                        }
                        else
                        {
                            xy[i,j] = math.randominteger(2);
                        }
                    }
                    if( nclasses==1 )
                    {
                        xy[i,nvars] = 2*math.randomreal()-1;
                    }
                    else
                    {
                        xy[i,nvars] = math.randominteger(nclasses);
                    }
                }
                
                //
                // create forest
                //
                dforest.dfbuildinternal(xy, npoints, nvars, nclasses, ntrees, nsample, nfeatures, flags, ref info, df1, rep);
                if( info<=0 )
                {
                    err = true;
                    return;
                }
                
                //
                // Same inputs leads to same outputs
                //
                for(i=0; i<=nvars-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nclasses-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                dforest.dfprocess(df1, x1, ref y1);
                dforest.dfprocess(df1, x2, ref y2);
                allsame = true;
                for(i=0; i<=nclasses-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Same inputs on original forest leads to same outputs
                // on copy created using DFCopy
                //
                unsetdf(df2);
                dforest.dfcopy(df1, df2);
                for(i=0; i<=nvars-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nclasses-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                dforest.dfprocess(df1, x1, ref y1);
                dforest.dfprocess(df2, x2, ref y2);
                allsame = true;
                for(i=0; i<=nclasses-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Same inputs on original forest leads to same outputs
                // on copy created using DFSerialize
                //
                unsetdf(df2);
                {
                    //
                    // This code passes data structure through serializers
                    // (serializes it to string and loads back)
                    //
                    serializer _local_serializer;
                    string _local_str;
                    
                    _local_serializer = new serializer();
                    _local_serializer.alloc_start();
                    dforest.dfalloc(_local_serializer, df1);
                    _local_serializer.sstart_str();
                    dforest.dfserialize(_local_serializer, df1);
                    _local_serializer.stop();
                    _local_str = _local_serializer.get_string();
                    
                    _local_serializer = new serializer();
                    _local_serializer.ustart_str(_local_str);
                    dforest.dfunserialize(_local_serializer, df2);
                    _local_serializer.stop();
                }
                for(i=0; i<=nvars-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nclasses-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                dforest.dfprocess(df1, x1, ref y1);
                dforest.dfprocess(df2, x2, ref y2);
                allsame = true;
                for(i=0; i<=nclasses-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Normalization properties
                //
                if( nclasses>1 )
                {
                    for(i=0; i<=nvars-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                    }
                    dforest.dfprocess(df1, x1, ref y1);
                    v = 0;
                    for(i=0; i<=nclasses-1; i++)
                    {
                        v = v+y1[i];
                        err = err | (double)(y1[i])<(double)(0);
                    }
                    err = err | (double)(Math.Abs(v-1))>(double)(1000*math.machineepsilon);
                }
            }
        }
        /*************************************************************************
        Tests for swapping functions
        *************************************************************************/
        private static bool testserializationfunctions(bool silent)
        {
            bool result = new bool();
            bool okb = new bool();
            bool oki = new bool();
            bool okr = new bool();
            int nb = 0;
            int ni = 0;
            int nr = 0;
            int i = 0;
            rec4serialization r0 = new rec4serialization();
            rec4serialization r1 = new rec4serialization();

            result = true;
            okb = true;
            oki = true;
            okr = true;
            for(nb=1; nb<=4; nb++)
            {
                for(ni=1; ni<=4; ni++)
                {
                    for(nr=1; nr<=4; nr++)
                    {
                        r0.b = new bool[nb];
                        for(i=0; i<=nb-1; i++)
                        {
                            r0.b[i] = math.randominteger(2)!=0;
                        }
                        r0.i = new int[ni];
                        for(i=0; i<=ni-1; i++)
                        {
                            r0.i[i] = math.randominteger(10)-5;
                        }
                        r0.r = new double[nr];
                        for(i=0; i<=nr-1; i++)
                        {
                            r0.r[i] = 2*math.randomreal()-1;
                        }
                        {
                            //
                            // This code passes data structure through serializers
                            // (serializes it to string and loads back)
                            //
                            serializer _local_serializer;
                            string _local_str;
                            
                            _local_serializer = new serializer();
                            _local_serializer.alloc_start();
                            testalglibbasicsunit.rec4serializationalloc(_local_serializer, r0);
                            _local_serializer.sstart_str();
                            testalglibbasicsunit.rec4serializationserialize(_local_serializer, r0);
                            _local_serializer.stop();
                            _local_str = _local_serializer.get_string();
                            
                            _local_serializer = new serializer();
                            _local_serializer.ustart_str(_local_str);
                            testalglibbasicsunit.rec4serializationunserialize(_local_serializer, r1);
                            _local_serializer.stop();
                        }
                        if( (ap.len(r0.b)==ap.len(r1.b) & ap.len(r0.i)==ap.len(r1.i)) & ap.len(r0.r)==ap.len(r1.r) )
                        {
                            for(i=0; i<=nb-1; i++)
                            {
                                okb = okb & ((r0.b[i] & r1.b[i]) | (!r0.b[i] & !r1.b[i]));
                            }
                            for(i=0; i<=ni-1; i++)
                            {
                                oki = oki & r0.i[i]==r1.i[i];
                            }
                            for(i=0; i<=nr-1; i++)
                            {
                                okr = okr & (double)(r0.r[i])==(double)(r1.r[i]);
                            }
                        }
                        else
                        {
                            oki = false;
                        }
                    }
                }
            }
            
            //
            // summary
            //
            result = result & okb;
            result = result & oki;
            result = result & okr;
            if( !silent )
            {
                if( result )
                {
                    System.Console.Write("SERIALIZATION FUNCTIONS:                 OK");
                    System.Console.WriteLine();
                }
                else
                {
                    System.Console.Write("SERIALIZATION FUNCTIONS:                 FAILED");
                    System.Console.WriteLine();
                    System.Console.Write("* BOOLEAN - - - - - - - - - - - - - - -  ");
                    if( okb )
                    {
                        System.Console.Write("OK");
                        System.Console.WriteLine();
                    }
                    else
                    {
                        System.Console.Write("FAILED");
                        System.Console.WriteLine();
                    }
                    System.Console.Write("* INTEGER - - - - - - - - - - - - - - -  ");
                    if( oki )
                    {
                        System.Console.Write("OK");
                        System.Console.WriteLine();
                    }
                    else
                    {
                        System.Console.Write("FAILED");
                        System.Console.WriteLine();
                    }
                    System.Console.Write("* REAL  - - - - - - - - - - - - - - - -  ");
                    if( okr )
                    {
                        System.Console.Write("OK");
                        System.Console.WriteLine();
                    }
                    else
                    {
                        System.Console.Write("FAILED");
                        System.Console.WriteLine();
                    }
                }
            }
            return result;
        }
        /*************************************************************************
        Processing functions test
        *************************************************************************/
        private static void testprocessing(int nkind,
            int nin,
            int nhid1,
            int nhid2,
            int nout,
            int passcount,
            ref bool err)
        {
            mlpbase.multilayerperceptron network = new mlpbase.multilayerperceptron();
            mlpbase.multilayerperceptron network2 = new mlpbase.multilayerperceptron();
            int n1 = 0;
            int n2 = 0;
            int wcount = 0;
            bool zeronet = new bool();
            double a1 = 0;
            double a2 = 0;
            int pass = 0;
            int i = 0;
            bool allsame = new bool();
            double[] x1 = new double[0];
            double[] x2 = new double[0];
            double[] y1 = new double[0];
            double[] y2 = new double[0];
            double v = 0;
            int i_ = 0;

            ap.assert(passcount>=2, "PassCount<2!");
            
            //
            // Prepare network
            //
            a1 = 0;
            a2 = 0;
            if( nkind==2 )
            {
                a1 = 1000*math.randomreal()-500;
                a2 = 2*math.randomreal()-1;
            }
            if( nkind==3 )
            {
                a1 = 1000*math.randomreal()-500;
                a2 = a1+(2*math.randominteger(2)-1)*(0.1+0.9*math.randomreal());
            }
            createnetwork(network, nkind, a1, a2, nin, nhid1, nhid2, nout);
            mlpbase.mlpproperties(network, ref n1, ref n2, ref wcount);
            
            //
            // Initialize arrays
            //
            x1 = new double[nin-1+1];
            x2 = new double[nin-1+1];
            y1 = new double[nout-1+1];
            y2 = new double[nout-1+1];
            
            //
            // Main cycle
            //
            for(pass=1; pass<=passcount; pass++)
            {
                
                //
                // Last run is made on zero network
                //
                mlpbase.mlprandomizefull(network);
                zeronet = false;
                if( pass==passcount )
                {
                    for(i_=0; i_<=wcount-1;i_++)
                    {
                        network.weights[i_] = 0*network.weights[i_];
                    }
                    zeronet = true;
                }
                
                //
                // Same inputs leads to same outputs
                //
                for(i=0; i<=nin-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nout-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                mlpbase.mlpprocess(network, x1, ref y1);
                mlpbase.mlpprocess(network, x2, ref y2);
                allsame = true;
                for(i=0; i<=nout-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Same inputs on original network leads to same outputs
                // on copy created using MLPCopy
                //
                unsetnetwork(network2);
                mlpbase.mlpcopy(network, network2);
                for(i=0; i<=nin-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nout-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                mlpbase.mlpprocess(network, x1, ref y1);
                mlpbase.mlpprocess(network2, x2, ref y2);
                allsame = true;
                for(i=0; i<=nout-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Same inputs on original network leads to same outputs
                // on copy created using MLPSerialize
                //
                unsetnetwork(network2);
                {
                    //
                    // This code passes data structure through serializers
                    // (serializes it to string and loads back)
                    //
                    serializer _local_serializer;
                    string _local_str;
                    
                    _local_serializer = new serializer();
                    _local_serializer.alloc_start();
                    mlpbase.mlpalloc(_local_serializer, network);
                    _local_serializer.sstart_str();
                    mlpbase.mlpserialize(_local_serializer, network);
                    _local_serializer.stop();
                    _local_str = _local_serializer.get_string();
                    
                    _local_serializer = new serializer();
                    _local_serializer.ustart_str(_local_str);
                    mlpbase.mlpunserialize(_local_serializer, network2);
                    _local_serializer.stop();
                }
                for(i=0; i<=nin-1; i++)
                {
                    x1[i] = 2*math.randomreal()-1;
                    x2[i] = x1[i];
                }
                for(i=0; i<=nout-1; i++)
                {
                    y1[i] = 2*math.randomreal()-1;
                    y2[i] = 2*math.randomreal()-1;
                }
                mlpbase.mlpprocess(network, x1, ref y1);
                mlpbase.mlpprocess(network2, x2, ref y2);
                allsame = true;
                for(i=0; i<=nout-1; i++)
                {
                    allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                }
                err = err | !allsame;
                
                //
                // Different inputs leads to different outputs (non-zero network)
                //
                if( !zeronet )
                {
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                        x2[i] = 2*math.randomreal()-1;
                    }
                    for(i=0; i<=nout-1; i++)
                    {
                        y1[i] = 2*math.randomreal()-1;
                        y2[i] = y1[i];
                    }
                    mlpbase.mlpprocess(network, x1, ref y1);
                    mlpbase.mlpprocess(network, x2, ref y2);
                    allsame = true;
                    for(i=0; i<=nout-1; i++)
                    {
                        allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                    }
                    err = err | allsame;
                }
                
                //
                // Randomization changes outputs (when inputs are unchanged, non-zero network)
                //
                if( !zeronet )
                {
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                        x2[i] = 2*math.randomreal()-1;
                    }
                    for(i=0; i<=nout-1; i++)
                    {
                        y1[i] = 2*math.randomreal()-1;
                        y2[i] = y1[i];
                    }
                    mlpbase.mlpcopy(network, network2);
                    mlpbase.mlprandomize(network2);
                    mlpbase.mlpprocess(network, x1, ref y1);
                    mlpbase.mlpprocess(network2, x1, ref y2);
                    allsame = true;
                    for(i=0; i<=nout-1; i++)
                    {
                        allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                    }
                    err = err | allsame;
                }
                
                //
                // Full randomization changes outputs (when inputs are unchanged, non-zero network)
                //
                if( !zeronet )
                {
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                        x2[i] = 2*math.randomreal()-1;
                    }
                    for(i=0; i<=nout-1; i++)
                    {
                        y1[i] = 2*math.randomreal()-1;
                        y2[i] = y1[i];
                    }
                    mlpbase.mlpcopy(network, network2);
                    mlpbase.mlprandomizefull(network2);
                    mlpbase.mlpprocess(network, x1, ref y1);
                    mlpbase.mlpprocess(network2, x1, ref y2);
                    allsame = true;
                    for(i=0; i<=nout-1; i++)
                    {
                        allsame = allsame & (double)(y1[i])==(double)(y2[i]);
                    }
                    err = err | allsame;
                }
                
                //
                // Normalization properties
                //
                if( nkind==1 )
                {
                    
                    //
                    // Classifier network outputs are normalized
                    //
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                    }
                    mlpbase.mlpprocess(network, x1, ref y1);
                    v = 0;
                    for(i=0; i<=nout-1; i++)
                    {
                        v = v+y1[i];
                        err = err | (double)(y1[i])<(double)(0);
                    }
                    err = err | (double)(Math.Abs(v-1))>(double)(1000*math.machineepsilon);
                }
                if( nkind==2 )
                {
                    
                    //
                    // B-type network outputs are bounded from above/below
                    //
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                    }
                    mlpbase.mlpprocess(network, x1, ref y1);
                    for(i=0; i<=nout-1; i++)
                    {
                        if( (double)(a2)>=(double)(0) )
                        {
                            err = err | (double)(y1[i])<(double)(a1);
                        }
                        else
                        {
                            err = err | (double)(y1[i])>(double)(a1);
                        }
                    }
                }
                if( nkind==3 )
                {
                    
                    //
                    // R-type network outputs are within [A1,A2] (or [A2,A1])
                    //
                    for(i=0; i<=nin-1; i++)
                    {
                        x1[i] = 2*math.randomreal()-1;
                    }
                    mlpbase.mlpprocess(network, x1, ref y1);
                    for(i=0; i<=nout-1; i++)
                    {
                        err = (err | (double)(y1[i])<(double)(Math.Min(a1, a2))) | (double)(y1[i])>(double)(Math.Max(a1, a2));
                    }
                }
            }
        }
        /*************************************************************************
        Network creation

        This function creates network with desired structure. Network  is  created
        using one of the three methods:
        a) straighforward creation using MLPCreate???()
        b) MLPCreate???() for proxy object, which is copied with PassThroughSerializer()
        c) MLPCreate???() for proxy object, which is copied with MLPCopy()
        One of these methods is chosen with probability 1/3.
        *************************************************************************/
        private static void createnetwork(mlpbase.multilayerperceptron network,
            int nkind,
            double a1,
            double a2,
            int nin,
            int nhid1,
            int nhid2,
            int nout)
        {
            int mkind = 0;
            mlpbase.multilayerperceptron tmp = new mlpbase.multilayerperceptron();

            ap.assert(((nin>0 & nhid1>=0) & nhid2>=0) & nout>0, "CreateNetwork error");
            ap.assert(nhid1!=0 | nhid2==0, "CreateNetwork error");
            ap.assert(nkind!=1 | nout>=2, "CreateNetwork error");
            mkind = math.randominteger(3);
            if( nhid1==0 )
            {
                
                //
                // No hidden layers
                //
                if( nkind==0 )
                {
                    if( mkind==0 )
                    {
                        mlpbase.mlpcreate0(nin, nout, network);
                    }
                    if( mkind==1 )
                    {
                        mlpbase.mlpcreate0(nin, nout, tmp);
                        {
                            //
                            // This code passes data structure through serializers
                            // (serializes it to string and loads back)
                            //
                            serializer _local_serializer;
                            string _local_str;
                            
                            _local_serializer = new serializer();
                            _local_serializer.alloc_start();
                            mlpbase.mlpalloc(_local_serializer, tmp);
                            _local_serializer.sstart_str();
                            mlpbase.mlpserialize(_local_serializer, tmp);
                            _local_serializer.stop();
                            _local_str = _local_serializer.get_string();
                            
                            _local_serializer = new serializer();
                            _local_serializer.ustart_str(_local_str);
                            mlpbase.mlpunserialize(_local_serializer, network);
                            _local_serializer.stop();
                        }
                    }
                    if( mkind==2 )
                    {
                        mlpbase.mlpcreate0(nin, nout, tmp);
                        mlpbase.mlpcopy(tmp, network);
                    }
                }
                else
                {
                    if( nkind==1 )
                    {
                        if( mkind==0 )
                        {
                            mlpbase.mlpcreatec0(nin, nout, network);
                        }
                        if( mkind==1 )
                        {
                            mlpbase.mlpcreatec0(nin, nout, tmp);
                            {
                                //
                                // This code passes data structure through serializers
                                // (serializes it to string and loads back)
                                //
                                serializer _local_serializer;
                                string _local_str;
                                
                                _local_serializer = new serializer();
                                _local_serializer.alloc_start();
                                mlpbase.mlpalloc(_local_serializer, tmp);
                                _local_serializer.sstart_str();
                                mlpbase.mlpserialize(_local_serializer, tmp);
                                _local_serializer.stop();
                                _local_str = _local_serializer.get_string();
                                
                                _local_serializer = new serializer();
                                _local_serializer.ustart_str(_local_str);
                                mlpbase.mlpunserialize(_local_serializer, network);
                                _local_serializer.stop();
                            }
                        }
                        if( mkind==2 )
                        {
                            mlpbase.mlpcreatec0(nin, nout, tmp);
                            mlpbase.mlpcopy(tmp, network);
                        }
                    }
                    else
                    {
                        if( nkind==2 )
                        {
                            if( mkind==0 )
                            {
                                mlpbase.mlpcreateb0(nin, nout, a1, a2, network);
                            }
                            if( mkind==1 )
                            {
                                mlpbase.mlpcreateb0(nin, nout, a1, a2, tmp);
                                {
                                    //
                                    // This code passes data structure through serializers
                                    // (serializes it to string and loads back)
                                    //
                                    serializer _local_serializer;
                                    string _local_str;
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.alloc_start();
                                    mlpbase.mlpalloc(_local_serializer, tmp);
                                    _local_serializer.sstart_str();
                                    mlpbase.mlpserialize(_local_serializer, tmp);
                                    _local_serializer.stop();
                                    _local_str = _local_serializer.get_string();
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.ustart_str(_local_str);
                                    mlpbase.mlpunserialize(_local_serializer, network);
                                    _local_serializer.stop();
                                }
                            }
                            if( mkind==2 )
                            {
                                mlpbase.mlpcreateb0(nin, nout, a1, a2, tmp);
                                mlpbase.mlpcopy(tmp, network);
                            }
                        }
                        else
                        {
                            if( nkind==3 )
                            {
                                if( mkind==0 )
                                {
                                    mlpbase.mlpcreater0(nin, nout, a1, a2, network);
                                }
                                if( mkind==1 )
                                {
                                    mlpbase.mlpcreater0(nin, nout, a1, a2, tmp);
                                    {
                                        //
                                        // This code passes data structure through serializers
                                        // (serializes it to string and loads back)
                                        //
                                        serializer _local_serializer;
                                        string _local_str;
                                        
                                        _local_serializer = new serializer();
                                        _local_serializer.alloc_start();
                                        mlpbase.mlpalloc(_local_serializer, tmp);
                                        _local_serializer.sstart_str();
                                        mlpbase.mlpserialize(_local_serializer, tmp);
                                        _local_serializer.stop();
                                        _local_str = _local_serializer.get_string();
                                        
                                        _local_serializer = new serializer();
                                        _local_serializer.ustart_str(_local_str);
                                        mlpbase.mlpunserialize(_local_serializer, network);
                                        _local_serializer.stop();
                                    }
                                }
                                if( mkind==2 )
                                {
                                    mlpbase.mlpcreater0(nin, nout, a1, a2, tmp);
                                    mlpbase.mlpcopy(tmp, network);
                                }
                            }
                        }
                    }
                }
                mlpbase.mlprandomizefull(network);
                return;
            }
            if( nhid2==0 )
            {
                
                //
                // One hidden layer
                //
                if( nkind==0 )
                {
                    if( mkind==0 )
                    {
                        mlpbase.mlpcreate1(nin, nhid1, nout, network);
                    }
                    if( mkind==1 )
                    {
                        mlpbase.mlpcreate1(nin, nhid1, nout, tmp);
                        {
                            //
                            // This code passes data structure through serializers
                            // (serializes it to string and loads back)
                            //
                            serializer _local_serializer;
                            string _local_str;
                            
                            _local_serializer = new serializer();
                            _local_serializer.alloc_start();
                            mlpbase.mlpalloc(_local_serializer, tmp);
                            _local_serializer.sstart_str();
                            mlpbase.mlpserialize(_local_serializer, tmp);
                            _local_serializer.stop();
                            _local_str = _local_serializer.get_string();
                            
                            _local_serializer = new serializer();
                            _local_serializer.ustart_str(_local_str);
                            mlpbase.mlpunserialize(_local_serializer, network);
                            _local_serializer.stop();
                        }
                    }
                    if( mkind==2 )
                    {
                        mlpbase.mlpcreate1(nin, nhid1, nout, tmp);
                        mlpbase.mlpcopy(tmp, network);
                    }
                }
                else
                {
                    if( nkind==1 )
                    {
                        if( mkind==0 )
                        {
                            mlpbase.mlpcreatec1(nin, nhid1, nout, network);
                        }
                        if( mkind==1 )
                        {
                            mlpbase.mlpcreatec1(nin, nhid1, nout, tmp);
                            {
                                //
                                // This code passes data structure through serializers
                                // (serializes it to string and loads back)
                                //
                                serializer _local_serializer;
                                string _local_str;
                                
                                _local_serializer = new serializer();
                                _local_serializer.alloc_start();
                                mlpbase.mlpalloc(_local_serializer, tmp);
                                _local_serializer.sstart_str();
                                mlpbase.mlpserialize(_local_serializer, tmp);
                                _local_serializer.stop();
                                _local_str = _local_serializer.get_string();
                                
                                _local_serializer = new serializer();
                                _local_serializer.ustart_str(_local_str);
                                mlpbase.mlpunserialize(_local_serializer, network);
                                _local_serializer.stop();
                            }
                        }
                        if( mkind==2 )
                        {
                            mlpbase.mlpcreatec1(nin, nhid1, nout, tmp);
                            mlpbase.mlpcopy(tmp, network);
                        }
                    }
                    else
                    {
                        if( nkind==2 )
                        {
                            if( mkind==0 )
                            {
                                mlpbase.mlpcreateb1(nin, nhid1, nout, a1, a2, network);
                            }
                            if( mkind==1 )
                            {
                                mlpbase.mlpcreateb1(nin, nhid1, nout, a1, a2, tmp);
                                {
                                    //
                                    // This code passes data structure through serializers
                                    // (serializes it to string and loads back)
                                    //
                                    serializer _local_serializer;
                                    string _local_str;
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.alloc_start();
                                    mlpbase.mlpalloc(_local_serializer, tmp);
                                    _local_serializer.sstart_str();
                                    mlpbase.mlpserialize(_local_serializer, tmp);
                                    _local_serializer.stop();
                                    _local_str = _local_serializer.get_string();
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.ustart_str(_local_str);
                                    mlpbase.mlpunserialize(_local_serializer, network);
                                    _local_serializer.stop();
                                }
                            }
                            if( mkind==2 )
                            {
                                mlpbase.mlpcreateb1(nin, nhid1, nout, a1, a2, tmp);
                                mlpbase.mlpcopy(tmp, network);
                            }
                        }
                        else
                        {
                            if( nkind==3 )
                            {
                                if( mkind==0 )
                                {
                                    mlpbase.mlpcreater1(nin, nhid1, nout, a1, a2, network);
                                }
                                if( mkind==1 )
                                {
                                    mlpbase.mlpcreater1(nin, nhid1, nout, a1, a2, tmp);
                                    {
                                        //
                                        // This code passes data structure through serializers
                                        // (serializes it to string and loads back)
                                        //
                                        serializer _local_serializer;
                                        string _local_str;
                                        
                                        _local_serializer = new serializer();
                                        _local_serializer.alloc_start();
                                        mlpbase.mlpalloc(_local_serializer, tmp);
                                        _local_serializer.sstart_str();
                                        mlpbase.mlpserialize(_local_serializer, tmp);
                                        _local_serializer.stop();
                                        _local_str = _local_serializer.get_string();
                                        
                                        _local_serializer = new serializer();
                                        _local_serializer.ustart_str(_local_str);
                                        mlpbase.mlpunserialize(_local_serializer, network);
                                        _local_serializer.stop();
                                    }
                                }
                                if( mkind==2 )
                                {
                                    mlpbase.mlpcreater1(nin, nhid1, nout, a1, a2, tmp);
                                    mlpbase.mlpcopy(tmp, network);
                                }
                            }
                        }
                    }
                }
                mlpbase.mlprandomizefull(network);
                return;
            }
            
            //
            // Two hidden layers
            //
            if( nkind==0 )
            {
                if( mkind==0 )
                {
                    mlpbase.mlpcreate2(nin, nhid1, nhid2, nout, network);
                }
                if( mkind==1 )
                {
                    mlpbase.mlpcreate2(nin, nhid1, nhid2, nout, tmp);
                    {
                        //
                        // This code passes data structure through serializers
                        // (serializes it to string and loads back)
                        //
                        serializer _local_serializer;
                        string _local_str;
                        
                        _local_serializer = new serializer();
                        _local_serializer.alloc_start();
                        mlpbase.mlpalloc(_local_serializer, tmp);
                        _local_serializer.sstart_str();
                        mlpbase.mlpserialize(_local_serializer, tmp);
                        _local_serializer.stop();
                        _local_str = _local_serializer.get_string();
                        
                        _local_serializer = new serializer();
                        _local_serializer.ustart_str(_local_str);
                        mlpbase.mlpunserialize(_local_serializer, network);
                        _local_serializer.stop();
                    }
                }
                if( mkind==2 )
                {
                    mlpbase.mlpcreate2(nin, nhid1, nhid2, nout, tmp);
                    mlpbase.mlpcopy(tmp, network);
                }
            }
            else
            {
                if( nkind==1 )
                {
                    if( mkind==0 )
                    {
                        mlpbase.mlpcreatec2(nin, nhid1, nhid2, nout, network);
                    }
                    if( mkind==1 )
                    {
                        mlpbase.mlpcreatec2(nin, nhid1, nhid2, nout, tmp);
                        {
                            //
                            // This code passes data structure through serializers
                            // (serializes it to string and loads back)
                            //
                            serializer _local_serializer;
                            string _local_str;
                            
                            _local_serializer = new serializer();
                            _local_serializer.alloc_start();
                            mlpbase.mlpalloc(_local_serializer, tmp);
                            _local_serializer.sstart_str();
                            mlpbase.mlpserialize(_local_serializer, tmp);
                            _local_serializer.stop();
                            _local_str = _local_serializer.get_string();
                            
                            _local_serializer = new serializer();
                            _local_serializer.ustart_str(_local_str);
                            mlpbase.mlpunserialize(_local_serializer, network);
                            _local_serializer.stop();
                        }
                    }
                    if( mkind==2 )
                    {
                        mlpbase.mlpcreatec2(nin, nhid1, nhid2, nout, tmp);
                        mlpbase.mlpcopy(tmp, network);
                    }
                }
                else
                {
                    if( nkind==2 )
                    {
                        if( mkind==0 )
                        {
                            mlpbase.mlpcreateb2(nin, nhid1, nhid2, nout, a1, a2, network);
                        }
                        if( mkind==1 )
                        {
                            mlpbase.mlpcreateb2(nin, nhid1, nhid2, nout, a1, a2, tmp);
                            {
                                //
                                // This code passes data structure through serializers
                                // (serializes it to string and loads back)
                                //
                                serializer _local_serializer;
                                string _local_str;
                                
                                _local_serializer = new serializer();
                                _local_serializer.alloc_start();
                                mlpbase.mlpalloc(_local_serializer, tmp);
                                _local_serializer.sstart_str();
                                mlpbase.mlpserialize(_local_serializer, tmp);
                                _local_serializer.stop();
                                _local_str = _local_serializer.get_string();
                                
                                _local_serializer = new serializer();
                                _local_serializer.ustart_str(_local_str);
                                mlpbase.mlpunserialize(_local_serializer, network);
                                _local_serializer.stop();
                            }
                        }
                        if( mkind==2 )
                        {
                            mlpbase.mlpcreateb2(nin, nhid1, nhid2, nout, a1, a2, tmp);
                            mlpbase.mlpcopy(tmp, network);
                        }
                    }
                    else
                    {
                        if( nkind==3 )
                        {
                            if( mkind==0 )
                            {
                                mlpbase.mlpcreater2(nin, nhid1, nhid2, nout, a1, a2, network);
                            }
                            if( mkind==1 )
                            {
                                mlpbase.mlpcreater2(nin, nhid1, nhid2, nout, a1, a2, tmp);
                                {
                                    //
                                    // This code passes data structure through serializers
                                    // (serializes it to string and loads back)
                                    //
                                    serializer _local_serializer;
                                    string _local_str;
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.alloc_start();
                                    mlpbase.mlpalloc(_local_serializer, tmp);
                                    _local_serializer.sstart_str();
                                    mlpbase.mlpserialize(_local_serializer, tmp);
                                    _local_serializer.stop();
                                    _local_str = _local_serializer.get_string();
                                    
                                    _local_serializer = new serializer();
                                    _local_serializer.ustart_str(_local_str);
                                    mlpbase.mlpunserialize(_local_serializer, network);
                                    _local_serializer.stop();
                                }
                            }
                            if( mkind==2 )
                            {
                                mlpbase.mlpcreater2(nin, nhid1, nhid2, nout, a1, a2, tmp);
                                mlpbase.mlpcopy(tmp, network);
                            }
                        }
                    }
                }
            }
            mlpbase.mlprandomizefull(network);
        }
        /*************************************************************************
        Testing serialization of KD trees

        This function sets Err to True on errors, but leaves it unchanged on success
        *************************************************************************/
        private static void testkdtreeserialization(ref bool err)
        {
            int n = 0;
            int nx = 0;
            int ny = 0;
            int normtype = 0;
            int i = 0;
            int j = 0;
            int k = 0;
            int q = 0;
            double[,] xy = new double[0,0];
            double[] x = new double[0];
            int[] tags = new int[0];
            int[] qsizes = new int[0];
            double threshold = 0;
            nearestneighbor.kdtree tree0 = new nearestneighbor.kdtree();
            nearestneighbor.kdtree tree1 = new nearestneighbor.kdtree();
            int k0 = 0;
            int k1 = 0;
            double[,] xy0 = new double[0,0];
            double[,] xy1 = new double[0,0];
            int[] tags0 = new int[0];
            int[] tags1 = new int[0];
            int i_ = 0;

            threshold = 100*math.machineepsilon;
            
            //
            // different N, NX, NY, NormType
            //
            n = 1;
            while( n<=51 )
            {
                
                //
                // prepare array with query sizes
                //
                qsizes = new int[4];
                qsizes[0] = 1;
                qsizes[1] = Math.Min(2, n);
                qsizes[2] = Math.Min(4, n);
                qsizes[3] = n;
                
                //
                // different NX/NY/NormType
                //
                for(nx=1; nx<=2; nx++)
                {
                    for(ny=0; ny<=2; ny++)
                    {
                        for(normtype=0; normtype<=2; normtype++)
                        {
                            
                            //
                            // Prepare data
                            //
                            xy = new double[n, nx+ny];
                            tags = new int[n];
                            for(i=0; i<=n-1; i++)
                            {
                                for(j=0; j<=nx+ny-1; j++)
                                {
                                    xy[i,j] = math.randomreal();
                                }
                                tags[i] = math.randominteger(100);
                            }
                            
                            //
                            // Build tree, pass it through serializer
                            //
                            nearestneighbor.kdtreebuildtagged(xy, tags, n, nx, ny, normtype, tree0);
                            {
                                //
                                // This code passes data structure through serializers
                                // (serializes it to string and loads back)
                                //
                                serializer _local_serializer;
                                string _local_str;
                                
                                _local_serializer = new serializer();
                                _local_serializer.alloc_start();
                                nearestneighbor.kdtreealloc(_local_serializer, tree0);
                                _local_serializer.sstart_str();
                                nearestneighbor.kdtreeserialize(_local_serializer, tree0);
                                _local_serializer.stop();
                                _local_str = _local_serializer.get_string();
                                
                                _local_serializer = new serializer();
                                _local_serializer.ustart_str(_local_str);
                                nearestneighbor.kdtreeunserialize(_local_serializer, tree1);
                                _local_serializer.stop();
                            }
                            
                            //
                            // For each point of XY we make queries with different sizes
                            //
                            x = new double[nx];
                            for(k=0; k<=n-1; k++)
                            {
                                for(q=0; q<=ap.len(qsizes)-1; q++)
                                {
                                    for(i_=0; i_<=nx-1;i_++)
                                    {
                                        x[i_] = xy[k,i_];
                                    }
                                    k0 = nearestneighbor.kdtreequeryknn(tree0, x, qsizes[q], true);
                                    k1 = nearestneighbor.kdtreequeryknn(tree1, x, qsizes[q], true);
                                    if( k0!=k1 )
                                    {
                                        err = true;
                                        return;
                                    }
                                    nearestneighbor.kdtreequeryresultsxy(tree0, ref xy0);
                                    nearestneighbor.kdtreequeryresultsxy(tree1, ref xy1);
                                    for(i=0; i<=k0-1; i++)
                                    {
                                        for(j=0; j<=nx+ny-1; j++)
                                        {
                                            if( (double)(Math.Abs(xy0[i,j]-xy1[i,j]))>(double)(threshold) )
                                            {
                                                err = true;
                                                return;
                                            }
                                        }
                                    }
                                    nearestneighbor.kdtreequeryresultstags(tree0, ref tags0);
                                    nearestneighbor.kdtreequeryresultstags(tree1, ref tags1);
                                    for(i=0; i<=k0-1; i++)
                                    {
                                        if( tags0[i]!=tags1[i] )
                                        {
                                            err = true;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                
                //
                // Next N
                //
                n = n+25;
            }
        }
Esempio n. 10
0
 _helper = new CacheHelper(CacheName, cpf, factory, formatter, serializer, manager, options, DefaultTtl);
Esempio n. 11
0
 ($"{runName}.ParseAndTraversePartial x{traversalCount}", () => ParseAndTraversePartial(serializer, inputBuffer, traversalCount)),
Esempio n. 12
0
 ($"{runName}.ParseAndTraverse x1", () => ParseAndTraverse(serializer, inputBuffer, 1)),
 ($"{runName}.ParseAndTraverse x{traversalCount}", () => ParseAndTraverse(serializer, inputBuffer, traversalCount)),
 Serialize(serializer, record.Value);
Esempio n. 14
0
 /// <summary>
 /// 序列化
 /// </summary>
 /// <param name="parentSerializer">序列化</param>
 /// <param name="isReferenceMember">是否检测相同的引用成员</param>
 protected serializer(serializer parentSerializer, bool isReferenceMember)
     : base(parentSerializer, isReferenceMember)
 {
 }
Esempio n. 15
0
this.change = (_, serializer, json) => change(serializer, json);
 => Definitions = LoadDefinitions(serializer, definitionStreams);