Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs	(revision 4249)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs	(revision 4250)
@@ -21,19 +21,12 @@
 
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
 using HeuristicLab.Data;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
 using HeuristicLab.Optimization;
 using HeuristicLab.Parameters;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.PluginInfrastructure;
 using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
-using HeuristicLab.Problems.DataAnalysis.Symbolic;
 
 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
@@ -84,10 +77,10 @@
     public SymbolicRegressionProblem()
       : base() {
-      var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator();
-      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly()));
+      var evaluator = new SymbolicRegressionPearsonsRSquaredEvaluator();
+      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(true)));
       Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
 
-      evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
+      evaluator.QualityParameter.ActualName = "TrainingPearsonR2";
 
       InitializeOperators();
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs	(revision 4249)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs	(revision 4250)
@@ -113,4 +113,5 @@
     public ISymbolicExpressionGrammar FunctionTreeGrammar {
       get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; }
+      private set { FunctionTreeGrammarParameter.Value = value; }
     }
     public override IEnumerable<IOperator> Operators {
@@ -190,4 +191,5 @@
       MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
+      FunctionTreeGrammarParameter.ValueChanged += new EventHandler(FunctionTreeGrammarParameter_ValueChanged);
     }
 
@@ -211,5 +213,5 @@
       UpdateGrammar();
     }
-    protected virtual void OnGrammarChanged(EventArgs e) { }
+    protected virtual void OnGrammarChanged() { UpdateGrammar(); }
     protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }
     protected virtual void OnSolutionCreatorChanged(EventArgs e) {
@@ -231,4 +233,10 @@
 
     #region event handlers
+    private void FunctionTreeGrammarParameter_ValueChanged(object sender, EventArgs e) {
+      if (!(FunctionTreeGrammar is GlobalSymbolicExpressionGrammar))
+        FunctionTreeGrammar = new GlobalSymbolicExpressionGrammar(FunctionTreeGrammar);
+      OnGrammarChanged();
+    }
+
     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
       OnSolutionCreatorChanged(e);
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs	(revision 4249)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs	(revision 4250)
@@ -26,4 +26,5 @@
 using HeuristicLab.Core;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
 
 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
@@ -50,7 +51,13 @@
 
     protected override void RecalculateEstimatedValues() {
-      estimatedValues = (from x in Model.GetEstimatedValues(ProblemData, 0, ProblemData.Dataset.Rows)
-                         let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x))
-                         select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList();
+      int minLag = 0;
+      var laggedTreeNodes = Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>();
+      if (laggedTreeNodes.Any())
+        minLag = laggedTreeNodes.Min(node => node.Lag);
+      IEnumerable<double> calculatedValues =
+          from x in Model.GetEstimatedValues(ProblemData, 0 - minLag, ProblemData.Dataset.Rows)
+          let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x))
+          select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX;
+      estimatedValues = Enumerable.Repeat(double.NaN, Math.Abs(minLag)).Concat(calculatedValues).ToList();
       OnEstimatedValuesChanged();
     }
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs	(revision 4249)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs	(revision 4250)
@@ -69,13 +69,10 @@
       get { return (IValueParameter<Dataset>)Parameters["Dataset"]; }
     }
-
     public IValueParameter<StringValue> TargetVariableParameter {
       get { return (IValueParameter<StringValue>)Parameters["TargetVariable"]; }
     }
-
     public IValueParameter<ICheckedItemList<StringValue>> InputVariablesParameter {
       get { return (IValueParameter<ICheckedItemList<StringValue>>)Parameters["InputVariables"]; }
     }
-
     public IValueParameter<IntValue> TrainingSamplesStartParameter {
       get { return (IValueParameter<IntValue>)Parameters["TrainingSamplesStart"]; }
@@ -109,4 +106,5 @@
           if (TargetVariable != null) DeregisterStringValueEventHandlers(TargetVariable);
           TargetVariableParameter.Value = value;
+          RegisterStringValueEventHandlers(TargetVariable);
         }
       }
@@ -119,4 +117,5 @@
           if (InputVariables != null) DeregisterInputVariablesEventHandlers();
           InputVariablesParameter.Value = value;
+          RegisterInputVariablesEventHandlers();
         }
       }
@@ -129,4 +128,5 @@
           if (TrainingSamplesStart != null) DeregisterValueTypeEventHandlers(TrainingSamplesStart);
           TrainingSamplesStartParameter.Value = value;
+          RegisterValueTypeEventHandlers(TrainingSamplesStart);
         }
       }
@@ -139,4 +139,5 @@
           if (TrainingSamplesEnd != null) DeregisterValueTypeEventHandlers(TrainingSamplesEnd);
           TrainingSamplesEndParameter.Value = value;
+          RegisterValueTypeEventHandlers(TrainingSamplesEnd);
         }
       }
@@ -149,4 +150,5 @@
           if (TestSamplesStart != null) DeregisterValueTypeEventHandlers(TestSamplesStart);
           TestSamplesStartParameter.Value = value;
+          RegisterValueTypeEventHandlers(TestSamplesStart);
         }
       }
@@ -159,4 +161,5 @@
           if (TestSamplesEnd != null) DeregisterValueTypeEventHandlers(TestSamplesEnd);
           TestSamplesEndParameter.Value = value;
+          RegisterValueTypeEventHandlers(TestSamplesEnd);
         }
       }
@@ -242,31 +245,23 @@
 
     #region parameter value changed event handlers
-    void DatasetParameter_ValueChanged(object sender, EventArgs e) {
-      OnProblemDataChanged(EventArgs.Empty);
-    }
-    void InputVariablesParameter_ValueChanged(object sender, EventArgs e) {
-      RegisterInputVariablesEventHandlers();
-      OnProblemDataChanged(EventArgs.Empty);
-    }
-    void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
-      if (TargetVariable != null) {
-        RegisterStringValueEventHandlers(TargetVariable);
-        OnProblemDataChanged(EventArgs.Empty);
-      }
-    }
-    void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
-      RegisterValueTypeEventHandlers(TrainingSamplesStart);
-      OnProblemDataChanged(EventArgs.Empty);
-    }
-    void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
-      RegisterValueTypeEventHandlers(TrainingSamplesEnd);
-      OnProblemDataChanged(EventArgs.Empty);
-    }
-    void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
-      RegisterValueTypeEventHandlers(TestSamplesStart);
-      OnProblemDataChanged(EventArgs.Empty);
-    }
-    void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
-      RegisterValueTypeEventHandlers(TestSamplesEnd);
+    private void DatasetParameter_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void InputVariablesParameter_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
+      if (TargetVariable != null) OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void TrainingSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void TrainingSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void TestSamplesStartParameter_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(EventArgs.Empty);
+    }
+    private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) {
       OnProblemDataChanged(EventArgs.Empty);
     }
@@ -278,6 +273,7 @@
       InputVariables.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_ItemsRemoved);
       InputVariables.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<StringValue>>(InputVariables_CheckedItemsChanged);
-      foreach (var item in InputVariables)
+      foreach (var item in InputVariables) {
         item.ValueChanged += new EventHandler(InputVariable_ValueChanged);
+      }
     }
 
@@ -295,5 +291,4 @@
       OnProblemDataChanged(e);
     }
-
     private void InputVariables_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
       foreach (var indexedItem in e.Items)
@@ -301,5 +296,4 @@
       OnProblemDataChanged(e);
     }
-
     private void InputVariables_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
       foreach (var indexedItem in e.Items)
@@ -307,5 +301,4 @@
       OnProblemDataChanged(e);
     }
-
     private void InputVariables_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<StringValue>> e) {
       foreach (var indexedItem in e.OldItems)
@@ -313,30 +306,25 @@
       OnProblemDataChanged(e);
     }
-
-    void InputVariable_ValueChanged(object sender, EventArgs e) {
-      OnProblemDataChanged(e);
-    }
+    private void InputVariable_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(e);
+    }
+
     #region helper
-
     private void RegisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
       value.ValueChanged += new EventHandler(value_ValueChanged);
     }
-
     private void DeregisterValueTypeEventHandlers<T>(ValueTypeValue<T> value) where T : struct {
       value.ValueChanged -= new EventHandler(value_ValueChanged);
     }
-
-    void value_ValueChanged(object sender, EventArgs e) {
-      OnProblemDataChanged(e);
-    }
-
     private void RegisterStringValueEventHandlers(StringValue value) {
       value.ValueChanged += new EventHandler(value_ValueChanged);
     }
-
     private void DeregisterStringValueEventHandlers(StringValue value) {
       value.ValueChanged -= new EventHandler(value_ValueChanged);
     }
 
+    private void value_ValueChanged(object sender, EventArgs e) {
+      OnProblemDataChanged(e);
+    }
     #endregion
     #endregion
