public void Eval(String start, String expect)
        {
            EncogProgramContext context = new EncogProgramContext();

            StandardExtensions.CreateNumericOperators(context);
            PrgPopulation   pop   = new PrgPopulation(context, 1);
            ICalculateScore score = new ZeroEvalScoreFunction();

            TrainEA genetic = new TrainEA(pop, score);

            genetic.ValidationMode = true;
            genetic.CODEC          = new PrgCODEC();
            genetic.AddOperation(0.95, new SubtreeCrossover());
            genetic.AddOperation(0.05, new SubtreeMutation(context, 4));
            genetic.AddScoreAdjuster(new ComplexityAdjustedScore());
            genetic.Rules.AddRewriteRule(new RewriteConstants());
            genetic.Rules.AddRewriteRule(new RewriteAlgebraic());

            EncogProgram expression = new EncogProgram(context);

            expression.CompileExpression(start);
            RenderCommonExpression render = new RenderCommonExpression();

            genetic.Rules.Rewrite(expression);
            Assert.AreEqual(expect, render.Render(expression));
        }
        public void TestCrossoverOperation()
        {
            RenderCommonExpression render = new RenderCommonExpression();
            EncogProgram           prg    = new EncogProgram("1+2");
            EncogProgram           prg2   = new EncogProgram("4+5");
            ProgramNode            node   = prg.FindNode(2);

            prg.ReplaceNode(node, prg2.RootNode);
            Assert.AreEqual("(1+(4+5))", render.Render(prg));
        }
Esempio n. 3
0
        public void TestDepth()
        {
            EncogProgramContext context = new EncogProgramContext();
            context.DefineVariable("x");

            StandardExtensions.CreateAll(context);

            PrgGrowGenerator rnd = new PrgGrowGenerator(context, 2);
            EncogProgram prg = (EncogProgram)rnd.Generate(new EncogRandom());
            RenderCommonExpression render = new RenderCommonExpression();
        }
Esempio n. 4
0
        public void TestSimpleClone()
        {
            EncogProgramContext context = new EncogProgramContext();

            context.LoadAllFunctions();
            RenderCommonExpression render = new RenderCommonExpression();

            EncogProgram prg1 = context.CreateProgram("1*2*3");
            EncogProgram prg2 = context.CloneProgram(prg1);

            Assert.AreEqual("((1*2)*3)", render.Render(prg1));
            Assert.AreEqual("((1*2)*3)", render.Render(prg2));
        }
Esempio n. 5
0
        private void Validate(PrgPopulation pop)
        {
            IList <IGenome> list = pop.Flatten();

            Assert.AreEqual(2, list.Count);

            EncogProgram prg1 = (EncogProgram)list[0];
            EncogProgram prg2 = (EncogProgram)list[1];

            RenderCommonExpression render = new RenderCommonExpression();

            Assert.AreEqual("(x+1)", render.Render(prg1));
            Assert.AreEqual("((x+5)/2)", render.Render(prg2));
        }
Esempio n. 6
0
        public void TestCloneComplex()
        {
            EncogProgramContext context = new EncogProgramContext();

            context.LoadAllFunctions();
            context.DefineVariable("a");
            RenderCommonExpression render = new RenderCommonExpression();

            EncogProgram prg1 = context.CreateProgram("((a+25)^3/25)-((a*3)^4/250)");
            EncogProgram prg2 = context.CloneProgram(prg1);

            Assert.AreEqual("((((a+25)^3)/25)-(((a*3)^4)/250))", render.Render(prg1));
            Assert.AreEqual("((((a+25)^3)/25)-(((a*3)^4)/250))", render.Render(prg2));
        }
Esempio n. 7
0
        /// <summary>
        ///     Dump the specified number of genomes.
        /// </summary>
        /// <param name="i">The specified number of genomes.</param>
        public void DumpMembers(int i)
        {
            var render = new RenderCommonExpression();

            int index = 0;

            foreach (ISpecies species in Species)
            {
                Console.Out.WriteLine("** Species: " + species);
                foreach (IGenome obj in species.Members)
                {
                    var prg = (EncogProgram)obj;
                    Console.WriteLine(index + ": Score " + prg.Score + " : "
                                      + render.Render(prg));
                    index++;
                    if (index > i)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     The string as a common "infix" expression.
        /// </summary>
        /// <returns>The string as a common "infix" expression.</returns>
        public String DumpAsCommonExpression()
        {
            var render = new RenderCommonExpression();

            return(render.Render(this));
        }