Index: branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
===================================================================
--- branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 17320)
+++ branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 17333)
@@ -24,7 +24,7 @@
 using System.Collections.Generic;
 using System.Linq;
+using HEAL.Attic;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
-using HEAL.Attic;
 using HeuristicLab.Problems.DataAnalysis;
 
@@ -38,4 +38,5 @@
     // don't store the actual model!
     // the actual model is only recalculated when necessary
+    private IGradientBoostedTreesModel fullModel;
     private readonly Lazy<IGradientBoostedTreesModel> actualModel;
     private IGradientBoostedTreesModel ActualModel {
@@ -48,15 +49,15 @@
     private readonly uint seed;
     [Storable]
-    private ILossFunction lossFunction;
+    private readonly ILossFunction lossFunction;
     [Storable]
-    private double r;
+    private readonly double r;
     [Storable]
-    private double m;
+    private readonly double m;
     [Storable]
-    private double nu;
+    private readonly double nu;
     [Storable]
-    private int iterations;
+    private readonly int iterations;
     [Storable]
-    private int maxSize;
+    private readonly int maxSize;
 
 
@@ -69,13 +70,10 @@
     [StorableConstructor]
     private GradientBoostedTreesModelSurrogate(StorableConstructorFlag _) : base(_) {
-      actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());
+      actualModel = CreateLazyInitFunc();
     }
 
     private GradientBoostedTreesModelSurrogate(GradientBoostedTreesModelSurrogate original, Cloner cloner)
       : base(original, cloner) {
-      IGradientBoostedTreesModel clonedModel = null;
-      if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel);
-      actualModel = new Lazy<IGradientBoostedTreesModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure
-
+      // clone data which is necessary to rebuild the model
       this.trainingProblemData = cloner.Clone(original.trainingProblemData);
       this.lossFunction = cloner.Clone(original.lossFunction);
@@ -86,10 +84,15 @@
       this.m = original.m;
       this.nu = original.nu;
+
+      // clone full model if it has already been created
+      if (original.fullModel != null) this.fullModel = cloner.Clone(original.fullModel);
+      actualModel = CreateLazyInitFunc();
     }
 
-    private Func<IGradientBoostedTreesModel> CreateLazyInitFunc(IGradientBoostedTreesModel clonedModel) {
-      return () => {
-        return clonedModel ?? RecalculateModel();
-      };
+    private Lazy<IGradientBoostedTreesModel> CreateLazyInitFunc() {
+      return new Lazy<IGradientBoostedTreesModel>(() => {
+        if (fullModel == null) fullModel = RecalculateModel();
+        return fullModel;
+      });
     }
 
@@ -107,12 +110,12 @@
       this.nu = nu;
 
-      actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());
+      actualModel = CreateLazyInitFunc();
     }
 
-    // wrap an actual model in a surrograte
+    // wrap an actual model in a surrogate
     public GradientBoostedTreesModelSurrogate(IGradientBoostedTreesModel model, IRegressionProblemData trainingProblemData, uint seed,
       ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
       : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) {
-      actualModel = new Lazy<IGradientBoostedTreesModel>(() => model);
+      fullModel = model;
     }
 
@@ -135,13 +138,9 @@
 
     public IEnumerable<IRegressionModel> Models {
-      get {
-        return ActualModel.Models;
-      }
+      get { return ActualModel.Models; }
     }
 
     public IEnumerable<double> Weights {
-      get {
-        return ActualModel.Weights;
-      }
+      get { return ActualModel.Weights; }
     }
   }
Index: branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs
===================================================================
--- branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs	(revision 17320)
+++ branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs	(revision 17333)
@@ -35,20 +35,23 @@
     #region parameters for recalculation of the model
     [Storable]
-    private int seed;
+    private readonly int seed;
     [Storable]
-    private IDataAnalysisProblemData originalTrainingData;
+    private readonly IDataAnalysisProblemData originalTrainingData;
     [Storable]
-    private double[] classValues;
+    private readonly double[] classValues;
     [Storable]
-    private int nTrees;
+    private readonly int nTrees;
     [Storable]
-    private double r;
+    private readonly double r;
     [Storable]
-    private double m;
+    private readonly double m;
     #endregion
+
 
     // don't store the actual model!
     // the actual model is only recalculated when necessary
+    private IRandomForestModel fullModel = null;
     private readonly Lazy<IRandomForestModel> actualModel;
+
     private IRandomForestModel ActualModel {
       get { return actualModel.Value; }
@@ -74,23 +77,20 @@
       this.m = m;
 
-      actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());
+      actualModel = CreateLazyInitFunc();
     }
 
-    // wrap an actual model in a surrograte
+    // wrap an actual model in a surrogate
     public RandomForestModelSurrogate(IRandomForestModel model, string targetVariable, IDataAnalysisProblemData originalTrainingData,
-      int seed, int nTrees, double r, double m, double[] classValues = null) : this(targetVariable, originalTrainingData, seed, nTrees, r, m, classValues) {
-      actualModel = new Lazy<IRandomForestModel>(() => model);
+      int seed, int nTrees, double r, double m, double[] classValues = null)
+      : this(targetVariable, originalTrainingData, seed, nTrees, r, m, classValues) {
+      fullModel = model;
     }
 
     [StorableConstructor]
     private RandomForestModelSurrogate(StorableConstructorFlag _) : base(_) {
-      actualModel = new Lazy<IRandomForestModel>(() => RecalculateModel());
+      actualModel = CreateLazyInitFunc();
     }
 
     private RandomForestModelSurrogate(RandomForestModelSurrogate original, Cloner cloner) : base(original, cloner) {
-      IRandomForestModel clonedModel = null;
-      if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel);
-      actualModel = new Lazy<IRandomForestModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure
-
       // clone data which is necessary to rebuild the model
       this.originalTrainingData = cloner.Clone(original.originalTrainingData);
@@ -100,14 +100,19 @@
       this.r = original.r;
       this.m = original.m;
-    }
 
-    private Func<IRandomForestModel> CreateLazyInitFunc(IRandomForestModel clonedModel) {
-      return () => {
-        return clonedModel ?? RecalculateModel();
-      };
+      // clone full model if it has already been created
+      if (original.fullModel != null) this.fullModel = cloner.Clone(original.fullModel);
+      actualModel = CreateLazyInitFunc();
     }
 
     public override IDeepCloneable Clone(Cloner cloner) {
       return new RandomForestModelSurrogate(this, cloner);
+    }
+
+    private Lazy<IRandomForestModel> CreateLazyInitFunc() {
+      return new Lazy<IRandomForestModel>(() => {
+        if (fullModel == null) fullModel = RecalculateModel();
+        return fullModel;
+      });
     }
 
