Index: branches/2994-AutoDiffForIntervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
===================================================================
--- branches/2994-AutoDiffForIntervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 17209)
+++ branches/2994-AutoDiffForIntervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs	(revision 17312)
@@ -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; }
     }
   }
