Exemplo n.º 1
0
        public override MathLiteral Clone()
        {
            MathFunction clone = new MathFunction();

            clone.BaseOp = (MathOp)BaseOp.Clone();
            return(clone);
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
		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;
			}
		}
Exemplo n.º 4
0
 public Organism(Problem problem)
 {
     this.problem = problem;
     root         = new MathFunction();
 }
Exemplo n.º 5
0
		public override MathLiteral Clone() {
			MathFunction clone = new MathFunction();
			clone.BaseOp = (MathOp)BaseOp.Clone();
			return clone;
		}
Exemplo n.º 6
0
		public Organism( Problem problem ) {
			this.problem = problem;
			root = new MathFunction();
		}