Ejemplo n.º 1
0
    //---------------------------------------------------------

    void Start()
    {
        netWorkInit  = GetComponent <NetworkInit>();
        learnManager = GetComponent <LearnManager>();
        storeManager = GetComponent <StoreManager>();


        sensorFields = new List <Field>();
        hiddenFields = new List <Field>();
        outputFields = new List <Field>();

        int inputFieldNumb = netWorkInit.networkStructure[0];

        edgeLength = Mathf.Sqrt(inputFieldNumb);
        edgeWidth  = edgeLength;
        gridWidth  = 1f;
        xOffset    = gridWidth / 2f;

        Vector3 camPosition = new Vector3(edgeWidth * gridWidth * 1.3f, edgeLength * gridWidth * 1.5f, -edgeLength * gridWidth / 2f + 1f);

        cam.transform.position = camPosition;
        Vector3 camRotation = new Vector3(90, 0, 0);

        cam.transform.rotation = Quaternion.Euler(camRotation);
    }
Ejemplo n.º 2
0
        static void compute(List <Agent> agents, LearnManager lm)
        {
            var home = agents[0].Home;

            for (int tick = 0; true; tick++)
            {
                Thread.Sleep(compute_fps);
                while (computePause)
                {
                    Thread.Sleep(1);
                }
                try
                {
                    for (int i = agents.Count - 1; i >= 0; i--)
                    {
                        agents[i].PreDo();
                        if (agents[i].Dead)
                        {
                            agents[i] = ((MyAgent)agents[i]).BornNew(home);
                            //agents.RemoveAt(i);
                        }
                        else
                        {
                            agents[i].Do();
                        }
                    }
                }
                catch (Exception ex) { Console.WriteLine(ex); }
            }
        }
Ejemplo n.º 3
0
        public static void Go(Field field, LearnManager lm, List <Agent> agents)
        {
            Console.WriteLine("START");

            var ctrl = new FieldControl((IFieldWithCells)field);

            var form = new Form();

            form.Controls.Add(ctrl);
            ctrl.Location   = new System.Drawing.Point(10, 10);
            form.Size       = new System.Drawing.Size(ctrl.Width + 40, ctrl.Height + 60);
            form.KeyPreview = true;
            form.KeyUp     += (s, e) =>
            {
                if (e.KeyCode == Keys.Right)
                {
                    compute_fps = Math.Max(0, compute_fps - 10);
                }
                else if (e.KeyCode == Keys.Left)
                {
                    compute_fps = Math.Min(300, compute_fps + 10);
                }
                else if (e.KeyCode == Keys.Space)
                {
                    computePause = !computePause;
                }
                form.Text = $"{nameof(compute_fps)} = {1000 / Math.Max(double.Epsilon, compute_fps)}";
            };
            form.Text = $"{nameof(compute_fps)} = {1000 / Math.Max(double.Epsilon, compute_fps)}";

            engine(agents, form, lm);

            Application.Run(form);
        }
Ejemplo n.º 4
0
        public override void OnDies(LearnManager lm, Agent baseOfMutation)
        {
            var    tracker = (ITrackHistory)baseOfMutation;
            double fit     = baseOfMutation.GetFitness();

            var list = tracker.History.Buffer;

            for (int i = 0, n = tracker.History.Length; i < n; i++)
            {
                var correct = LearnManager.GetCorrect(list[i].Value, lm.GetMeanRatioNormalized(fit));
                TR.TrainOne(list[i].Position, new double[] { correct }, learningRate: 0.1, momentum: 0);
            }

            tracker.CleanHistory();
        }
Ejemplo n.º 5
0
        public override Genome OnBirth(LearnManager lm, Agent parent)
        {
            Genome re;

            //var lma = (MyLearnManager)lm;

            if (U.Rand() > MUTATE_RATE)
            {
                re = lm.GetWagedRandomGenome();
            }
            else
            {
                re = new MyGenome();
            }

            return(re);
        }
Ejemplo n.º 6
0
    //---------------------------------------------

    void Start()
    {
        patternArchiveList = new List <Archive>();

        // streamingAssetsPath = Application.streamingAssetsPath + "/";
        streamingAssetsPath = "http://jojo-studio.de/Projekte/NeuralNetwork/StreamingAssets/";


        netWorkInit  = GetComponent <NetworkInit>();
        sensorField  = GetComponent <SensorField>();
        learnManager = GetComponent <LearnManager>();

        StartCoroutine(LoadNetworkFromWeb());
        ///StartCoroutine(LoadPatternArchive("ExercisePattern"));
        //StartCoroutine(LoadPatternArchive("TestPattern"));
        StartCoroutine(WaitForLoadingFiles());
    }
Ejemplo n.º 7
0
        static void engine(List <Agent> agents, Form f, LearnManager lm)
        {
            new Thread(computeMy).Start();
            new Thread(drawMy).Start();
            new Thread(reportMy).Start();

            void computeMy()
            {
                compute(agents, lm);
            }

            void drawMy()
            {
                draw(f);
            }

            void reportMy()
            {
                report(agents, lm);
            }
        }
Ejemplo n.º 8
0
        static void report(List <Agent> agents, LearnManager lm)
        {
            string str = "";
            //var toplist = new ModuloList<MyGenom>(10);
            int global_max = int.MinValue;


            while (true)
            {
                Thread.Sleep(300);
                while (computePause)
                {
                    Thread.Sleep(1);
                }

                int max_on_cycle = (int)(1.0 / lm.GetMaxRatio(1));
                if (max_on_cycle > global_max)
                {
                    global_max = max_on_cycle;
                    //toplist.SetNext(lm.GetGenoms.Max(z => z.)
                }

                if (lm.DeathCount < lastDeath)
                {
                }

                print($"Death count:          {lm.DeathCount}");
                print($"Average live time:    {lm.GetAverage()}");
                print($"Max live time:        {max_on_cycle}");
                print($"Global max live time: {global_max}");
                print($"");

                Console.WriteLine(str); str = "";
            }

            void print(string s)
            {
                str += s + '\n';
            }
        }
Ejemplo n.º 9
0
    //-----------------------------------------------------

    private void Start()
    {
        //Button btn = button.GetComponent<Button>();
        // btn.onClick.AddListener(NewNetwork);

        networkStructure = new List <int> {
            400, 20, 10
        };

        sensorField  = GetComponent <SensorField>();
        learnManager = GetComponent <LearnManager>();
        storeManager = GetComponent <StoreManager>();

        Result zero = new Result();

        zero.iD   = 0;
        zero.name = "Null";
        zero.outputConfiguration = new List <float>()
        {
            1, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };
        // zero.outputConfiguration = new List<float>() { 0 , 0, 0, 0, 0};
        Result one = new Result();

        one.iD   = 1;
        one.name = "Eins";
        one.outputConfiguration = new List <float>()
        {
            0, 1, 0, 0, 0, 0, 0, 0, 0, 0
        };
        //one.outputConfiguration = new List<float>() { 1 , 0, 0, 0, 0};
        Result two = new Result();

        two.iD   = 2;
        two.name = "Zwei";
        two.outputConfiguration = new List <float>()
        {
            0, 0, 1, 0, 0, 0, 0, 0, 0, 0
        };
        // two.outputConfiguration = new List<float>() { 0, 1, 0, 0, 0};

        Result three = new Result();

        three.iD   = 3;
        three.name = "Drei";
        three.outputConfiguration = new List <float>()
        {
            0, 0, 0, 1, 0, 0, 0, 0, 0, 0
        };
        //three.outputConfiguration = new List<float>() { 0 , 0, 1, 0, 0};
        Result four = new Result();

        four.iD   = 4;
        four.name = "Vier";
        four.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 1, 0, 0, 0, 0, 0
        };
        // four.outputConfiguration = new List<float>() { 0 , 0, 0, 1, 0};
        Result five = new Result();

        five.iD   = 5;
        five.name = "Fünf";
        five.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 0, 1, 0, 0, 0, 0
        };
        //five.outputConfiguration = new List<float>() { 0 , 0, 0, 0, 1};
        Result six = new Result();

        six.iD   = 6;
        six.name = "Sechs";
        six.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 0, 0, 1, 0, 0, 0
        };
        //six.outputConfiguration = new List<float>() { 1 , 1, 0, 0, 0};
        Result seven = new Result();

        seven.iD   = 7;
        seven.name = "Sieben";
        seven.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 0, 0, 0, 1, 0, 0
        };
        //seven.outputConfiguration = new List<float>() { 1 , 0, 1, 0, 0};
        Result eight = new Result();

        eight.iD   = 8;
        eight.name = "Acht";
        eight.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 0, 0, 0, 0, 1, 0
        };
        //eight.outputConfiguration = new List<float>() { 1 , 0, 0, 1, 0};
        Result nine = new Result();

        nine.iD   = 9;
        nine.name = "Neun";
        nine.outputConfiguration = new List <float>()
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 1
        };
        //nine.outputConfiguration = new List<float>() {1, 0, 0, 0, 1};

        expectedResults = new List <Result>()
        {
            zero, one, two, three, four, five, six, seven, eight, nine
        };
    }
Ejemplo n.º 10
0
 public override void OnDies(LearnManager lm, Agent baseOfMutation) /*EMPTY*/ }
Ejemplo n.º 11
0
 public abstract Genome OnBirth(LearnManager lm, Agent parent);
Ejemplo n.º 12
0
 public abstract void OnDies(LearnManager lm, Agent baseOfMutation);