Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs (revision 3374)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs (revision 3374)
@@ -0,0 +1,92 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Drawing;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
+ [Item("SymbolicRegressionEvaluator", "Evaluates a symbolic regression solution.")]
+ [StorableClass]
+ public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator {
+ private const string QualityParameterName = "Quality";
+ private const string FunctionTreeParameterName = "FunctionTree";
+ private const string RegressionProblemDataParameterName = "RegressionProblemData";
+ private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";
+ #region ISymbolicRegressionEvaluator Members
+
+ public ILookupParameter QualityParameter {
+ get { return (ILookupParameter)Parameters[QualityParameterName]; }
+ }
+
+ public ILookupParameter FunctionTreeParameter {
+ get { return (ILookupParameter)Parameters[FunctionTreeParameterName]; }
+ }
+
+ public ILookupParameter RegressionProblemDataParameter {
+ get { return (ILookupParameter)Parameters[RegressionProblemDataParameterName]; }
+ }
+
+ //public ILookupParameter SamplesStartParameter {
+ // get { return (ILookupParameter)Parameters["SamplesStart"]; }
+ //}
+
+ //public ILookupParameter SamplesEndParameter {
+ // get { return (ILookupParameter)Parameters["SamplesEnd"]; }
+ //}
+
+ public ILookupParameter NumberOfEvaluatedNodesParameter {
+ get { return (ILookupParameter)Parameters[NumberOfEvaluatedNodexParameterName]; }
+ }
+
+ #endregion
+
+ public SymbolicRegressionEvaluator()
+ : base() {
+ Parameters.Add(new LookupParameter(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
+ Parameters.Add(new LookupParameter(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
+ Parameters.Add(new LookupParameter(RegressionProblemDataParameterName, "The data set on which the symbolic regression solution should be evaluated."));
+ Parameters.Add(new LookupParameter(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)"));
+ }
+
+ public override IOperation Apply() {
+ SymbolicExpressionTree solution = FunctionTreeParameter.ActualValue;
+ DataAnalysisProblemData regressionProblemData = RegressionProblemDataParameter.ActualValue;
+ DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
+
+ QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, regressionProblemData.Dataset, regressionProblemData.TargetVariable, regressionProblemData.TrainingSamplesStart, regressionProblemData.TrainingSamplesEnd, numberOfEvaluatedNodes));
+ return null;
+ }
+
+ protected abstract double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes);
+ }
+}
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs (revision 3374)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs (revision 3374)
@@ -0,0 +1,57 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Drawing;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Operators;
+using HeuristicLab.Problems.DataAnalysis.Evaluators;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
+
+namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
+ [Item("SymbolicRegressionMeanSquaredErrorEvaluator", "Calculates the mean squared error of a symbolic regression solution.")]
+ [StorableClass]
+ public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
+ protected override double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes) {
+ double mse = Calculate(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
+ numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value);
+ return mse;
+ }
+
+ public static double Calculate(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {
+ SimpleArithmeticExpressionEvaluator evaluator = new SimpleArithmeticExpressionEvaluator();
+ int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
+ var estimatedValues = evaluator.EstimatedValues(solution, dataset, Enumerable.Range(start, end - start));
+ var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex];
+ return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues);
+ }
+ }
+}