Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj	(revision 3847)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj	(revision 3848)
@@ -86,4 +86,5 @@
     <Compile Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs" />
     <Compile Include="LinearRegression\LinearRegressionSolutionCreator.cs" />
+    <Compile Include="LinearRegression\LinearRegressionUtil.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="SupportVectorRegression\BestSupportVectorRegressionSolutionAnalyzer.cs" />
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionSolutionCreator.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionSolutionCreator.cs	(revision 3847)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionSolutionCreator.cs	(revision 3848)
@@ -33,4 +33,5 @@
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
 using HeuristicLab.Parameters;
+using HeuristicLab.Data;
 
 namespace HeuristicLab.Problems.DataAnalysis.Regression.LinearRegression {
@@ -43,8 +44,12 @@
     private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
+    private const string SamplesStartParameterName = "SamplesStart";
+    private const string SamplesEndParameterName = "SamplesEnd";
 
     public LinearRegressionSolutionCreator() {
       Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The resulting solution encoded as a symbolic expression tree."));
       Parameters.Add(new LookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The problem data on which the linear regression should be calculated."));
+      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName,"The start of the samples on which the linear regression should be applied."));
+      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName,"The end of the samples on which the linear regression should be applied."));
     }
     [StorableConstructor]
@@ -69,21 +74,36 @@
       set { DataAnalysisProblemDataParameter.ActualValue = value; }
     }
+
+    public IValueLookupParameter<IntValue> SamplesStartParameter {
+      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
+    }
+    public IntValue SamplesStart {
+      get { return SamplesStartParameter.ActualValue; }
+      set { SamplesStartParameter.ActualValue = value; }
+    }
+
+    public IValueLookupParameter<IntValue> SamplesEndParameter {
+      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
+    }
+    public IntValue SamplesEnd {
+      get { return SamplesEndParameter.ActualValue; }
+      set { SamplesEndParameter.ActualValue = value; }
+    }
     #endregion
 
 
     public override IOperation Apply() {
-      SymbolicExpressionTree = CreateSymbolicExpressionTree(DataAnalysisProblemData);
+      SymbolicExpressionTree = CreateSymbolicExpressionTree(DataAnalysisProblemData.Dataset,DataAnalysisProblemData.TargetVariable.Value, DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value), SamplesStart.Value, SamplesEnd.Value);
       return base.Apply();
     }
 
-    public static SymbolicExpressionTree CreateSymbolicExpressionTree(DataAnalysisProblemData problem) {
-      List<int> allowedRows = CalculateAllowedRows(problem);
-      double[,] inputMatrix = PrepareInputMatrix(problem, allowedRows);
+    public static SymbolicExpressionTree CreateSymbolicExpressionTree(Dataset dataset, string targetVariable, IEnumerable<string> allowedInputVariables, int start, int end) {
+      double[,] inputMatrix = LinearRegressionUtil.PrepareInputMatrix(dataset, targetVariable, allowedInputVariables, start, end);
 
       alglib.linreg.linearmodel lm = new alglib.linreg.linearmodel();
       alglib.linreg.lrreport ar = new alglib.linreg.lrreport();
       int nRows = inputMatrix.GetLength(0);
-      int nFeatures = inputMatrix.GetLength(1) -1;
-      double[] coefficients = new double[nFeatures +1]; //last coefficient is for the constant
+      int nFeatures = inputMatrix.GetLength(1) - 1;
+      double[] coefficients = new double[nFeatures + 1]; //last coefficient is for the constant
 
       int retVal = 1;
@@ -91,15 +111,15 @@
       if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression model");
 
-      for (int i = 0; i < nFeatures+1; i++)
+      for (int i = 0; i < nFeatures + 1; i++)
         coefficients[i] = lm.w[i + 4];
 
       SymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
-      SymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();
-      tree.Root.AddSubTree(start);
+      SymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
+      tree.Root.AddSubTree(startNode);
       SymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
-      start.AddSubTree(addition);
+      startNode.AddSubTree(addition);
 
       int col = 0;
-      foreach (string column in problem.InputVariables.CheckedItems.Select(c => c.Value.Value)) {
+      foreach (string column in allowedInputVariables) {
         VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable().CreateTreeNode();
         vNode.VariableName = column;
@@ -111,40 +131,8 @@
       ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
       cNode.Value = coefficients[coefficients.Length - 1];
+      addition.AddSubTree(cNode);
 
       return tree;
     }
-
-    private static List<int> CalculateAllowedRows(DataAnalysisProblemData problem) {
-      List<int> allowedRows = new List<int>();
-      bool add = false;
-
-      for (int row = problem.TrainingSamplesStart.Value; row < problem.TrainingSamplesEnd.Value; row++) {
-        add = true;
-        foreach (string column in problem.InputVariables.CheckedItems.Select(c => c.Value.Value)) {
-          double value = problem.Dataset[column, row];
-          if (double.IsInfinity(value) ||
-            double.IsNaN(value))
-            add = false;
-        }
-        if (double.IsNaN(problem.Dataset[problem.TargetVariable.Value, row]))
-          add = false;
-        if (add)
-          allowedRows.Add(row);
-        add = true;
-      }
-      return allowedRows;
-    }
-    private static double[,] PrepareInputMatrix(DataAnalysisProblemData problem, IList<int> allowedRows) {
-      double[,] matrix = new double[allowedRows.Count, problem.InputVariables.CheckedItems.Count()+1];
-      for (int row = 0; row < allowedRows.Count; row++) {
-        int col = 0;
-        foreach (string column in problem.InputVariables.CheckedItems.Select(c => c.Value.Value)) {
-          matrix[row, col] = problem.Dataset[column, row];
-          col++;
-        }
-        matrix[row, problem.InputVariables.CheckedItems.Count()] = problem.Dataset[problem.TargetVariable.Value, row];
-      }
-      return matrix;
-    }
   }
 }
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionUtil.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionUtil.cs	(revision 3848)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/LinearRegression/LinearRegressionUtil.cs	(revision 3848)
@@ -0,0 +1,65 @@
+﻿#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 <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace HeuristicLab.Problems.DataAnalysis.Regression.LinearRegression {
+  public static class LinearRegressionUtil {
+    public static double[,] PrepareInputMatrix(Dataset dataset, string targetVariable, IEnumerable<string> allowedInputVariables, int start, int end) {
+      List<int> allowedRows = CalculateAllowedRows(dataset, targetVariable, allowedInputVariables, start, end);
+
+      double[,] matrix = new double[allowedRows.Count, allowedInputVariables.Count() +1];
+      for (int row = 0; row < allowedRows.Count; row++) {
+        int col = 0;
+        foreach (string column in allowedInputVariables) {
+          matrix[row, col] = dataset[column, row];
+          col++;
+        }
+        matrix[row, allowedInputVariables.Count()] = dataset[targetVariable, row];
+      }
+      return matrix;
+    }
+
+    private static List<int> CalculateAllowedRows(Dataset dataset, string targetVariable, IEnumerable<string> allowedInputVariables, int start, int end) {
+      List<int> allowedRows = new List<int>();
+      bool add = false;
+
+      for (int row = start; row < end; row++) {
+        add = true;
+        foreach (string column in allowedInputVariables) {
+          double value = dataset[column, row];
+          if (double.IsInfinity(value) ||
+            double.IsNaN(value))
+            add = false;
+        }
+        if (double.IsNaN(dataset[targetVariable, row]))
+          add = false;
+        if (add)
+          allowedRows.Add(row);
+        add = true;
+      }
+      return allowedRows;
+    }
+  }
+}
