Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs	(revision 13030)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs	(revision 13065)
@@ -255,20 +255,19 @@
       // produce solution 
       if (CreateSolution) {
-        var surrogateModel = new GradientBoostedTreesModelSurrogate(problemData, (uint)Seed, lossFunction,
-          Iterations, MaxSize, R, M, Nu, state.GetModel());
+        var model = state.GetModel();
 
         // for logistic regression we produce a classification solution
         if (lossFunction is LogisticRegressionLoss) {
-          var model = new DiscriminantFunctionClassificationModel(surrogateModel,
+          var classificationModel = new DiscriminantFunctionClassificationModel(model,
             new AccuracyMaximizationThresholdCalculator());
           var classificationProblemData = new ClassificationProblemData(problemData.Dataset,
             problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations);
-          model.RecalculateModelParameters(classificationProblemData, classificationProblemData.TrainingIndices);
-
-          var classificationSolution = new DiscriminantFunctionClassificationSolution(model, classificationProblemData);
+          classificationModel.RecalculateModelParameters(classificationProblemData, classificationProblemData.TrainingIndices);
+
+          var classificationSolution = new DiscriminantFunctionClassificationSolution(classificationModel, classificationProblemData);
           Results.Add(new Result("Solution", classificationSolution));
         } else {
           // otherwise we produce a regression solution
-          Results.Add(new Result("Solution", new RegressionSolution(surrogateModel, problemData)));
+          Results.Add(new Result("Solution", new RegressionSolution(model, problemData)));
         }
       }
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs	(revision 13030)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs	(revision 13065)
@@ -52,4 +52,5 @@
       internal RegressionTreeBuilder treeBuilder { get; private set; }
 
+      private readonly uint randSeed;
       private MersenneTwister random { get; set; }
 
@@ -71,4 +72,5 @@
         this.m = m;
 
+        this.randSeed = randSeed;
         random = new MersenneTwister(randSeed);
         this.problemData = problemData;
@@ -99,5 +101,11 @@
 
       public IRegressionModel GetModel() {
-        return new GradientBoostedTreesModel(models, weights);
+#pragma warning disable 618
+        var model = new GradientBoostedTreesModel(models, weights);
+#pragma warning restore 618
+        // we don't know the number of iterations here but the number of weights is equal 
+        // to the number of iterations + 1 (for the constant model)
+        // wrap the actual model in a surrogate that enables persistence and lazy recalculation of the model if necessary
+        return new GradientBoostedTreesModelSurrogate(problemData, randSeed, lossFunction, weights.Count - 1, maxSize, r, m, nu, model);
       }
       public IEnumerable<KeyValuePair<string, double>> GetVariableRelevance() {
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs	(revision 13030)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs	(revision 13065)
@@ -76,4 +76,5 @@
       this.isCompatibilityLoaded = original.isCompatibilityLoaded;
     }
+    [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")]
     public GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
       : base("Gradient boosted tree model", string.Empty) {
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 13030)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 13065)
@@ -21,11 +21,8 @@
 #endregion
 
-using System;
 using System.Collections.Generic;
-using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.PluginInfrastructure;
 using HeuristicLab.Problems.DataAnalysis;
 
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs	(revision 13030)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs	(revision 13065)
@@ -119,23 +119,4 @@
     }
 
-    // simple API produces a single regression tree optimizing sum of squared errors
-    // this can be used if only a simple regression tree should be produced
-    // for a set of trees use the method CreateRegressionTreeForGradientBoosting below
-    //
-    // r and m work in the same way as for alglib random forest
-    // r is fraction of rows to use for training
-    // m is fraction of variables to use for training
-    public IRegressionModel CreateRegressionTree(int maxSize, double r = 0.5, double m = 0.5) {
-      // subtract mean of y first
-      var yAvg = y.Average();
-      for (int i = 0; i < y.Length; i++) y[i] -= yAvg;
-
-      var seLoss = new SquaredErrorLoss();
-
-      var model = CreateRegressionTreeForGradientBoosting(y, curPred, maxSize, problemData.TrainingIndices.ToArray(), seLoss, r, m);
-
-      return new GradientBoostedTreesModel(new[] { new ConstantRegressionModel(yAvg), model }, new[] { 1.0, 1.0 });
-    }
-
     // specific interface that allows to specify the target labels and the training rows which is necessary when for gradient boosted trees
     public IRegressionModel CreateRegressionTreeForGradientBoosting(double[] y, double[] curPred, int maxSize, int[] idx, ILossFunction lossFunction, double r = 0.5, double m = 0.5) {
