public void TestBuildHiddenset() { var gp = new Gp(); var hiddenset = gp.BuildHiddenSet(); TestOutput(JsonConvert.SerializeObject(hiddenset)); }
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); }
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)); }