public override MathLiteral Clone() { MathFunction clone = new MathFunction(); clone.BaseOp = (MathOp)BaseOp.Clone(); return(clone); }
public void Tick() { Engine engine = new Engine(); MathFunction clone = null; clone = (MathFunction)root.Clone(); clone.Mutate(); if (clone.ToString() == root.ToString()) { return; } double totNewError = 0; double totOldError = 0; foreach (Case currentCase in problem.Cases) { engine.SetVariable("x", currentCase.X); engine.SetVariable("y", currentCase.Y); double newResult = clone.Evaluate(engine); double oldResult = root.Evaluate(engine); double newError = Math.Abs(currentCase.Result - newResult); double oldError = Math.Abs(currentCase.Result - oldResult); totNewError += newError; totOldError += oldError; } //its a good match if (totNewError < totOldError || ((clone.ToString().Length < root.ToString().Length) && totNewError < totOldError + double.Epsilon)) { //Console.WriteLine(clone.ToString ()); // Console.WriteLine(totNewError.ToString("0.0000000000") + " " + clone.ToString()); root = clone; this.Error = totNewError; } }
public void Tick() { Engine engine = new Engine(); MathFunction clone = null; clone = (MathFunction)root.Clone(); clone.Mutate(); if( clone.ToString() == root.ToString() ) return; double totNewError = 0; double totOldError = 0; foreach( Case currentCase in problem.Cases ) { engine.SetVariable( "x", currentCase.X ); engine.SetVariable( "y", currentCase.Y ); double newResult = clone.Evaluate( engine ); double oldResult = root.Evaluate( engine ); double newError = Math.Abs( currentCase.Result - newResult ); double oldError = Math.Abs( currentCase.Result - oldResult ); totNewError += newError; totOldError += oldError; } //its a good match if( totNewError < totOldError || ( ( clone.ToString().Length < root.ToString().Length ) && totNewError < totOldError + double.Epsilon ) ) { //Console.WriteLine(clone.ToString ()); // Console.WriteLine(totNewError.ToString("0.0000000000") + " " + clone.ToString()); root = clone; this.Error = totNewError; } }
public Organism(Problem problem) { this.problem = problem; root = new MathFunction(); }
public override MathLiteral Clone() { MathFunction clone = new MathFunction(); clone.BaseOp = (MathOp)BaseOp.Clone(); return clone; }
public Organism( Problem problem ) { this.problem = problem; root = new MathFunction(); }