Пример #1
0
        public void TestBuildHiddenset()
        {
            var gp        = new Gp();
            var hiddenset = gp.BuildHiddenSet();

            TestOutput(JsonConvert.SerializeObject(hiddenset));
        }
Пример #2
0
        public void TestMakeRandomTree()
        {
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };
            var random1        = Gp.MakeRandomTree(paramArr);

            var printer = new GpPrinter();

            TestOutput(printer.Display(random1));

            var func = Expression.Lambda <Func <int, int, int> >(random1, paramArr).Compile();

            TestOutput(func(7, 1));
            TestOutput(func(2, 4));

            var random2 = Gp.MakeRandomTree(paramArr);

            TestOutput(printer.Display(random2));

            var func2 = Expression.Lambda <Func <int, int, int> >(random2, paramArr).Compile();

            TestOutput(func2(5, 3));
            TestOutput(func2(5, 20));
        }
Пример #3
0
        public void TestEvolve()
        {
            var gp             = new Gp(TestOutput);
            var rf             = gp.GetRankFunction(gp.BuildHiddenSet());
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };

            gp.Evolve(paramArr, 500, rf, mutationrate: 0.2, breedingreate: 0.1, pexp: 0.7, pnew: 0.1);
        }
Пример #4
0
        public void TestMutate()
        {
            var gp             = new Gp();
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };
            var random1        = Gp.MakeRandomTree(paramArr);

            var printer = new GpPrinter();

            TestOutput(printer.Display(random1));

            TestOutput("-----------我是分隔线-------------");

            var newExp = gp.Mutate(random1, paramArr);

            TestOutput(printer.Display(newExp));
        }
Пример #5
0
        public void TestScoreFunction()
        {
            var gp             = new Gp();
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };
            var random1        = Gp.MakeRandomTree(paramArr);
            var func           = Expression.Lambda <Func <int, int, int> >(random1, paramArr).Compile();
            var hiddenset      = gp.BuildHiddenSet();
            var diff           = gp.ScoreFunction(func, hiddenset);

            TestOutput(diff);
            var random2 = Gp.MakeRandomTree(paramArr);
            var func2   = Expression.Lambda <Func <int, int, int> >(random2, paramArr).Compile();

            diff = gp.ScoreFunction(func2, hiddenset);
            TestOutput(diff);
        }
Пример #6
0
        public void TestMutateResult()
        {
            var gp             = new Gp();
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };
            var random1        = Gp.MakeRandomTree(paramArr);

            var hiddenset = gp.BuildHiddenSet();
            var func1     = random1.Compile <Func <int, int, int> >(paramArr);

            TestOutput(gp.ScoreFunction(func1, hiddenset));

            TestOutput("-----------我是分隔线-------------");

            var newExp     = gp.Mutate(random1, paramArr);
            var funcMutate = newExp.Compile <Func <int, int, int> >(paramArr);

            TestOutput(gp.ScoreFunction(funcMutate, hiddenset));
        }
Пример #7
0
        public void TestCrossOver()
        {
            var gp             = new Gp();
            var printer        = new GpPrinter();
            var input1ParamExp = Expression.Parameter(typeof(int), "input1");
            var input2ParamExp = Expression.Parameter(typeof(int), "input2");
            var paramArr       = new[] { input1ParamExp, input2ParamExp };
            var random1        = Gp.MakeRandomTree(paramArr);

            TestOutput(printer.Display(random1));

            TestOutput("-----------我是分隔线-------------");

            var random2 = Gp.MakeRandomTree(paramArr);

            TestOutput(printer.Display(random2));

            TestOutput("-----------我是分隔线-------------");

            var crossed = gp.CrossOver(random1, random2);

            TestOutput(printer.Display(crossed));
        }