Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs	(revision 17873)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs	(revision 17931)
@@ -207,7 +207,6 @@
         inputMatrix[row, nColumns - 1] = classIndices[inputMatrix[row, nColumns - 1]];
       }
-
-      alglib.dfreport rep;
-      var dForest = RandomForestUtil.CreateRandomForestModel(seed, inputMatrix, nTrees, r, m, nClasses, out rep);
+      
+      var dForest = RandomForestUtil.CreateRandomForestModel(seed, inputMatrix, nTrees, r, m, nClasses, out var rep);
 
       rmsError = rep.rmserror;
@@ -216,5 +215,5 @@
       outOfBagRelClassificationError = rep.oobrelclserror;
 
-      return new RandomForestModelFull(dForest, problemData.TargetVariable, problemData.AllowedInputVariables, classValues);
+      return new RandomForestModelFull(dForest, nTrees, problemData.TargetVariable, problemData.AllowedInputVariables, classValues);
     }
     #endregion
Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs	(revision 17873)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs	(revision 17931)
@@ -20,4 +20,6 @@
 #endregion
 
+extern alias alglib_3_7;
+
 using System;
 using System.Collections.Generic;
@@ -39,6 +41,6 @@
   public sealed class RandomForestModel : ClassificationModel, IRandomForestModel {
     // not persisted
-    private alglib.decisionforest randomForest;
-    private alglib.decisionforest RandomForest {
+    private alglib_3_7.alglib.decisionforest randomForest;
+    private alglib_3_7.alglib.decisionforest RandomForest {
       get {
         // recalculate lazily
@@ -74,9 +76,9 @@
     private RandomForestModel(StorableConstructorFlag _) : base(_) {
       // for backwards compatibility (loading old solutions)
-      randomForest = new alglib.decisionforest();
+      randomForest = new alglib_3_7.alglib.decisionforest();
     }
     private RandomForestModel(RandomForestModel original, Cloner cloner)
       : base(original, cloner) {
-      randomForest = new alglib.decisionforest();
+      randomForest = new alglib_3_7.alglib.decisionforest();
       randomForest.innerobj.bufsize = original.randomForest.innerobj.bufsize;
       randomForest.innerobj.nclasses = original.randomForest.innerobj.nclasses;
@@ -100,5 +102,5 @@
 
     // random forest models can only be created through the static factory methods CreateRegressionModel and CreateClassificationModel
-    private RandomForestModel(string targetVariable, alglib.decisionforest randomForest,
+    private RandomForestModel(string targetVariable, alglib_3_7.alglib.decisionforest randomForest,
       int seed, IDataAnalysisProblemData originalTrainingData,
       int nTrees, double r, double m, double[] classValues = null)
@@ -151,5 +153,5 @@
           x[column] = inputData[row, column];
         }
-        alglib.dfprocess(RandomForest, x, ref y);
+        alglib_3_7.alglib.dfprocess(RandomForest, x, ref y);
         yield return y[0];
       }
@@ -169,5 +171,5 @@
           x[column] = inputData[row, column];
         }
-        alglib.dforest.dfprocessraw(RandomForest.innerobj, x, ref ys);
+        alglib_3_7.alglib.dforest.dfprocessraw(RandomForest.innerobj, x, ref ys);
         yield return ys.VariancePop();
       }
@@ -187,5 +189,5 @@
           x[column] = inputData[row, column];
         }
-        alglib.dfprocess(randomForest, x, ref y);
+        alglib_3_7.alglib.dfprocess(randomForest, x, ref y);
         // find class for with the largest probability value
         int maxProbClassIndex = 0;
@@ -315,6 +317,5 @@
       double[,] inputMatrix = problemData.Dataset.ToArray(variables, trainingIndices);
 
-      alglib.dfreport rep;
-      var dForest = RandomForestUtil.CreateRandomForestModel(seed, inputMatrix, nTrees, r, m, 1, out rep);
+      var dForest = RandomForestUtil.CreateRandomForestModelAlglib_3_7(seed, inputMatrix, nTrees, r, m, 1, out var rep);
 
       rmsError = rep.rmserror;
@@ -353,6 +354,5 @@
       }
 
-      alglib.dfreport rep;
-      var dForest = RandomForestUtil.CreateRandomForestModel(seed, inputMatrix, nTrees, r, m, nClasses, out rep);
+      var dForest = RandomForestUtil.CreateRandomForestModelAlglib_3_7(seed, inputMatrix, nTrees, r, m, nClasses, out var rep);
 
       rmsError = rep.rmserror;
Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelAlglib_3_7.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelAlglib_3_7.cs	(revision 17931)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelAlglib_3_7.cs	(revision 17931)
@@ -0,0 +1,282 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 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
+
+extern alias alglib_3_7;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HEAL.Attic;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
+
+namespace HeuristicLab.Algorithms.DataAnalysis {
+
+  [StorableType("9C797DF0-1169-4381-A732-6DAB90802839")]
+  [Item("RandomForestModel (alglib 3.7)", "Represents a random forest for regression and classification.")]
+  [Obsolete("This version uses alglib version 3.7. Use RandomForestModelFull instead.")]
+  public sealed class RandomForestModelAlglib_3_7 : ClassificationModel, IRandomForestModel {
+
+    public override IEnumerable<string> VariablesUsedForPrediction {
+      get { return inputVariables; }
+    }
+
+    [Storable]
+    private double[] classValues;
+
+    [Storable]
+    private string[] inputVariables;
+
+    public int NumberOfTrees {
+      get { return RandomForestNTrees; }
+    }
+
+    // not persisted
+    private alglib_3_7.alglib.decisionforest randomForest;
+
+    [Storable]
+    private int RandomForestBufSize {
+      get { return randomForest.innerobj.bufsize; }
+      set { randomForest.innerobj.bufsize = value; }
+    }
+    [Storable]
+    private int RandomForestNClasses {
+      get { return randomForest.innerobj.nclasses; }
+      set { randomForest.innerobj.nclasses = value; }
+    }
+    [Storable]
+    private int RandomForestNTrees {
+      get { return randomForest.innerobj.ntrees; }
+      set { randomForest.innerobj.ntrees = value; }
+    }
+    [Storable]
+    private int RandomForestNVars {
+      get { return randomForest.innerobj.nvars; }
+      set { randomForest.innerobj.nvars = value; }
+    }
+    [Storable]
+    private double[] RandomForestTrees {
+      get { return randomForest.innerobj.trees; }
+      set { randomForest.innerobj.trees = value; }
+    }
+
+    [StorableConstructor]
+    private RandomForestModelAlglib_3_7(StorableConstructorFlag _) : base(_) {
+      randomForest = new alglib_3_7.alglib.decisionforest();
+    }
+
+    private RandomForestModelAlglib_3_7(RandomForestModelAlglib_3_7 original, Cloner cloner) : base(original, cloner) {
+      randomForest = new alglib_3_7.alglib.decisionforest();
+      randomForest.innerobj.bufsize = original.randomForest.innerobj.bufsize;
+      randomForest.innerobj.nclasses = original.randomForest.innerobj.nclasses;
+      randomForest.innerobj.ntrees = original.randomForest.innerobj.ntrees;
+      randomForest.innerobj.nvars = original.randomForest.innerobj.nvars;
+      randomForest.innerobj.trees = (double[])original.randomForest.innerobj.trees.Clone();
+
+      // following fields are immutable so we don't need to clone them
+      inputVariables = original.inputVariables;
+      classValues = original.classValues;
+    }
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new RandomForestModelAlglib_3_7(this, cloner);
+    }
+
+    public RandomForestModelAlglib_3_7(alglib_3_7.alglib.decisionforest decisionForest, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<double> classValues = null) : base(targetVariable) {
+      this.name = ItemName;
+      this.description = ItemDescription;
+
+      randomForest = decisionForest;
+
+      this.inputVariables = inputVariables.ToArray();
+
+      //classValues are only use for classification models
+      if (classValues == null) this.classValues = new double[0];
+      else this.classValues = classValues.ToArray();
+    }
+
+
+    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
+      return new RandomForestRegressionSolution(this, new RegressionProblemData(problemData));
+    }
+    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
+      return new RandomForestClassificationSolution(this, new ClassificationProblemData(problemData));
+    }
+
+    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
+      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
+    }
+
+    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
+      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
+
+      var regressionProblemData = problemData as IRegressionProblemData;
+      if (regressionProblemData != null)
+        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
+
+      var classificationProblemData = problemData as IClassificationProblemData;
+      if (classificationProblemData != null)
+        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
+
+      throw new ArgumentException("The problem data is not compatible with this random forest. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
+    }
+
+    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
+      double[,] inputData = dataset.ToArray(inputVariables, rows);
+      RandomForestUtil.AssertInputMatrix(inputData);
+
+      int n = inputData.GetLength(0);
+      int columns = inputData.GetLength(1);
+      double[] x = new double[columns];
+      double[] y = new double[1];
+
+      for (int row = 0; row < n; row++) {
+        for (int column = 0; column < columns; column++) {
+          x[column] = inputData[row, column];
+        }
+        alglib_3_7.alglib.dfprocess(randomForest, x, ref y);
+        yield return y[0];
+      }
+    }
+    public IEnumerable<double> GetEstimatedVariances(IDataset dataset, IEnumerable<int> rows) {
+      double[,] inputData = dataset.ToArray(inputVariables, rows);
+      RandomForestUtil.AssertInputMatrix(inputData);
+
+      int n = inputData.GetLength(0);
+      int columns = inputData.GetLength(1);
+      double[] x = new double[columns];
+      double[] ys = new double[this.randomForest.innerobj.ntrees];
+
+      for (int row = 0; row < n; row++) {
+        for (int column = 0; column < columns; column++) {
+          x[column] = inputData[row, column];
+        }
+        alglib_3_7.alglib.dforest.dfprocessraw(randomForest.innerobj, x, ref ys);
+        yield return ys.VariancePop();
+      }
+    }
+
+    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
+      double[,] inputData = dataset.ToArray(inputVariables, rows);
+      RandomForestUtil.AssertInputMatrix(inputData);
+
+      int n = inputData.GetLength(0);
+      int columns = inputData.GetLength(1);
+      double[] x = new double[columns];
+      double[] y = new double[randomForest.innerobj.nclasses];
+
+      for (int row = 0; row < n; row++) {
+        for (int column = 0; column < columns; column++) {
+          x[column] = inputData[row, column];
+        }
+        alglib_3_7::alglib.dfprocess(randomForest, x, ref y);
+        // find class for with the largest probability value
+        int maxProbClassIndex = 0;
+        double maxProb = y[0];
+        for (int i = 1; i < y.Length; i++) {
+          if (maxProb < y[i]) {
+            maxProb = y[i];
+            maxProbClassIndex = i;
+          }
+        }
+        yield return classValues[maxProbClassIndex];
+      }
+    }
+
+    public ISymbolicExpressionTree ExtractTree(int treeIdx) {
+      var rf = randomForest;
+      // hoping that the internal representation of alglib is stable
+
+      // TREE FORMAT
+      // W[Offs]      -   size of sub-array (for the tree)
+      //     node info:
+      // W[K+0]       -   variable number        (-1 for leaf mode)
+      // W[K+1]       -   threshold              (class/value for leaf node)
+      // W[K+2]       -   ">=" branch index      (absent for leaf node)
+
+      // skip irrelevant trees
+      int offset = 0;
+      for (int i = 0; i < treeIdx - 1; i++) {
+        offset = offset + (int)Math.Round(rf.innerobj.trees[offset]);
+      }
+
+      var constSy = new Constant();
+      var varCondSy = new VariableCondition() { IgnoreSlope = true };
+
+      var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, constSy, varCondSy);
+
+      var startNode = new StartSymbol().CreateTreeNode();
+      startNode.AddSubtree(node);
+      var root = new ProgramRootSymbol().CreateTreeNode();
+      root.AddSubtree(startNode);
+      return new SymbolicExpressionTree(root);
+    }
+
+    private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Constant constSy, VariableCondition varCondSy) {
+
+      // alglib source for evaluation of one tree (dfprocessinternal)
+      // offs = 0
+      //
+      // Set pointer to the root
+      //
+      // k = offs + 1;
+      // 
+      // //
+      // // Navigate through the tree
+      // //
+      // while (true) {
+      //   if ((double)(df.trees[k]) == (double)(-1)) {
+      //     if (df.nclasses == 1) {
+      //       y[0] = y[0] + df.trees[k + 1];
+      //     } else {
+      //       idx = (int)Math.Round(df.trees[k + 1]);
+      //       y[idx] = y[idx] + 1;
+      //     }
+      //     break;
+      //   }
+      //   if ((double)(x[(int)Math.Round(df.trees[k])]) < (double)(df.trees[k + 1])) {
+      //     k = k + innernodewidth;
+      //   } else {
+      //     k = offs + (int)Math.Round(df.trees[k + 2]);
+      //   }
+      // }
+
+      if ((double)(trees[k]) == (double)(-1)) {
+        var constNode = (ConstantTreeNode)constSy.CreateTreeNode();
+        constNode.Value = trees[k + 1];
+        return constNode;
+      } else {
+        var condNode = (VariableConditionTreeNode)varCondSy.CreateTreeNode();
+        condNode.VariableName = inputVariables[(int)Math.Round(trees[k])];
+        condNode.Threshold = trees[k + 1];
+        condNode.Slope = double.PositiveInfinity;
+
+        var left = CreateRegressionTreeRec(trees, offset, k + 3, constSy, varCondSy);
+        var right = CreateRegressionTreeRec(trees, offset, offset + (int)Math.Round(trees[k + 2]), constSy, varCondSy);
+
+        condNode.AddSubtree(left); // not 100% correct because interpreter uses: if(x <= thres) left() else right() and RF uses if(x < thres) left() else right() (see above)
+        condNode.AddSubtree(right);
+        return condNode;
+      }
+    }
+  }
+}
Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelFull.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelFull.cs	(revision 17873)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelFull.cs	(revision 17931)
@@ -31,5 +31,5 @@
 
 namespace HeuristicLab.Algorithms.DataAnalysis {
-  [StorableType("9C797DF0-1169-4381-A732-6DAB90802839")]
+  [StorableType("55412E08-DAD4-4C2E-9181-C142E7EA9474")]
   [Item("RandomForestModelFull", "Represents a random forest for regression and classification.")]
   public sealed class RandomForestModelFull : ClassificationModel, IRandomForestModel {
@@ -42,9 +42,12 @@
     private double[] classValues;
 
+    public int NumClasses => classValues == null ? 0 : classValues.Length;
+
     [Storable]
     private string[] inputVariables;
 
+    [Storable]
     public int NumberOfTrees {
-      get { return RandomForestNTrees; }
+      get; private set;
     }
 
@@ -53,41 +56,16 @@
 
     [Storable]
-    private int RandomForestBufSize {
-      get { return randomForest.innerobj.bufsize; }
-      set { randomForest.innerobj.bufsize = value; }
-    }
-    [Storable]
-    private int RandomForestNClasses {
-      get { return randomForest.innerobj.nclasses; }
-      set { randomForest.innerobj.nclasses = value; }
-    }
-    [Storable]
-    private int RandomForestNTrees {
-      get { return randomForest.innerobj.ntrees; }
-      set { randomForest.innerobj.ntrees = value; }
-    }
-    [Storable]
-    private int RandomForestNVars {
-      get { return randomForest.innerobj.nvars; }
-      set { randomForest.innerobj.nvars = value; }
-    }
-    [Storable]
-    private double[] RandomForestTrees {
-      get { return randomForest.innerobj.trees; }
-      set { randomForest.innerobj.trees = value; }
+    private string RandomForestSerialized {
+      get { alglib.dfserialize(randomForest, out var serialized); return serialized; }
+      set { if (value != null) alglib.dfunserialize(value, out randomForest); }
     }
 
     [StorableConstructor]
-    private RandomForestModelFull(StorableConstructorFlag _) : base(_) {
-      randomForest = new alglib.decisionforest();
-    }
+    private RandomForestModelFull(StorableConstructorFlag _) : base(_) { }
 
     private RandomForestModelFull(RandomForestModelFull original, Cloner cloner) : base(original, cloner) {
-      randomForest = new alglib.decisionforest();
-      randomForest.innerobj.bufsize = original.randomForest.innerobj.bufsize;
-      randomForest.innerobj.nclasses = original.randomForest.innerobj.nclasses;
-      randomForest.innerobj.ntrees = original.randomForest.innerobj.ntrees;
-      randomForest.innerobj.nvars = original.randomForest.innerobj.nvars;
-      randomForest.innerobj.trees = (double[])original.randomForest.innerobj.trees.Clone();
+      if (original.randomForest != null)
+        randomForest = (alglib.decisionforest)original.randomForest.make_copy();
+      NumberOfTrees = original.NumberOfTrees;
 
       // following fields are immutable so we don't need to clone them
@@ -99,9 +77,10 @@
     }
 
-    public RandomForestModelFull(alglib.decisionforest decisionForest, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<double> classValues = null) : base(targetVariable) {
+    public RandomForestModelFull(alglib.decisionforest decisionForest, int nTrees, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<double> classValues = null) : base(targetVariable) {
       this.name = ItemName;
       this.description = ItemDescription;
 
-      randomForest = decisionForest;
+      randomForest = (alglib.decisionforest)decisionForest.make_copy();
+      NumberOfTrees = nTrees;
 
       this.inputVariables = inputVariables.ToArray();
@@ -147,9 +126,10 @@
       double[] y = new double[1];
 
+      alglib.dfcreatebuffer(randomForest, out var buf);
       for (int row = 0; row < n; row++) {
         for (int column = 0; column < columns; column++) {
           x[column] = inputData[row, column];
         }
-        alglib.dfprocess(randomForest, x, ref y);
+        alglib.dftsprocess(randomForest, buf, x, ref y); // thread-safe process (as long as separate buffers are used)
         yield return y[0];
       }
@@ -168,5 +148,6 @@
           x[column] = inputData[row, column];
         }
-        alglib.dforest.dfprocessraw(randomForest.innerobj, x, ref ys);
+        lock (randomForest)
+          alglib.dforest.dfprocessraw(randomForest.innerobj, x, ref ys, null);
         yield return ys.VariancePop();
       }
@@ -180,11 +161,12 @@
       int columns = inputData.GetLength(1);
       double[] x = new double[columns];
-      double[] y = new double[randomForest.innerobj.nclasses];
-
+      double[] y = new double[NumClasses];
+
+      alglib.dfcreatebuffer(randomForest, out var buf);
       for (int row = 0; row < n; row++) {
         for (int column = 0; column < columns; column++) {
           x[column] = inputData[row, column];
         }
-        alglib.dfprocess(randomForest, x, ref y);
+        alglib.dftsprocess(randomForest, buf, x, ref y);
         // find class for with the largest probability value
         int maxProbClassIndex = 0;
Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs	(revision 17873)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs	(revision 17931)
@@ -20,4 +20,6 @@
 #endregion
 
+extern alias alglib_3_7;
+using alglib_3_7;
 using System.Collections.Generic;
 using System.Linq;
@@ -200,5 +202,5 @@
       outOfBagAvgRelError = rep.oobavgrelerror;
 
-      return new RandomForestModelFull(dForest, problemData.TargetVariable, problemData.AllowedInputVariables);
+      return new RandomForestModelFull(dForest, nTrees, problemData.TargetVariable, problemData.AllowedInputVariables);
     }
 
Index: trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestUtil.cs
===================================================================
--- trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestUtil.cs	(revision 17873)
+++ trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestUtil.cs	(revision 17931)
@@ -22,4 +22,6 @@
 #endregion
 
+extern alias alglib_3_7;
+
 using System;
 using System.Collections.Generic;
@@ -103,8 +105,28 @@
       RandomForestUtil.AssertInputMatrix(inputMatrix);
 
+      int nRows = inputMatrix.GetLength(0);
+      int nColumns = inputMatrix.GetLength(1);
+
+      alglib.dfbuildercreate(out var dfbuilder);
+      alglib.dfbuildersetdataset(dfbuilder, inputMatrix, nRows, nColumns - 1, nClasses);
+      alglib.dfbuildersetimportancenone(dfbuilder); // do not calculate importance (TODO add this feature)
+      alglib.dfbuildersetrdfalgo(dfbuilder, 0); // only one algorithm supported in version 3.17
+      alglib.dfbuildersetrdfsplitstrength(dfbuilder, 2); // 0 = split at the random position, fastest one
+                                                         // 1 = split at the middle of the range
+                                                         // 2 = strong split at the best point of the range (default)
+      alglib.dfbuildersetrndvarsratio(dfbuilder, m);
+      alglib.dfbuildersetsubsampleratio(dfbuilder, r);
+      alglib.dfbuildersetseed(dfbuilder, seed);
+      alglib.dfbuilderbuildrandomforest(dfbuilder, nTrees, out var dForest, out rep);
+      return dForest;
+    }
+    internal static alglib_3_7.alglib.decisionforest CreateRandomForestModelAlglib_3_7(int seed, double[,] inputMatrix, int nTrees, double r, double m, int nClasses, out alglib_3_7.alglib.dfreport rep) {
+      RandomForestUtil.AssertParameters(r, m);
+      RandomForestUtil.AssertInputMatrix(inputMatrix);
+
       int info = 0;
-      alglib.math.rndobject = new System.Random(seed);
-      var dForest = new alglib.decisionforest();
-      rep = new alglib.dfreport();
+      alglib_3_7.alglib.math.rndobject = new System.Random(seed);
+      var dForest = new alglib_3_7.alglib.decisionforest();
+      rep = new alglib_3_7.alglib.dfreport();
       int nRows = inputMatrix.GetLength(0);
       int nColumns = inputMatrix.GetLength(1);
@@ -112,5 +134,5 @@
       int nFeatures = Math.Max((int)Math.Round(m * (nColumns - 1)), 1);
 
-      alglib.dforest.dfbuildinternal(inputMatrix, nRows, nColumns - 1, nClasses, nTrees, sampleSize, nFeatures, alglib.dforest.dfusestrongsplits + alglib.dforest.dfuseevs, ref info, dForest.innerobj, rep.innerobj);
+      alglib_3_7.alglib.dforest.dfbuildinternal(inputMatrix, nRows, nColumns - 1, nClasses, nTrees, sampleSize, nFeatures, alglib_3_7.alglib.dforest.dfusestrongsplits + alglib_3_7.alglib.dforest.dfuseevs, ref info, dForest.innerobj, rep.innerobj);
       if (info != 1) throw new ArgumentException("Error in calculation of random forest model");
       return dForest;
@@ -123,8 +145,8 @@
       var targetVariable = GetTargetVariableName(problemData);
       foreach (var tuple in partitions) {
-        double rmsError, avgRelError, outOfBagAvgRelError, outOfBagRmsError;
         var trainingRandomForestPartition = tuple.Item1;
         var testRandomForestPartition = tuple.Item2;
-        var model = RandomForestModel.CreateRegressionModel(problemData, trainingRandomForestPartition, nTrees, r, m, seed, out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
+        var model = RandomForestRegression.CreateRandomForestRegressionModel(problemData, trainingRandomForestPartition, nTrees, r, m, seed,
+                                                                             out var rmsError, out var avgRelError, out var outOfBagRmsError, out var outOfBagAvgRelError);
         var estimatedValues = model.GetEstimatedValues(ds, testRandomForestPartition);
         var targetValues = ds.GetDoubleValues(targetVariable, testRandomForestPartition);
@@ -143,8 +165,8 @@
       var targetVariable = GetTargetVariableName(problemData);
       foreach (var tuple in partitions) {
-        double rmsError, avgRelError, outOfBagAvgRelError, outOfBagRmsError;
         var trainingRandomForestPartition = tuple.Item1;
         var testRandomForestPartition = tuple.Item2;
-        var model = RandomForestModel.CreateClassificationModel(problemData, trainingRandomForestPartition, nTrees, r, m, seed, out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
+        var model = RandomForestClassification.CreateRandomForestClassificationModel(problemData, trainingRandomForestPartition, nTrees, r, m, seed,
+                                                                                     out var rmsError, out var avgRelError, out var outOfBagRmsError, out var outOfBagAvgRelError);
         var estimatedValues = model.GetEstimatedClassValues(ds, testRandomForestPartition);
         var targetValues = ds.GetDoubleValues(targetVariable, testRandomForestPartition);
@@ -176,6 +198,6 @@
         var parameters = new RFParameter();
         for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); }
-        double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError;
-        RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, parameters.N, parameters.R, parameters.M, seed, out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
+        RandomForestRegression.CreateRandomForestRegressionModel(problemData, problemData.TrainingIndices, parameters.N, parameters.R, parameters.M, seed,
+                                                                 out var rmsError, out var outOfBagRmsError, out var avgRelError, out var outOfBagAvgRelError);
 
         lock (locker) {
@@ -208,7 +230,6 @@
         var parameters = new RFParameter();
         for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); }
-        double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError;
-        RandomForestModel.CreateClassificationModel(problemData, problemData.TrainingIndices, parameters.N, parameters.R, parameters.M, seed,
-                                                                out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
+        RandomForestClassification.CreateRandomForestClassificationModel(problemData, problemData.TrainingIndices, parameters.N, parameters.R, parameters.M, seed,
+                                                                         out var rmsError, out var outOfBagRmsError, out var avgRelError, out var outOfBagAvgRelError);
 
         lock (locker) {
