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)); }
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)); }
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); }
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)); }
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)); }