コード例 #1
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        /// <summary>
        /// Creates and draws examples of randomly generated programs according to some profile.
        /// </summary>
        /// <param name="args"></param>
        static void Main1(string[] args)
        {
            /*
             * //NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(new List<SolutionProgram> { getProgram0(), getProgram1(), getProgram2() }, atLeastOneOfEach: true);
             * NodeTypeRelativizedFrequencyProfile p = NodeTypeRelativizedFrequencyProfile.createProfile(new List<SolutionProgram> { getProgram0(), getProgram1(), getProgram2() });
             *
             * for (int i = 0; i < 50; i++)
             * {
             *      //SolutionProgram pr = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, p, 10));
             *      SolutionProgram pr = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, p, 10, null));
             *      Console.WriteLine(pr.ToString());
             *      new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(pr));
             *      Console.WriteLine();
             * }
             */



            //enumerates and visualizes all trees with depth <= given number
            int depth = 2;

            foreach (var item in SearchMethodsSupport.enumerateAllTrees(NodeClass.numeric, depth))
            {
                new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(item));
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        //TODO
        //dodelat spravne odsazovani u metody tostring u Nodu

        //do profilu (nebo jinam) dat pravidla co kde muze a nesmi byt. napr. v tele forcyklu se musi vyskytovat ridici promenna, u operatoru nesmi byt jen konstanty
        //to se da udelat tak, ze prvni argument operatoru nesmi byt konstanta (a to by se propagovalo hloubs)
        //v celem programu se musi prirazovat do vysledku a cist vstupy atd..

        //pri generovani podstromu by hloubka nemela byt pouze fixni, ale mely by tam byt vsechny stromy s hloubkou mensi rovnou danemu limitu

        //profil nebude uniformni, ale podmineny, tzn. nebude dana "globalni pravdepodobnost vyskytu typu uzlu", ale "pravdepodobnost vyskytu typu uzlu v zavislosti na typu rodice"
        //To by melo omezit vyskyt ReadVar -> ReadVar a podobne.	-- DONE

        //pri hodnoceni uspesnosti programu je nutne brat v uvahu nejen vysledek, ale i neco dalsiho. Napr. hodnoty vnitrnich promennych na konci, posloupnost hodnot vnitrnich promennych v prubehu vypoctu, nebo neco podobneho
        //obecne by to mely byt kriteria, ktera bud zada uzivatel, nebo se najdou automaticky (pomoci "korelaci" vstupu s pozadovanymi vystupy, resp. kriterium je "uzitecne" pokud pro vsechny x: korelace(krit(x), target(x)) je velka.
        //Pricemz "korelace" je spis v Kolmogorovskem smyslu - tzn. {a_i} a {b_i} maji velkou korelaci pokud program, ktery pro vsechny "i" prevadi a_i na b_i je kratky)

        //prohledavani prostoru programu:
        //A* s heuristikou, kde heuristika je "velikost programu, ktery prevadi vystup toho, co mame ted, na pozadovany vystup" (pomoci aproximace kolmogorovske slozitosti)
        //MCTS - podobne. program se bude stavet pomoci MCTS, heuristika bude ohodnoceni, pravdepodobne pouzit AMAF, v listech delat samplovani (vyhodnoti se vzdycky jen na malem mnozstvi samplu pri kazde navsteve)


        /// <summary>
        /// Enumerates all trees of given depth
        /// </summary>
        /// <param name="args"></param>
        static void Main5(string[] args)
        {
            NodeTypeFrequencyProfile p = new NodeTypeFrequencyProfile();

            for (int depth = 3; depth < 5; depth++)
            {
                //Console.WriteLine("number of graphs of depth " + depth + ": " + TreeIterator.enumerateAllTrees(NodeClass.directive, depth, p).Count());
                //continue;

                foreach (var tree in TreeIterator.enumerateAllTrees(NodeClass.directive, depth, p))
                {
                    new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(new SolutionProgram((DirectiveNode)(tree))));
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        /// <summary>
        /// Main function for testing the search.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(new List<SolutionProgram> { getProgram0(), getProgram1(), getProgram2() }, true);
            NodeTypeRelativizedFrequencyProfile p = NodeTypeRelativizedFrequencyProfile.createProfile(new List <SolutionProgram> {
                getProgram0(), getProgram1(), getProgram2()
            });

            //TrainingSamplesGenerator g = new SimpleCopySamplesGenerator();
            TrainingSamplesGenerator g = new MaximumOfTwo_SamplesGenerator();
            //TrainingSamplesGenerator g = new AlwaysOne_SamplesGenerator();

            //RandomMutationSearch s = new RandomMutationSearch(generator: g, mutationsInEachStep: 5, profile: p);
            SearchAlgorithm s = new FullEnumerationSearch(generator: g);

            var res = s.search(TimeSpan.FromMinutes(10));

            new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(res));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        static void Main2(string[] args)
        {
            //SolutionProgram p = getProgram0();
            //SolutionProgram p = getProgram1();
            SolutionProgram p = getProgram2();

            Interpret i = new Interpret();

            i.numericInputs = new List <int>()
            {
                97
            };
            Console.WriteLine(p.ToString());
            p.execute(i);
            new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(p));
            Console.WriteLine("inputs: " + string.Join(" ", i.numericInputs));
            Console.WriteLine("outputs: " + string.Join(" ", i.outputs));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        /// <summary>
        /// To test the primality testing program and Erratic sequence program
        /// </summary>
        /// <param name="args"></param>
        static void Main4(string[] args)
        {
            runEvaluation(new PrimalityTestingSamplesGenerator(), getProgram2(), 10000, quiet: true);
            new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(getProgram2()));

            //applies a random mutation to the program and evaluates it. Repeates 10-times.
            NodeTypeRelativizedFrequencyProfile prof = NodeTypeRelativizedFrequencyProfile.createProfile(new List <SolutionProgram> {
                getProgram0(), getProgram1(), getProgram2()
            });
            PointMutation m = new PointMutation(prof, 1);

            for (int i = 0; i < 10; i++)
            {
                var p = getProgram2();
                m.modify(p);
                new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(p));
                runEvaluation(new PrimalityTestingSamplesGenerator(), p, 10000, quiet: true);
            }
            //runEvaluation(new ErraticSequenceLengthSamplesGenerator(), getProgram1(), 10000);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: otaTrunda/ProgramBreeder
        /// <summary>
        /// To test the Clone() method
        /// </summary>
        /// <param name="args"></param>
        static void Main3(string[] args)
        {
            NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(new List <SolutionProgram> {
                getProgram0(), getProgram1(), getProgram2()
            }, true);

            for (int i = 0; i < 50; i++)
            {
                Console.WriteLine("New random program:");
                SolutionProgram pr = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, p, 10));
                Console.WriteLine(pr.ToString());
                new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(pr));
                Console.WriteLine();
                Console.WriteLine("CLONE:");
                SolutionProgram clon = (SolutionProgram)pr.Clone();
                Console.WriteLine(clon.ToString());
                new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(clon));
                Console.WriteLine();
            }
        }