Beispiel #1
0
    static void Main()
    {
        double[][] inputs = new double[10][];
        double[][] targets = new double[10][];
        int temp;
        for(int i=0;i<10;i++)
        {
            double[] array = new double[25000];
            temp = Network.random.Next(0,2);
            int a = 0;
            int b = 0;
            int c = 0;
            int d = 0;
            int e = 0;

            for(int j=0;j<25000;j++)
            {
                temp = Network.random.Next(0,2);
                a = (a+temp)%2;
                b = (b+temp)%3;
                c = (c+temp)%5;
                d = (d+temp)%7;
                e = (e+temp)% 11;
                array[j] = temp;
            }

            double[] tar = new double[]{a, b/2.0, c/4.0, d/6.0, e/10.0};
            inputs[i]=Functions.copyDoubleArray(array);
            targets[i]=Functions.copyDoubleArray(tar);
        }
         Network net = new Network();
         net.addLayers(25000,1000,5);
         net.setVerbosity(0);
         net.setInputs(inputs);
         net.setTargets(targets);
         net.setReportRate(1);
         net.setResetEpoch(100000);
         net.setTolerance(.4);
         Console.WriteLine("Generated patterns");
         DateTime start = DateTime.Now;
         net.train(0,10);
         TimeSpan timeTaken = DateTime.Now - start;
         Console.WriteLine("Minutes: " + timeTaken.Minutes);
         Console.WriteLine("Seconds: " + timeTaken.Seconds);
         Console.WriteLine("Milliseconds: " + timeTaken.Milliseconds);

        /*
        Random rand = new Random();
        SRN net = new SRN();
        net.addSRNLayers(3,3,3);
        net.tolerance = .3;
        double[][] inputs = new double[99][];
        double temp = 0;
        for(int i = 0; i< 99; i++)
        {
            if(i%3 == 0)
            {
                inputs[i] = new double[]{.9,.1,.1};
            }
            else
            {
                if (temp==2)
                {
                    inputs[i] = new double[]{.1,.9,.1};
                    temp = 0;
                }
                else
                {
                    if (temp == 3)
                    {
                        inputs[i] = new double[]{.1,.1,.9};
                        temp = 0;
                    }
                    else
                    {
                        temp = rand.Next(2,4);
                        if (temp==2)
                        {
                            inputs[i] = new double[]{.1,.1,.9};
                        }
                        else
                        {
                            inputs[i] = new double[]{.1,.9,.1};
                        }
                    }
                }
            }
        }
        double[][] targets = new double[99][];
        for(int i=0; i<98;i++)
        {
            targets[i] = inputs[i+1];
        }
        targets[98] = new double[]{.9,.1,.1};

        net.setInputs(inputs);
        net.setTargets(targets);
        net.setSequenceType("ordered-continuous");
        net.setReportRate(10);
        net.train();

        */

        /*

        //very simple Network for debugging

        double[][] inputs = new double[2][];
        double[][] targets = new double[2][];
        double[] a1 = new double[]{0,1};
        double[] a2 = new double[]{1,0};
        double[] b1 = new double[]{1};
        double[] b2 = new double[]{0};
        inputs[0]=a1;
        inputs[1]=a2;
        targets[0]=b1;
        targets[1]=b2;

        Network net = new Network();
        net.addThreeLayers(2,1,1);
        net.setInputs(inputs);
        net.setTargets(targets);
        net.setTolerance(.4);
        net.setVerbosity(0);
        net.setReportRate(1);
        net.saveInputsToFile("intest.conx");
        net.loadInputsFromFile("intest.conx");
        net.saveTargetsToFile("tartest.conx");
        net.loadTargetsFromFile("tartest.conx");
        net.layers[0].weight[0]=0;
        net.layers[0].weight[1]=0;
        net.layers[1].weight[0]=0;
        net.layers[2].weight[0]=0;
        net.connections[0].weight[0][0]=0;
        net.connections[0].weight[1][0]=0;
        net.connections[1].weight[0][0]=0;
        net.setOrderedInputs(true);
        net.setVerbosity(0);
        net.train(0,1000);

        Console.WriteLine("Done.");
        */
    }