public void TestRenderFunction()
 {
     EncogProgram expression = new EncogProgram("(sin(x)+cos(x))/2");
     RenderCommonExpression render = new RenderCommonExpression();
     String result = render.Render(expression);
     Assert.AreEqual("((sin(x)+cos(x))/2)", result);
 }
 public void TestRenderComplex()
 {
     EncogProgram expression = new EncogProgram("((a+25)^3/25)-((a*3)^4/250)");
     RenderCommonExpression render = new RenderCommonExpression();
     String result = render.Render(expression);
     Assert.AreEqual("((((a+25)^3)/25)-(((a*3)^4)/250))", result);
 }
 public void TestRenderBasic()
 {
     EncogProgram expression = new EncogProgram("(2+6)");
     RenderCommonExpression render = new RenderCommonExpression();
     String result = render.Render(expression);
     Assert.AreEqual("(2+6)", result);
 }
 public void TestKnownConst()
 {
     EncogProgram expression = new EncogProgram("x*2*PI");
     RenderCommonExpression render = new RenderCommonExpression();
     String result = render.Render(expression);
     Assert.AreEqual("((x*2)*PI)", result);
 }
        public void TestKnownConst()
        {
            EncogProgram           expression = new EncogProgram("x*2*PI");
            RenderCommonExpression render     = new RenderCommonExpression();
            String result = render.Render(expression);

            Assert.AreEqual("((x*2)*PI)", result);
        }
        public void TestRenderFunction()
        {
            EncogProgram           expression = new EncogProgram("(sin(x)+cos(x))/2");
            RenderCommonExpression render     = new RenderCommonExpression();
            String result = render.Render(expression);

            Assert.AreEqual("((sin(x)+cos(x))/2)", result);
        }
        public void TestRenderComplex()
        {
            EncogProgram           expression = new EncogProgram("((a+25)^3/25)-((a*3)^4/250)");
            RenderCommonExpression render     = new RenderCommonExpression();
            String result = render.Render(expression);

            Assert.AreEqual("((((a+25)^3)/25)-(((a*3)^4)/250))", result);
        }
        public void TestRenderBasic()
        {
            EncogProgram           expression = new EncogProgram("(2+6)");
            RenderCommonExpression render     = new RenderCommonExpression();
            String result = render.Render(expression);

            Assert.AreEqual("(2+6)", result);
        }
 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));
 }
示例#10
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();
        }
        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));
        }
        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));
        }
        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));
        }
 /// <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);
 }
        /// <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;
                    }
                }
            }
        }
        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));
        }