Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/17 00:52:14 (7 years ago)
Author:
abeham
Message:

#2258: merged r13329:14000 from trunk into branch

Location:
branches/Async
Files:
71 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/Async

  • branches/Async/HeuristicLab.Algorithms.DataAnalysis

  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneR.cs

    r13092 r15280  
    139139      }
    140140
    141       var model = new OneRClassificationModel(bestVariable, bestSplits.Select(s => s.thresholdValue).ToArray(), bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass);
     141      var model = new OneRClassificationModel(problemData.TargetVariable, bestVariable, bestSplits.Select(s => s.thresholdValue).ToArray(), bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass);
    142142      var solution = new OneRClassificationSolution(model, (IClassificationProblemData)problemData.Clone());
    143143
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationModel.cs

    r13098 r15280  
    3131  [StorableClass]
    3232  [Item("OneR Classification Model", "A model that uses intervals for one variable to determine the class.")]
    33   public class OneRClassificationModel : NamedItem, IClassificationModel {
     33  public class OneRClassificationModel : ClassificationModel {
     34    public override IEnumerable<string> VariablesUsedForPrediction {
     35      get { return new[] { Variable }; }
     36    }
     37
    3438    [Storable]
    3539    protected string variable;
     
    6670    public override IDeepCloneable Clone(Cloner cloner) { return new OneRClassificationModel(this, cloner); }
    6771
    68     public OneRClassificationModel(string variable, double[] splits, double[] classes, double missingValuesClass = double.NaN)
    69       : base() {
     72    public OneRClassificationModel(string targetVariable, string variable, double[] splits, double[] classes, double missingValuesClass = double.NaN)
     73      : base(targetVariable) {
    7074      if (splits.Length != classes.Length) {
    7175        throw new ArgumentException("Number of splits and classes has to be equal.");
     
    8488    // uses sorting to return the values in the order of rows, instead of using nested for loops
    8589    // to avoid O(n²) runtime
    86     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     90    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    8791      var values = dataset.GetDoubleValues(Variable, rows).ToArray();
    8892      var rowsArray = rows.ToArray();
     
    108112    }
    109113
    110     public IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     114    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    111115      return new OneRClassificationSolution(this, new ClassificationProblemData(problemData));
    112116    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/ZeroR.cs

    r13098 r15280  
    6464        .MaxItems(kvp => kvp.Value).Select(x => x.Key).First();
    6565
    66       var model = new ConstantModel(dominantClass);
     66      var model = new ConstantModel(dominantClass, target);
    6767      var solution = model.CreateClassificationSolution(problemData);
    6868      return solution;
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceConst.cs

    r12012 r15280  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523using HeuristicLab.Common;
    2624using HeuristicLab.Core;
     
    8381    }
    8482
    85     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     83    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    8684      double scale;
    8785      GetParameterValues(p, out scale);
     
    9189      cov.CrossCovariance = (x, xt, i, j) => scale;
    9290      if (HasFixedScaleParameter) {
    93         cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     91        cov.CovarianceGradient = (x, i, j) => new double[0];
    9492      } else {
    95         cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, columnIndices);
     93        cov.CovarianceGradient = (x, i, j) => new[] { 2.0 * scale };
    9694      }
    9795      return cov;
    9896    }
    99 
    100     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double scale, IEnumerable<int> columnIndices) {
    101       yield return 2.0 * scale;
    102     }
    10397  }
    10498}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinear.cs

    r12012 r15280  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523using HeuristicLab.Common;
    2624using HeuristicLab.Core;
     
    5250    }
    5351
    54     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     52    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    5553      if (p.Length > 0) throw new ArgumentException("No parameters are allowed for the linear covariance function.");
    5654      // create functions
    5755      var cov = new ParameterizedCovarianceFunction();
    58       cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, 1, columnIndices);
    59       cov.CrossCovariance = (x, xt, i, j) =>  Util.ScalarProd(x, i, xt, j, 1.0 , columnIndices);
    60       cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     56      cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, columnIndices, 1.0);
     57      cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, columnIndices, 1.0);
     58      cov.CovarianceGradient = (x, i, j) => new double[0];
    6159      return cov;
    6260    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs

    r12012 r15280  
    8181    }
    8282
    83     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     83    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    8484      double[] inverseLength;
    8585      GetParameterValues(p, out inverseLength);
     
    9090      cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, inverseLength, columnIndices);
    9191      if (fixedInverseLength)
    92         cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     92        cov.CovarianceGradient = (x, i, j) => new double[0];
    9393      else
    9494        cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, inverseLength, columnIndices);
     
    9696    }
    9797
    98     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, IEnumerable<int> columnIndices) {
     98    private static IList<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, int[] columnIndices) {
    9999      int k = 0;
    100       foreach (int columnIndex in columnIndices) {
    101         yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k];
     100      var g = new List<double>(columnIndices.Length);
     101      for (int c = 0; c < columnIndices.Length; c++) {
     102        var columnIndex = columnIndices[c];
     103        g.Add(-2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k]);
    102104        k++;
    103105      }
     106      return g;
    104107    }
    105108  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMask.cs

    r12012 r15280  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using System.Linq;
    25 using System.Linq.Expressions;
    2623using HeuristicLab.Common;
    2724using HeuristicLab.Core;
     
    7370    }
    7471
    75     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     72    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    7673      var cov = CovarianceFunctionParameter.Value;
    7774      var selectedDimensions = SelectedDimensionsParameter.Value;
    7875
    79       return cov.GetParameterizedCovarianceFunction(p, selectedDimensions.Intersect(columnIndices));
     76      return cov.GetParameterizedCovarianceFunction(p, selectedDimensions.Intersect(columnIndices).ToArray());
    8077    }
    8178  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMaternIso.cs

    r12012 r15280  
    111111    }
    112112
    113     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     113    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    114114      double inverseLength, scale;
    115115      int d = DParameter.Value.Value;
     
    122122        double dist = i == j
    123123                       ? 0.0
    124                        : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
     124                       : Math.Sqrt(Util.SqrDist(x, i, j, columnIndices, Math.Sqrt(d) * inverseLength));
    125125        return scale * m(d, dist);
    126126      };
    127127      cov.CrossCovariance = (x, xt, i, j) => {
    128         double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, Math.Sqrt(d) * inverseLength, columnIndices));
     128        double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, Math.Sqrt(d) * inverseLength));
    129129        return scale * m(d, dist);
    130130      };
     
    155155    }
    156156
    157 
    158     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, IEnumerable<int> columnIndices,
     157    private static IList<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, int[] columnIndices,
    159158      bool fixedInverseLength, bool fixedScale) {
    160159      double dist = i == j
    161160                   ? 0.0
    162                    : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
     161                   : Math.Sqrt(Util.SqrDist(x, i, j, columnIndices, Math.Sqrt(d) * inverseLength));
    163162
    164       if (!fixedInverseLength) yield return scale * dm(d, dist);
    165       if (!fixedScale) yield return 2 * scale * m(d, dist);
     163      var g = new List<double>(2);
     164      if (!fixedInverseLength) g.Add(scale * dm(d, dist));
     165      if (!fixedScale) g.Add(2 * scale * m(d, dist));
     166      return g;
    166167    }
    167168  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNeuralNetwork.cs

    r12012 r15280  
    102102    }
    103103
    104     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     104    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    105105      double length, scale;
    106106      GetParameterValues(p, out scale, out length);
     
    113113        double s1 = 1.0;
    114114        double s2 = 1.0;
    115         foreach (var col in columnIndices) {
     115        for (int c = 0; c < columnIndices.Length; c++) {
     116          var col = columnIndices[c];
    116117          sx += x[i, col] * x[j, col];
    117118          s1 += x[i, col] * x[i, col];
     
    125126        double s1 = 1.0;
    126127        double s2 = 1.0;
    127         foreach (var col in columnIndices) {
     128        for (int c = 0; c < columnIndices.Length; c++) {
     129          var col = columnIndices[c];
    128130          sx += x[i, col] * xt[j, col];
    129131          s1 += x[i, col] * x[i, col];
     
    138140
    139141    // order of returned gradients must match the order in GetParameterValues!
    140     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, IEnumerable<int> columnIndices,
     142    private static IList<double> GetGradient(double[,] x, int i, int j, double length, double scale, int[] columnIndices,
    141143      bool fixedLength, bool fixedScale) {
    142       {
    143         double sx = 1.0;
    144         double s1 = 1.0;
    145         double s2 = 1.0;
    146         foreach (var col in columnIndices) {
    147           sx += x[i, col] * x[j, col];
    148           s1 += x[i, col] * x[i, col];
    149           s2 += x[j, col] * x[j, col];
    150         }
    151         var h = (length + s1) * (length + s2);
    152         var f = sx / Math.Sqrt(h);
    153         if (!fixedLength) {
    154           yield return -scale / Math.Sqrt(1.0 - f * f) * ((length * sx * (2.0 * length + s1 + s2)) / Math.Pow(h, 3.0 / 2.0));
    155         }
    156         if (!fixedScale) {
    157           yield return 2.0 * scale * Math.Asin(f);
    158         }
     144      double sx = 1.0;
     145      double s1 = 1.0;
     146      double s2 = 1.0;
     147      for (int c = 0; c < columnIndices.Length; c++) {
     148        var col = columnIndices[c];
     149        sx += x[i, col] * x[j, col];
     150        s1 += x[i, col] * x[i, col];
     151        s2 += x[j, col] * x[j, col];
    159152      }
     153      var h = (length + s1) * (length + s2);
     154      var f = sx / Math.Sqrt(h);
     155
     156      var g = new List<double>(2);
     157      if (!fixedLength) g.Add(-scale / Math.Sqrt(1.0 - f * f) * ((length * sx * (2.0 * length + s1 + s2)) / Math.Pow(h, 3.0 / 2.0)));
     158      if (!fixedScale) g.Add(2.0 * scale * Math.Asin(f));
     159      return g;
    160160    }
    161161  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNoise.cs

    r12012 r15280  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523using HeuristicLab.Common;
    2624using HeuristicLab.Core;
     
    8482    }
    8583
    86     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     84    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    8785      double scale;
    8886      GetParameterValues(p, out scale);
     
    9189      var cov = new ParameterizedCovarianceFunction();
    9290      cov.Covariance = (x, i, j) => i == j ? scale : 0.0;
    93       cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, 1.0, columnIndices) < 1e-9 ? scale : 0.0;
     91      cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, columnIndices, 1.0) < 1e-9 ? scale : 0.0;
    9492      if (fixedScale)
    95         cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
     93        cov.CovarianceGradient = (x, i, j) => new double[0];
    9694      else
    97         cov.CovarianceGradient = (x, i, j) => Enumerable.Repeat(i == j ? 2.0 * scale : 0.0, 1);
     95        cov.CovarianceGradient = (x, i, j) => new double[1] { i == j ? 2.0 * scale : 0.0 };
    9896      return cov;
    9997    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs

    r12012 r15280  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    117116    }
    118117
    119     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     118    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    120119      double inverseLength, period, scale;
    121120      GetParameterValues(p, out scale, out period, out inverseLength);
     
    145144    }
    146145
    147 
    148     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double period, double inverseLength,
     146    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double period, double inverseLength,
    149147      bool fixedInverseLength, bool fixedPeriod, bool fixedScale) {
    150148      double k = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period;
    151149      double gradient = Math.Sin(k) * inverseLength;
    152150      gradient *= gradient;
    153       if (!fixedInverseLength) yield return 4.0 * scale * Math.Exp(-2.0 * gradient) * gradient;
     151      var g = new List<double>(3);
     152      if (!fixedInverseLength)
     153        g.Add(4.0 * scale * Math.Exp(-2.0 * gradient) * gradient);
    154154      if (!fixedPeriod) {
    155155        double r = Math.Sin(k) * inverseLength;
    156         yield return 2.0 * k * scale * Math.Exp(-2 * r * r) * Math.Sin(2 * k) * inverseLength * inverseLength;
     156        g.Add(2.0 * k * scale * Math.Exp(-2 * r * r) * Math.Sin(2 * k) * inverseLength * inverseLength);
    157157      }
    158158      if (!fixedScale)
    159         yield return 2.0 * scale * Math.Exp(-2 * gradient);
    160 
     159        g.Add(2.0 * scale * Math.Exp(-2 * gradient));
     160      return g;
    161161    }
    162162
    163     private static double GetDistance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
    164       return Math.Sqrt(Util.SqrDist(x, i, xt, j, 1, columnIndices));
     163    private static double GetDistance(double[,] x, double[,] xt, int i, int j, int[] columnIndices) {
     164      return Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, 1));
    165165    }
    166166  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePiecewisePolynomial.cs

    r12012 r15280  
    6969      Parameters.Add(new OptionalValueParameter<DoubleValue>("Scale", "The scale parameter of the piecewise polynomial covariance function."));
    7070
    71       var validValues = new ItemSet<IntValue>(new IntValue[] { 
    72         (IntValue)(new IntValue().AsReadOnly()), 
    73         (IntValue)(new IntValue(1).AsReadOnly()), 
    74         (IntValue)(new IntValue(2).AsReadOnly()), 
     71      var validValues = new ItemSet<IntValue>(new IntValue[] {
     72        (IntValue)(new IntValue().AsReadOnly()),
     73        (IntValue)(new IntValue(1).AsReadOnly()),
     74        (IntValue)(new IntValue(2).AsReadOnly()),
    7575        (IntValue)(new IntValue(3).AsReadOnly()) });
    7676      Parameters.Add(new ConstrainedValueParameter<IntValue>("V", "The v parameter of the piecewise polynomial function (allowed values 0, 1, 2, 3).", validValues, validValues.First()));
     
    113113    }
    114114
    115     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     115    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    116116      double length, scale;
    117117      int v = VParameter.Value.Value;
     
    148148      var cov = new ParameterizedCovarianceFunction();
    149149      cov.Covariance = (x, i, j) => {
    150         double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));
     150        double k = Math.Sqrt(Util.SqrDist(x, i, x, j, columnIndices, 1.0 / length));
    151151        return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
    152152      };
    153153      cov.CrossCovariance = (x, xt, i, j) => {
    154         double k = Math.Sqrt(Util.SqrDist(x, i, xt, j, 1.0 / length, columnIndices));
     154        double k = Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, 1.0 / length));
    155155        return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
    156156      };
     
    159159    }
    160160
    161     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, IEnumerable<int> columnIndices,
     161    private static IList<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, int[] columnIndices,
    162162      bool fixedLength, bool fixedScale) {
    163       double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));
    164       if (!fixedLength) yield return scale * Math.Pow(Math.Max(1.0 - k, 0), exp + v - 1) * k * ((exp + v) * f(k) - Math.Max(1 - k, 0) * df(k));
    165       if (!fixedScale) yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
     163      double k = Math.Sqrt(Util.SqrDist(x, i, x, j, columnIndices, 1.0 / length));
     164      var g = new List<double>(2);
     165      if (!fixedLength) g.Add(scale * Math.Pow(Math.Max(1.0 - k, 0), exp + v - 1) * k * ((exp + v) * f(k) - Math.Max(1 - k, 0) * df(k)));
     166      if (!fixedScale) g.Add(2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k));
     167      return g;
    166168    }
    167169  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePolynomial.cs

    r12012 r15280  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    107106    }
    108107
    109     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     108    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    110109      double @const, scale;
    111110      int degree = DegreeParameter.Value.Value;
     
    116115      // create functions
    117116      var cov = new ParameterizedCovarianceFunction();
    118       cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, 1.0, columnIndices), degree);
    119       cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, 1.0, columnIndices), degree);
     117      cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, columnIndices, 1.0), degree);
     118      cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, columnIndices, 1.0), degree);
    120119      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, @const, scale, degree, columnIndices, fixedConst, fixedScale);
    121120      return cov;
    122121    }
    123122
    124     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, IEnumerable<int> columnIndices,
     123    private static IList<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, int[] columnIndices,
    125124      bool fixedConst, bool fixedScale) {
    126       double s = Util.ScalarProd(x, i, j, 1.0, columnIndices);
    127       if (!fixedConst) yield return c * degree * scale * Math.Pow(c + s, degree - 1);
    128       if (!fixedScale) yield return 2 * scale * Math.Pow(c + s, degree);
     125      double s = Util.ScalarProd(x, i, j, columnIndices, 1.0);
     126      var g = new List<double>(2);
     127      if (!fixedConst) g.Add(c * degree * scale * Math.Pow(c + s, degree - 1));
     128      if (!fixedScale) g.Add(2 * scale * Math.Pow(c + s, degree));
     129      return g;
    129130    }
    130131  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceProduct.cs

    r12012 r15280  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Linq.Expressions;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    7675    }
    7776
    78     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     77    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    7978      if (factors.Count == 0) throw new ArgumentException("at least one factor is necessary for the product covariance function.");
    8079      var functions = new List<ParameterizedCovarianceFunction>();
     
    9392    }
    9493
    95     public static IEnumerable<double> GetGradient(double[,] x, int i, int j, List<ParameterizedCovarianceFunction> factorFunctions) {
     94    public static IList<double> GetGradient(double[,] x, int i, int j, List<ParameterizedCovarianceFunction> factorFunctions) {
    9695      var covariances = factorFunctions.Select(f => f.Covariance(x, i, j)).ToArray();
     96      var gr = new List<double>();
    9797      for (int ii = 0; ii < factorFunctions.Count; ii++) {
    9898        foreach (var g in factorFunctions[ii].CovarianceGradient(x, i, j)) {
     
    100100          for (int jj = 0; jj < covariances.Length; jj++)
    101101            if (ii != jj) res *= covariances[jj];
    102           yield return res;
     102          gr.Add(res);
    103103        }
    104104      }
     105      return gr;
    105106    }
    106107  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs

    r12012 r15280  
    121121    }
    122122
    123     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     123    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    124124      double scale, shape;
    125125      double[] inverseLength;
     
    144144    }
    145145
    146     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double[] inverseLength,
     146    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double shape, double[] inverseLength,
    147147      bool fixedInverseLength, bool fixedScale, bool fixedShape) {
    148148      double d = i == j
     
    151151      double b = 1 + 0.5 * d / shape;
    152152      int k = 0;
     153      var g = new List<double>(columnIndices.Length + 2);
    153154      if (!fixedInverseLength) {
    154155        foreach (var columnIndex in columnIndices) {
    155           yield return
     156          g.Add(
    156157            scale * Math.Pow(b, -shape - 1) *
    157             Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
     158            Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]));
    158159          k++;
    159160        }
    160161      }
    161       if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape);
    162       if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
     162      if (!fixedScale) g.Add(2 * scale * Math.Pow(b, -shape));
     163      if (!fixedShape) g.Add(scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b)));
     164      return g;
    163165    }
    164166  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs

    r12012 r15280  
    117117    }
    118118
    119     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     119    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    120120      double scale, shape, inverseLength;
    121121      GetParameterValues(p, out scale, out shape, out inverseLength);
     
    128128        double d = i == j
    129129                    ? 0.0
    130                     : Util.SqrDist(x, i, j, inverseLength, columnIndices);
     130                    : Util.SqrDist(x, i, j, columnIndices, inverseLength);
    131131        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    132132      };
    133133      cov.CrossCovariance = (x, xt, i, j) => {
    134         double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
     134        double d = Util.SqrDist(x, i, xt, j, columnIndices, inverseLength);
    135135        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    136136      };
     
    139139    }
    140140
    141     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double inverseLength,
     141    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double shape, double inverseLength,
    142142      bool fixedInverseLength, bool fixedScale, bool fixedShape) {
    143143      double d = i == j
    144144                   ? 0.0
    145                    : Util.SqrDist(x, i, j, inverseLength, columnIndices);
     145                   : Util.SqrDist(x, i, j, columnIndices, inverseLength);
    146146
    147147      double b = 1 + 0.5 * d / shape;
    148       if (!fixedInverseLength) yield return scale * Math.Pow(b, -shape - 1) * d;
    149       if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape);
    150       if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
     148      var g = new List<double>(3);
     149      if (!fixedInverseLength) g.Add(scale * Math.Pow(b, -shape - 1) * d);
     150      if (!fixedScale) g.Add(2 * scale * Math.Pow(b, -shape));
     151      if (!fixedShape) g.Add(scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b)));
     152      return g;
    151153    }
    152154  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceScale.cs

    r12012 r15280  
    8787    }
    8888
    89     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     89    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    9090      double scale;
    9191      GetParameterValues(p, out scale);
     
    100100    }
    101101
    102     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, ParameterizedCovarianceFunction cov,
     102    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, ParameterizedCovarianceFunction cov,
    103103      bool fixedScale) {
     104      var gr = new List<double>((!fixedScale ? 1 : 0) + cov.CovarianceGradient(x, i, j).Count);
    104105      if (!fixedScale) {
    105         yield return 2 * scale * cov.Covariance(x, i, j);
     106        gr.Add(2 * scale * cov.Covariance(x, i, j));
    106107      }
    107108      foreach (var g in cov.CovarianceGradient(x, i, j))
    108         yield return scale * g;
     109        gr.Add(scale * g);
     110      return gr;
    109111    }
    110112  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSpectralMixture.cs

    r12012 r15280  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Linq.Expressions;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    131130    }
    132131
    133     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     132    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    134133      double[] weight, frequency, lengthScale;
    135134      GetParameterValues(p, out weight, out frequency, out lengthScale);
     
    152151    }
    153152
    154     private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int> columnIndices) {
     153    private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices) {
    155154      // tau = x - x' (only for selected variables)
    156155      double[] tau =
     
    164163        int idx = 0; // helper index for tau
    165164        // for each selected variable
    166         foreach (var c in columnIndices) {
    167           kc *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]);
     165        for (int c = 0; c < columnIndices.Length; c++) {
     166          var col = columnIndices[c];
     167          kc *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]);
    168168          idx++;
    169169        }
     
    181181
    182182    // order of returned gradients must match the order in GetParameterValues!
    183     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int> columnIndices,
     183    private static IList<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices,
    184184      bool fixedWeight, bool fixedFrequency, bool fixedLengthScale) {
    185185      double[] tau = Util.GetRow(x, i, columnIndices).Zip(Util.GetRow(x, j, columnIndices), (xi, xj) => xi - xj).ToArray();
    186186      int numberOfVariables = lengthScale.Length / maxQ;
    187187
     188      var g = new List<double>((!fixedWeight ? maxQ : 0) + (!fixedFrequency ? maxQ * columnIndices.Length : 0) + (!fixedLengthScale ? maxQ * columnIndices.Length : 0));
    188189      if (!fixedWeight) {
    189190        // weight
     
    193194          int idx = 0; // helper index for tau
    194195          // for each selected variable
    195           foreach (var c in columnIndices) {
    196             k *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]);
     196          for (int c = 0; c < columnIndices.Length; c++) {
     197            var col = columnIndices[c];
     198            k *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]);
    197199            idx++;
    198200          }
    199           yield return k;
     201          g.Add(k);
    200202        }
    201203      }
     
    212214                       Math.Sin(2 * Math.PI * tau[idx] * frequency[q * numberOfVariables + c]);
    213215            idx++;
    214             yield return weight[q] * k;
     216            g.Add(weight[q] * k);
    215217          }
    216218        }
     
    228230                       f2(tau[idx], frequency[q * numberOfVariables + c]);
    229231            idx++;
    230             yield return weight[q] * k;
     232            g.Add(weight[q] * k);
    231233          }
    232234        }
    233235      }
     236
     237      return g;
    234238    }
    235239  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs

    r12012 r15280  
    9999    }
    100100
    101     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     101    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    102102      double scale;
    103103      double[] inverseLength;
     
    122122
    123123    // order of returned gradients must match the order in GetParameterValues!
    124     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double[] inverseLength,
     124    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double[] inverseLength,
    125125      bool fixedInverseLength, bool fixedScale) {
    126126      double d = i == j
     
    129129
    130130      int k = 0;
     131      var g = new List<double>((!fixedInverseLength ? columnIndices.Length : 0) + (!fixedScale ? 1 : 0));
    131132      if (!fixedInverseLength) {
    132         foreach (var columnIndex in columnIndices) {
     133        for (int c = 0; c < columnIndices.Length; c++) {
     134          var columnIndex = columnIndices[c];
    133135          double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
    134           yield return scale * Math.Exp(-d / 2.0) * sqrDist;
     136          g.Add(scale * Math.Exp(-d / 2.0) * sqrDist);
    135137          k++;
    136138        }
    137139      }
    138       if (!fixedScale) yield return 2.0 * scale * Math.Exp(-d / 2.0);
     140      if (!fixedScale) g.Add(2.0 * scale * Math.Exp(-d / 2.0));
     141      return g;
    139142    }
    140143  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs

    r12012 r15280  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq.Expressions;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    104103    }
    105104
    106     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     105    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    107106      double inverseLength, scale;
    108107      GetParameterValues(p, out scale, out inverseLength);
     
    114113        double d = i == j
    115114                ? 0.0
    116                 : Util.SqrDist(x, i, j, inverseLength, columnIndices);
     115                : Util.SqrDist(x, i, j, columnIndices, inverseLength);
    117116        return scale * Math.Exp(-d / 2.0);
    118117      };
    119118      cov.CrossCovariance = (x, xt, i, j) => {
    120         double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
     119        double d = Util.SqrDist(x, i, xt, j, columnIndices, inverseLength);
    121120        return scale * Math.Exp(-d / 2.0);
    122121      };
     
    127126
    128127    // order of returned gradients must match the order in GetParameterValues!
    129     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices,
     128    private static IList<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, int[] columnIndices,
    130129      bool fixedInverseLength, bool fixedScale) {
    131130      double d = i == j
    132131                   ? 0.0
    133                    : Util.SqrDist(x, i, j, inverseLength, columnIndices);
     132                   : Util.SqrDist(x, i, j, columnIndices, inverseLength);
    134133      double g = Math.Exp(-d / 2.0);
    135       if (!fixedInverseLength) yield return sf2 * g * d;
    136       if (!fixedScale) yield return 2.0 * sf2 * g;
     134      var gr = new List<double>(2);
     135      if (!fixedInverseLength) gr.Add(sf2 * g * d);
     136      if (!fixedScale) gr.Add(2.0 * sf2 * g);
     137      return gr;
    137138    }
    138139  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSum.cs

    r12012 r15280  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Linq.Expressions;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    7675    }
    7776
    78     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     77    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    7978      if (terms.Count == 0) throw new ArgumentException("at least one term is necessary for the product covariance function.");
    8079      var functions = new List<ParameterizedCovarianceFunction>();
     
    8887      sum.Covariance = (x, i, j) => functions.Select(e => e.Covariance(x, i, j)).Sum();
    8988      sum.CrossCovariance = (x, xt, i, j) => functions.Select(e => e.CrossCovariance(x, xt, i, j)).Sum();
    90       sum.CovarianceGradient = (x, i, j) => functions.Select(e => e.CovarianceGradient(x, i, j)).Aggregate(Enumerable.Concat);
     89      sum.CovarianceGradient = (x, i, j) => {
     90        var g = new List<double>();
     91        foreach (var e in functions)
     92          g.AddRange(e.CovarianceGradient(x, i, j));
     93        return g;
     94      };
    9195      return sum;
    9296    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r13160 r15280  
    3434  [StorableClass]
    3535  [Item("GaussianProcessModel", "Represents a Gaussian process posterior.")]
    36   public sealed class GaussianProcessModel : NamedItem, IGaussianProcessModel {
     36  public sealed class GaussianProcessModel : RegressionModel, IGaussianProcessModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
     38      get { return allowedInputVariables; }
     39    }
     40
    3741    [Storable]
    3842    private double negativeLogLikelihood;
     
    6165      get { return meanFunction; }
    6266    }
    63     [Storable]
    64     private string targetVariable;
    65     public string TargetVariable {
    66       get { return targetVariable; }
    67     }
     67
    6868    [Storable]
    6969    private string[] allowedInputVariables;
     
    128128      this.trainingDataset = cloner.Clone(original.trainingDataset);
    129129      this.negativeLogLikelihood = original.negativeLogLikelihood;
    130       this.targetVariable = original.targetVariable;
    131130      this.sqrSigmaNoise = original.sqrSigmaNoise;
    132131      if (original.meanParameter != null) {
     
    147146      IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction,
    148147      bool scaleInputs = true)
    149       : base() {
     148      : base(targetVariable) {
    150149      this.name = ItemName;
    151150      this.description = ItemDescription;
    152151      this.meanFunction = (IMeanFunction)meanFunction.Clone();
    153152      this.covarianceFunction = (ICovarianceFunction)covarianceFunction.Clone();
    154       this.targetVariable = targetVariable;
    155153      this.allowedInputVariables = allowedInputVariables.ToArray();
    156154
     
    167165      try {
    168166        CalculateModel(ds, rows, scaleInputs);
    169       } catch (alglib.alglibexception ae) {
     167      }
     168      catch (alglib.alglibexception ae) {
    170169        // wrap exception so that calling code doesn't have to know about alglib implementation
    171170        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    181180
    182181      IEnumerable<double> y;
    183       y = ds.GetDoubleValues(targetVariable, rows);
     182      y = ds.GetDoubleValues(TargetVariable, rows);
    184183
    185184      int n = x.GetLength(0);
    186185
     186      var columns = Enumerable.Range(0, x.GetLength(1)).ToArray();
    187187      // calculate cholesky decomposed (lower triangular) covariance matrix
    188       var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
     188      var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    189189      this.l = CalculateL(x, cov, sqrSigmaNoise);
    190190
    191191      // calculate mean
    192       var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, x.GetLength(1)));
     192      var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    193193      double[] m = Enumerable.Range(0, x.GetLength(0))
    194194        .Select(r => mean.Mean(x, r))
     
    227227      double[] meanGradients = new double[meanFunction.GetNumberOfParameters(nAllowedVariables)];
    228228      for (int k = 0; k < meanGradients.Length; k++) {
    229         var meanGrad = Enumerable.Range(0, alpha.Length)
    230         .Select(r => mean.Gradient(x, r, k));
     229        var meanGrad = new double[alpha.Length];
     230        for (int g = 0; g < meanGrad.Length; g++)
     231          meanGrad[g] = mean.Gradient(x, g, k);
    231232        meanGradients[k] = -Util.ScalarProd(meanGrad, alpha);
    232233      }
     
    236237        for (int i = 0; i < n; i++) {
    237238          for (int j = 0; j < i; j++) {
    238             var g = cov.CovarianceGradient(x, i, j).ToArray();
     239            var g = cov.CovarianceGradient(x, i, j);
    239240            for (int k = 0; k < covGradients.Length; k++) {
    240241              covGradients[k] += lCopy[i, j] * g[k];
     
    242243          }
    243244
    244           var gDiag = cov.CovarianceGradient(x, i, i).ToArray();
     245          var gDiag = cov.CovarianceGradient(x, i, i);
    245246          for (int k = 0; k < covGradients.Length; k++) {
    246247            // diag
     
    298299
    299300    #region IRegressionModel Members
    300     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     301    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    301302      return GetEstimatedValuesHelper(dataset, rows);
    302303    }
    303     public GaussianProcessRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     304    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    304305      return new GaussianProcessRegressionSolution(this, new RegressionProblemData(problemData));
    305     }
    306     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    307       return CreateRegressionSolution(problemData);
    308306    }
    309307    #endregion
     
    320318        int newN = newX.GetLength(0);
    321319
    322         var Ks = new double[newN, n];
    323         var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, newX.GetLength(1)));
     320        var Ks = new double[newN][];
     321        var columns = Enumerable.Range(0, newX.GetLength(1)).ToArray();
     322        var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    324323        var ms = Enumerable.Range(0, newX.GetLength(0))
    325324        .Select(r => mean.Mean(newX, r))
    326325        .ToArray();
    327         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, newX.GetLength(1)));
     326        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    328327        for (int i = 0; i < newN; i++) {
     328          Ks[i] = new double[n];
    329329          for (int j = 0; j < n; j++) {
    330             Ks[i, j] = cov.CrossCovariance(x, newX, j, i);
     330            Ks[i][j] = cov.CrossCovariance(x, newX, j, i);
    331331          }
    332332        }
    333333
    334334        return Enumerable.Range(0, newN)
    335           .Select(i => ms[i] + Util.ScalarProd(Util.GetRow(Ks, i), alpha));
    336       } catch (alglib.alglibexception ae) {
     335          .Select(i => ms[i] + Util.ScalarProd(Ks[i], alpha));
     336      }
     337      catch (alglib.alglibexception ae) {
    337338        // wrap exception so that calling code doesn't have to know about alglib implementation
    338339        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    352353        var kss = new double[newN];
    353354        double[,] sWKs = new double[n, newN];
    354         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
     355        var columns = Enumerable.Range(0, newX.GetLength(1)).ToArray();
     356        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    355357
    356358        if (l == null) {
     
    372374
    373375        for (int i = 0; i < newN; i++) {
    374           var sumV = Util.ScalarProd(Util.GetCol(sWKs, i), Util.GetCol(sWKs, i));
     376          var col = Util.GetCol(sWKs, i).ToArray();
     377          var sumV = Util.ScalarProd(col, col);
    375378          kss[i] += sqrSigmaNoise; // kss is V(f), add noise variance of predictive distibution to get V(y)
    376379          kss[i] -= sumV;
     
    378381        }
    379382        return kss;
    380       } catch (alglib.alglibexception ae) {
     383      }
     384      catch (alglib.alglibexception ae) {
    381385        // wrap exception so that calling code doesn't have to know about alglib implementation
    382386        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
    383387      }
    384388    }
     389
    385390  }
    386391}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/ICovarianceFunction.cs

    r12012 r15280  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq.Expressions;
    2523using HeuristicLab.Core;
    2624
     
    2927  public delegate double CovarianceFunctionDelegate(double[,] x, int i, int j);
    3028  public delegate double CrossCovarianceFunctionDelegate(double[,] x, double[,] xt, int i, int j);
    31   public delegate IEnumerable<double> CovarianceGradientFunctionDelegate(double[,] x, int i, int j);
     29  public delegate IList<double> CovarianceGradientFunctionDelegate(double[,] x, int i, int j);
    3230
    3331  public class ParameterizedCovarianceFunction {
     
    4038    int GetNumberOfParameters(int numberOfVariables);
    4139    void SetParameter(double[] p);
    42     ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices);
     40    ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices);
    4341  }
    4442}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/IMeanFunction.cs

    r12012 r15280  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Core;
    2523
     
    3634    int GetNumberOfParameters(int numberOfVariables);
    3735    void SetParameter(double[] p);
    38     ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices);
     36    ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices);
    3937  }
    4038}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanConst.cs

    r12012 r15280  
    7676    }
    7777
    78     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     78    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    7979      double c;
    8080      GetParameters(p, out c);
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanLinear.cs

    r12012 r15280  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Common;
     
    7069    }
    7170
    72     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     71    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    7372      double[] weights;
    74       int[] columns = columnIndices.ToArray();
     73      int[] columns = columnIndices;
    7574      GetParameter(p, out weights);
    7675      var mf = new ParameterizedMeanFunction();
     
    7877        // sanity check
    7978        if (weights.Length != columns.Length) throw new ArgumentException("The number of rparameters must match the number of variables for the linear mean function.");
    80         return Util.ScalarProd(weights, Util.GetRow(x, i, columns));
     79        return Util.ScalarProd(weights, Util.GetRow(x, i, columns).ToArray());
    8180      };
    8281      mf.Gradient = (x, i, k) => {
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanModel.cs

    r13136 r15280  
    7373    }
    7474
    75     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     75    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    7676      if (p.Length > 0) throw new ArgumentException("No parameters allowed for model-based mean function.", "p");
    7777      var solution = RegressionSolution;
    7878      var variableNames = solution.ProblemData.AllowedInputVariables.ToArray();
    79       if (variableNames.Length != columnIndices.Count())
     79      if (variableNames.Length != columnIndices.Length)
    8080        throw new ArgumentException("The number of input variables does not match in MeanModel");
    8181      var variableValues = variableNames.Select(_ => new List<double>() { 0.0 }).ToArray(); // or of zeros
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanProduct.cs

    r12012 r15280  
    7373
    7474
    75     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     75    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    7676      var factorMf = new List<ParameterizedMeanFunction>();
    7777      int totalNumberOfParameters = GetNumberOfParameters(numberOfVariables);
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanSum.cs

    r12012 r15280  
    6868    }
    6969
    70     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     70    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    7171      var termMf = new List<ParameterizedMeanFunction>();
    7272      int totalNumberOfParameters = GetNumberOfParameters(numberOfVariables);
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanZero.cs

    r12012 r15280  
    2020#endregion
    2121using System;
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    5048    }
    5149
    52     public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     50    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
    5351      if (p.Length > 0) throw new ArgumentException("No parameters allowed for zero mean function.", "p");
    5452      var mf = new ParameterizedMeanFunction();
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs

    r12012 r15280  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2725
    2826namespace HeuristicLab.Algorithms.DataAnalysis {
    2927  internal static class Util {
    30     public static double ScalarProd(IEnumerable<double> v, IEnumerable<double> u) {
    31       return v.Zip(u, (vi, ui) => vi * ui).Sum();
     28    public static double ScalarProd(double[] v, double[] u) {
     29      if (v.Length != u.Length) throw new InvalidOperationException();
     30      double prod = 0.0;
     31      for (int i = 0; i < v.Length; i++)
     32        prod += v[i] * u[i];
     33      return prod;
    3234    }
    3335
     
    4143    }
    4244
    43     public static double SqrDist(double[,] x, int i, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
    44       return SqrDist(x, i, x, j, scale, columnIndices);
     45    public static double SqrDist(double[,] x, int i, int j, int[] columnIndices, double scale = 1.0) {
     46      return SqrDist(x, i, x, j, columnIndices, scale);
    4547    }
    4648
    47     public static double SqrDist(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
     49    public static double SqrDist(double[,] x, int i, double[,] xt, int j, int[] columnIndices, double scale = 1.0) {
    4850      double ss = 0.0;
    49       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    50       foreach (int columnIndex in columnIndices) {
     51      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1)).ToArray();
     52      for (int c = 0; c < columnIndices.Length; c++) {
     53        var columnIndex = columnIndices[c];
    5154        double d = x[i, columnIndex] - xt[j, columnIndex];
    5255        ss += d * d;
     
    5558    }
    5659
    57     public static double SqrDist(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {
     60    public static double SqrDist(double[,] x, int i, int j, double[] scale, int[] columnIndices) {
    5861      return SqrDist(x, i, x, j, scale, columnIndices);
    5962    }
    6063
    61     public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {
     64    public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale, int[] columnIndices) {
    6265      double ss = 0.0;
    63       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    6466      int scaleIndex = 0;
    65       foreach (int columnIndex in columnIndices) {
     67      for (int c = 0; c < columnIndices.Length; c++) {
     68        var columnIndex = columnIndices[c];
    6669        double d = x[i, columnIndex] - xt[j, columnIndex];
    6770        ss += d * d * scale[scaleIndex] * scale[scaleIndex];
     
    7376      return ss;
    7477    }
    75     public static double ScalarProd(double[,] x, int i, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
    76       return ScalarProd(x, i, x, j, scale, columnIndices);
     78    public static double ScalarProd(double[,] x, int i, int j, int[] columnIndices, double scale = 1.0) {
     79      return ScalarProd(x, i, x, j, columnIndices, scale);
    7780    }
    7881
    79     public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
     82    public static double ScalarProd(double[,] x, int i, double[,] xt, int j, int[] columnIndices, double scale = 1.0) {
    8083      double sum = 0.0;
    81       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    82       foreach (int columnIndex in columnIndices) {
     84      for (int c = 0; c < columnIndices.Length; c++) {
     85        var columnIndex = columnIndices[c];
    8386        sum += x[i, columnIndex] * xt[j, columnIndex];
    8487      }
    8588      return scale * scale * sum;
    8689    }
    87     public static double ScalarProd(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {
     90    public static double ScalarProd(double[,] x, int i, int j, double[] scale, int[] columnIndices) {
    8891      return ScalarProd(x, i, x, j, scale, columnIndices);
    8992    }
    9093
    91     public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {
     94    public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale, int[] columnIndices) {
    9295      double sum = 0.0;
    93       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    9496      int scaleIndex = 0;
    95       foreach (int columnIndex in columnIndices) {
     97      for (int c = 0; c < columnIndices.Length; c++, scaleIndex++) {
     98        var columnIndex = columnIndices[c];
    9699        sum += x[i, columnIndex] * scale[scaleIndex] * xt[j, columnIndex] * scale[scaleIndex];
    97         scaleIndex++;
    98100      }
    99101      // must be at the end of scale after iterating over columnIndices
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs

    r13238 r15280  
    3535
    3636namespace HeuristicLab.Algorithms.DataAnalysis {
    37   [Item("Gradient Boosted Trees (GBT)", "Gradient boosted trees algorithm. Friedman, J. \"Greedy Function Approximation: A Gradient Boosting Machine\", IMS 1999 Reitz Lecture.")]
     37  [Item("Gradient Boosted Trees (GBT)", "Gradient boosted trees algorithm. Specific implementation of gradient boosting for regression trees. Friedman, J. \"Greedy Function Approximation: A Gradient Boosting Machine\", IMS 1999 Reitz Lecture.")]
    3838  [StorableClass]
    3939  [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 125)]
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs

    r13157 r15280  
    9696        weights = new List<double>();
    9797        // add constant model
    98         models.Add(new ConstantModel(f0));
     98        models.Add(new ConstantModel(f0, problemData.TargetVariable));
    9999        weights.Add(1.0);
    100100      }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r13157 r15280  
    3333  [Item("Gradient boosted tree model", "")]
    3434  // this is essentially a collection of weighted regression models
    35   public sealed class GradientBoostedTreesModel : NamedItem, IGradientBoostedTreesModel {
     35  public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel {
    3636    // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models
    3737    #region Backwards compatible code, remove with 3.5
     
    5858    #endregion
    5959
     60    public override IEnumerable<string> VariablesUsedForPrediction {
     61      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     62    }
     63
    6064    private readonly IList<IRegressionModel> models;
    6165    public IEnumerable<IRegressionModel> Models { get { return models; } }
     
    7781    }
    7882    [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")]
    79     public GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
    80       : base("Gradient boosted tree model", string.Empty) {
     83    internal GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
     84      : base(string.Empty, "Gradient boosted tree model", string.Empty) {
    8185      this.models = new List<IRegressionModel>(models);
    8286      this.weights = new List<double>(weights);
     
    8993    }
    9094
    91     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     95    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9296      // allocate target array go over all models and add up weighted estimation for each row
    9397      if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable.
     
    105109    }
    106110
    107     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    108112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    109113    }
     114
    110115  }
    111116}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r13157 r15280  
    2222
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3334  // recalculate the actual GBT model on demand
    3435  [Item("Gradient boosted tree model", "")]
    35   public sealed class GradientBoostedTreesModelSurrogate : NamedItem, IGradientBoostedTreesModel {
     36  public sealed class GradientBoostedTreesModelSurrogate : RegressionModel, IGradientBoostedTreesModel {
    3637    // don't store the actual model!
    3738    private IGradientBoostedTreesModel actualModel; // the actual model is only recalculated when necessary
     
    5556
    5657
     58    public override IEnumerable<string> VariablesUsedForPrediction {
     59      get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     60    }
     61
    5762    [StorableConstructor]
    5863    private GradientBoostedTreesModelSurrogate(bool deserializing) : base(deserializing) { }
     
    7378
    7479    // create only the surrogate model without an actual model
    75     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
    76       : base("Gradient boosted tree model", string.Empty) {
     80    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     81      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
     82      : base(trainingProblemData.TargetVariable, "Gradient boosted tree model", string.Empty) {
    7783      this.trainingProblemData = trainingProblemData;
    7884      this.seed = seed;
     
    8692
    8793    // wrap an actual model in a surrograte
    88     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu, IGradientBoostedTreesModel model)
     94    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     95      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu,
     96      IGradientBoostedTreesModel model)
    8997      : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) {
    9098      this.actualModel = model;
     
    96104
    97105    // forward message to actual model (recalculate model first if necessary)
    98     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     106    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    99107      if (actualModel == null) actualModel = RecalculateModel();
    100108      return actualModel.GetEstimatedValues(dataset, rows);
    101109    }
    102110
    103     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    104112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    105113    }
    106 
    107114
    108115    private IGradientBoostedTreesModel RecalculateModel() {
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs

    r13065 r15280  
    137137      int nRows = idx.Count();
    138138
    139       // shuffle variable idx
     139      // shuffle variable names
    140140      HeuristicLab.Random.ListExtensions.ShuffleInPlace(allowedVariables, random);
    141141
     
    176176      CreateRegressionTreeFromQueue(maxSize, lossFunction);
    177177
    178       return new RegressionTreeModel(tree.ToArray());
    179     }
    180 
    181 
    182     // processes potential splits from the queue as long as splits are left and the maximum size of the tree is not reached
     178      return new RegressionTreeModel(tree.ToArray(), problemData.TargetVariable);
     179    }
     180
     181
     182    // processes potential splits from the queue as long as splits are remaining and the maximum size of the tree is not reached
    183183    private void CreateRegressionTreeFromQueue(int maxNodes, ILossFunction lossFunction) {
    184184      while (queue.Any() && curTreeNodeIdx + 1 < maxNodes) { // two nodes are created in each loop
     
    204204
    205205        // overwrite existing leaf node with an internal node
    206         tree[f.ParentNodeIdx] = new RegressionTreeModel.TreeNode(f.SplittingVariable, f.SplittingThreshold, leftTreeIdx, rightTreeIdx);
     206        tree[f.ParentNodeIdx] = new RegressionTreeModel.TreeNode(f.SplittingVariable, f.SplittingThreshold, leftTreeIdx, rightTreeIdx, weightLeft: (splitIdx - startIdx + 1) / (double)(endIdx - startIdx + 1));
    207207      }
    208208    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r13030 r15280  
    3434  [StorableClass]
    3535  [Item("RegressionTreeModel", "Represents a decision tree for regression.")]
    36   public sealed class RegressionTreeModel : NamedItem, IRegressionModel {
     36  public sealed class RegressionTreeModel : RegressionModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
     38      get { return tree.Select(t => t.VarName).Where(v => v != TreeNode.NO_VARIABLE); }
     39    }
    3740
    3841    // trees are represented as a flat array   
     
    4043      public readonly static string NO_VARIABLE = null;
    4144
    42       public TreeNode(string varName, double val, int leftIdx = -1, int rightIdx = -1)
     45      public TreeNode(string varName, double val, int leftIdx = -1, int rightIdx = -1, double weightLeft = -1.0)
    4346        : this() {
    4447        VarName = varName;
     
    4649        LeftIdx = leftIdx;
    4750        RightIdx = rightIdx;
    48       }
    49 
    50       public string VarName { get; private set; } // name of the variable for splitting or NO_VARIABLE if terminal node
    51       public double Val { get; private set; } // threshold
    52       public int LeftIdx { get; private set; }
    53       public int RightIdx { get; private set; }
     51        WeightLeft = weightLeft;
     52      }
     53
     54      public string VarName { get; internal set; } // name of the variable for splitting or NO_VARIABLE if terminal node
     55      public double Val { get; internal set; } // threshold
     56      public int LeftIdx { get; internal set; }
     57      public int RightIdx { get; internal set; }
     58      public double WeightLeft { get; internal set; } // for partial dependence plots (value in range [0..1] describes the fraction of training samples for the left sub-tree
     59
    5460
    5561      // necessary because the default implementation of GetHashCode for structs in .NET would only return the hashcode of val here
     
    6470            LeftIdx.Equals(other.LeftIdx) &&
    6571            RightIdx.Equals(other.RightIdx) &&
     72            WeightLeft.Equals(other.WeightLeft) &&
    6673            EqualStrings(VarName, other.VarName);
    6774        } else {
     
    7986    private TreeNode[] tree;
    8087
    81     [Storable]
     88    #region old storable format
     89    // remove with HL 3.4
     90    [Storable(AllowOneWay = true)]
    8291    // to prevent storing the references to data caches in nodes
    83     // TODO seemingly it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary)
     92    // seemingly, it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary)
    8493    private Tuple<string, double, int, int>[] SerializedTree {
    85       get { return tree.Select(t => Tuple.Create(t.VarName, t.Val, t.LeftIdx, t.RightIdx)).ToArray(); }
    86       set { this.tree = value.Select(t => new TreeNode(t.Item1, t.Item2, t.Item3, t.Item4)).ToArray(); }
    87     }
     94      // get { return tree.Select(t => Tuple.Create(t.VarName, t.Val, t.LeftIdx, t.RightIdx)).ToArray(); }
     95      set { this.tree = value.Select(t => new TreeNode(t.Item1, t.Item2, t.Item3, t.Item4, -1.0)).ToArray(); } // use a weight of -1.0 to indicate that partial dependence cannot be calculated for old models
     96    }
     97    #endregion
     98    #region new storable format
     99    [Storable]
     100    private string[] SerializedTreeVarNames {
     101      get { return tree.Select(t => t.VarName).ToArray(); }
     102      set {
     103        if (tree == null) tree = new TreeNode[value.Length];
     104        for (int i = 0; i < value.Length; i++) {
     105          tree[i].VarName = value[i];
     106        }
     107      }
     108    }
     109    [Storable]
     110    private double[] SerializedTreeValues {
     111      get { return tree.Select(t => t.Val).ToArray(); }
     112      set {
     113        if (tree == null) tree = new TreeNode[value.Length];
     114        for (int i = 0; i < value.Length; i++) {
     115          tree[i].Val = value[i];
     116        }
     117      }
     118    }
     119    [Storable]
     120    private int[] SerializedTreeLeftIdx {
     121      get { return tree.Select(t => t.LeftIdx).ToArray(); }
     122      set {
     123        if (tree == null) tree = new TreeNode[value.Length];
     124        for (int i = 0; i < value.Length; i++) {
     125          tree[i].LeftIdx = value[i];
     126        }
     127      }
     128    }
     129    [Storable]
     130    private int[] SerializedTreeRightIdx {
     131      get { return tree.Select(t => t.RightIdx).ToArray(); }
     132      set {
     133        if (tree == null) tree = new TreeNode[value.Length];
     134        for (int i = 0; i < value.Length; i++) {
     135          tree[i].RightIdx = value[i];
     136        }
     137      }
     138    }
     139    [Storable]
     140    private double[] SerializedTreeWeightLeft {
     141      get { return tree.Select(t => t.WeightLeft).ToArray(); }
     142      set {
     143        if (tree == null) tree = new TreeNode[value.Length];
     144        for (int i = 0; i < value.Length; i++) {
     145          tree[i].WeightLeft = value[i];
     146        }
     147      }
     148    }
     149    #endregion
    88150
    89151    [StorableConstructor]
     
    98160    }
    99161
    100     internal RegressionTreeModel(TreeNode[] tree)
    101       : base("RegressionTreeModel", "Represents a decision tree for regression.") {
     162    internal RegressionTreeModel(TreeNode[] tree, string targetVariable)
     163      : base(targetVariable, "RegressionTreeModel", "Represents a decision tree for regression.") {
    102164      this.tree = tree;
    103165    }
     
    108170        if (node.VarName == TreeNode.NO_VARIABLE)
    109171          return node.Val;
    110 
    111         if (columnCache[nodeIdx][row] <= node.Val)
     172        if (columnCache[nodeIdx] == null) {
     173          if (node.WeightLeft.IsAlmost(-1.0)) throw new InvalidOperationException("Cannot calculate partial dependence for trees loaded from older versions of HeuristicLab.");
     174          // weighted average for partial dependence plot (recursive here because we need to calculate both sub-trees)
     175          return node.WeightLeft * GetPredictionForRow(t, columnCache, node.LeftIdx, row) +
     176                 (1.0 - node.WeightLeft) * GetPredictionForRow(t, columnCache, node.RightIdx, row);
     177        } else if (columnCache[nodeIdx][row] <= node.Val)
    112178          nodeIdx = node.LeftIdx;
    113179        else
     
    121187    }
    122188
    123     public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
     189    public override IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
    124190      // lookup columns for variableNames in one pass over the tree to speed up evaluation later on
    125191      ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length];
     
    127193      for (int i = 0; i < tree.Length; i++) {
    128194        if (tree[i].VarName != TreeNode.NO_VARIABLE) {
    129           columnCache[i] = ds.GetReadOnlyDoubleValues(tree[i].VarName);
     195          // tree models also support calculating estimations if not all variables used for training are available in the dataset
     196          if (ds.ColumnNames.Contains(tree[i].VarName))
     197            columnCache[i] = ds.GetReadOnlyDoubleValues(tree[i].VarName);
    130198        }
    131199      }
     
    133201    }
    134202
    135     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     203    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    136204      return new RegressionSolution(this, new RegressionProblemData(problemData));
    137205    }
     
    148216      } else {
    149217        return
    150           TreeToString(n.LeftIdx, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2} <= {3:F}", part, string.IsNullOrEmpty(part) ? "" : " and ", n.VarName, n.Val))
    151         + TreeToString(n.RightIdx, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2} >  {3:F}", part, string.IsNullOrEmpty(part) ? "" : " and ", n.VarName, n.Val));
    152       }
    153     }
     218          TreeToString(n.LeftIdx, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2} <= {3:F} ({4:N3})", part, string.IsNullOrEmpty(part) ? "" : " and ", n.VarName, n.Val, n.WeightLeft))
     219        + TreeToString(n.RightIdx, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}  >  {3:F} ({4:N3}))", part, string.IsNullOrEmpty(part) ? "" : " and ", n.VarName, n.Val, 1.0 - n.WeightLeft));
     220      }
     221    }
     222
    154223  }
    155224}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r13157 r15280  
    201201    <Compile Include="GaussianProcess\GaussianProcessRegressionSolution.cs" />
    202202    <Compile Include="GaussianProcess\ICovarianceFunction.cs" />
     203    <Compile Include="GBM\GradientBoostingRegressionAlgorithm.cs" />
    203204    <Compile Include="GradientBoostedTrees\IGradientBoostedTreesModel.cs" />
    204205    <Compile Include="GradientBoostedTrees\GradientBoostedTreesModelSurrogate.cs" />
     
    252253    <Compile Include="Linear\MultinomialLogitClassificationSolution.cs" />
    253254    <Compile Include="Linear\MultinomialLogitModel.cs" />
     255    <Compile Include="MctsSymbolicRegression\Automaton.cs" />
     256    <Compile Include="MctsSymbolicRegression\CodeGenerator.cs" />
     257    <Compile Include="MctsSymbolicRegression\ConstraintHandler.cs" />
     258    <Compile Include="MctsSymbolicRegression\Disassembler.cs" />
     259    <Compile Include="MctsSymbolicRegression\ExpressionEvaluator.cs" />
     260    <Compile Include="MctsSymbolicRegression\MctsSymbolicRegressionAlgorithm.cs" />
     261    <Compile Include="MctsSymbolicRegression\MctsSymbolicRegressionStatic.cs" />
     262    <Compile Include="MctsSymbolicRegression\OpCodes.cs" />
     263    <Compile Include="MctsSymbolicRegression\Policies\EpsGreedy.cs" />
     264    <Compile Include="MctsSymbolicRegression\Policies\UcbTuned.cs" />
     265    <Compile Include="MctsSymbolicRegression\Policies\IActionStatistics.cs" />
     266    <Compile Include="MctsSymbolicRegression\Policies\IPolicy.cs" />
     267    <Compile Include="MctsSymbolicRegression\Policies\PolicyBase.cs" />
     268    <Compile Include="MctsSymbolicRegression\Policies\Ucb.cs" />
     269    <Compile Include="MctsSymbolicRegression\SymbolicExpressionGenerator.cs" />
     270    <Compile Include="MctsSymbolicRegression\Tree.cs" />
    254271    <Compile Include="Nca\Initialization\INcaInitializer.cs" />
    255272    <Compile Include="Nca\Initialization\LdaInitializer.cs" />
     
    309326      <Private>False</Private>
    310327    </ProjectReference>
     328    <ProjectReference Include="..\..\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm\3.3\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.csproj">
     329      <Project>{F409DD9E-1E9C-4EB1-AA3A-9F6E987C6E58}</Project>
     330      <Name>HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3</Name>
     331    </ProjectReference>
    311332    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
    312333      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
     
    407428      <Name>HeuristicLab.Random-3.3</Name>
    408429      <Private>False</Private>
     430    </ProjectReference>
     431    <ProjectReference Include="..\..\HeuristicLab.Selection\3.3\HeuristicLab.Selection-3.3.csproj">
     432      <Project>{2C36CD4F-E5F5-43A4-801A-201EA895FE17}</Project>
     433      <Name>HeuristicLab.Selection-3.3</Name>
    409434    </ProjectReference>
    410435  </ItemGroup>
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r12509 r15280  
    111111      IClassificationProblemData problemData,
    112112      IEnumerable<int> rows) {
    113       var model = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter, new AccuracyMaximizationThresholdCalculator());
     113      var model = new SymbolicDiscriminantFunctionClassificationModel(problemData.TargetVariable, tree, interpreter, new AccuracyMaximizationThresholdCalculator());
    114114      model.RecalculateModelParameters(problemData, rows);
    115115      return model;
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r13238 r15280  
    110110      addition.AddSubtree(cNode);
    111111
    112       SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone());
     112      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone());
    113113      solution.Model.Name = "Linear Regression Model";
    114114      solution.Name = "Linear Regression Solution";
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs

    r13238 r15280  
    9595      relClassError = alglib.mnlrelclserror(lm, inputMatrix, nRows);
    9696
    97       MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution((IClassificationProblemData)problemData.Clone(), new MultinomialLogitModel(lm, targetVariable, allowedInputVariables, classValues));
     97      MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution(new MultinomialLogitModel(lm, targetVariable, allowedInputVariables, classValues), (IClassificationProblemData)problemData.Clone());
    9898      return solution;
    9999    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassificationSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public MultinomialLogitClassificationSolution(IClassificationProblemData problemData, MultinomialLogitModel logitModel)
     45    public MultinomialLogitClassificationSolution( MultinomialLogitModel logitModel,IClassificationProblemData problemData)
    4646      : base(logitModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs

    r12509 r15280  
    3434  [StorableClass]
    3535  [Item("Multinomial Logit Model", "Represents a multinomial logit model for classification.")]
    36   public sealed class MultinomialLogitModel : NamedItem, IClassificationModel {
     36  public sealed class MultinomialLogitModel : ClassificationModel {
    3737
    3838    private alglib.logitmodel logitModel;
     
    4848    }
    4949
    50     [Storable]
    51     private string targetVariable;
     50    public override IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
    5254    [Storable]
    5355    private string[] allowedInputVariables;
     
    6466      logitModel = new alglib.logitmodel();
    6567      logitModel.innerobj.w = (double[])original.logitModel.innerobj.w.Clone();
    66       targetVariable = original.targetVariable;
    6768      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    6869      classValues = (double[])original.classValues.Clone();
    6970    }
    7071    public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)
    71       : base() {
     72      : base(targetVariable) {
    7273      this.name = ItemName;
    7374      this.description = ItemDescription;
    7475      this.logitModel = logitModel;
    75       this.targetVariable = targetVariable;
    7676      this.allowedInputVariables = allowedInputVariables.ToArray();
    7777      this.classValues = (double[])classValues.Clone();
     
    8282    }
    8383
    84     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     84    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    8585      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    8686
     
    108108    }
    109109
    110     public MultinomialLogitClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    111       return new MultinomialLogitClassificationSolution(new ClassificationProblemData(problemData), this);
    112     }
    113     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    114       return CreateClassificationSolution(problemData);
     110    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     111      return new MultinomialLogitClassificationSolution(this, new ClassificationProblemData(problemData));
    115112    }
    116113
     
    135132    }
    136133    #endregion
     134
    137135  }
    138136}
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaClassificationSolution.cs

    r12012 r15280  
    4040      : base(original, cloner) {
    4141    }
    42     public NcaClassificationSolution(IClassificationProblemData problemData, INcaModel ncaModel)
     42    public NcaClassificationSolution(INcaModel ncaModel, IClassificationProblemData problemData)
    4343      : base(ncaModel, problemData) {
    4444    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r12509 r15280  
    3030  [Item("NCA Model", "")]
    3131  [StorableClass]
    32   public class NcaModel : NamedItem, INcaModel {
     32  public class NcaModel : ClassificationModel, INcaModel {
     33    public override IEnumerable<string> VariablesUsedForPrediction {
     34      get { return allowedInputVariables; }
     35    }
    3336
    3437    [Storable]
     
    3942    [Storable]
    4043    private string[] allowedInputVariables;
    41     [Storable]
    42     private string targetVariable;
    4344    [Storable]
    4445    private INearestNeighbourModel nnModel;
     
    5253      this.transformationMatrix = (double[,])original.transformationMatrix.Clone();
    5354      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    54       this.targetVariable = original.targetVariable;
    5555      this.nnModel = cloner.Clone(original.nnModel);
    5656      this.classValues = (double[])original.classValues.Clone();
    5757    }
    58     public NcaModel(int k, double[,] transformationMatrix, IDataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues) {
     58    public NcaModel(int k, double[,] transformationMatrix, IDataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)
     59      : base(targetVariable) {
    5960      Name = ItemName;
    6061      Description = ItemDescription;
    6162      this.transformationMatrix = (double[,])transformationMatrix.Clone();
    6263      this.allowedInputVariables = allowedInputVariables.ToArray();
    63       this.targetVariable = targetVariable;
    6464      this.classValues = (double[])classValues.Clone();
    6565
     
    7272    }
    7373
    74     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     74    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    7575      var ds = ReduceDataset(dataset, rows);
    7676      return nnModel.GetEstimatedClassValues(ds, Enumerable.Range(0, ds.Rows));
    7777    }
    7878
    79     public INcaClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    80       return new NcaClassificationSolution(new ClassificationProblemData(problemData), this);
     79    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     80      return new NcaClassificationSolution(this, new ClassificationProblemData(problemData));
    8181    }
    8282
    83     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    84       return CreateClassificationSolution(problemData);
     83    INcaClassificationSolution INcaModel.CreateClassificationSolution(IClassificationProblemData problemData) {
     84      return new NcaClassificationSolution(this, new ClassificationProblemData(problemData));
    8585    }
    8686
     
    8888      var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    8989
    90       var targets = dataset.GetDoubleValues(targetVariable, rows).ToArray();
     90      var targets = dataset.GetDoubleValues(TargetVariable, rows).ToArray();
    9191      var result = new double[data.GetLength(0), transformationMatrix.GetLength(1) + 1];
    9292      for (int i = 0; i < data.GetLength(0); i++)
     
    104104          .Range(0, transformationMatrix.GetLength(1))
    105105          .Select(x => "X" + x.ToString())
    106           .Concat(targetVariable.ToEnumerable()),
     106          .Concat(TargetVariable.ToEnumerable()),
    107107        Reduce(dataset, rows));
    108108    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs

    r13238 r15280  
    8181    public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k) {
    8282      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    83       return new NearestNeighbourClassificationSolution(problemDataClone, Train(problemDataClone, k));
     83      return new NearestNeighbourClassificationSolution(Train(problemDataClone, k), problemDataClone);
    8484    }
    8585
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassificationSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourClassificationSolution(IClassificationProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourClassificationSolution(INearestNeighbourModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r12509 r15280  
    3434  [StorableClass]
    3535  [Item("NearestNeighbourModel", "Represents a nearest neighbour model for regression and classification.")]
    36   public sealed class NearestNeighbourModel : NamedItem, INearestNeighbourModel {
     36  public sealed class NearestNeighbourModel : ClassificationModel, INearestNeighbourModel {
    3737
    3838    private alglib.nearestneighbor.kdtree kdTree;
     
    4848    }
    4949
    50     [Storable]
    51     private string targetVariable;
     50    public override IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
    5254    [Storable]
    5355    private string[] allowedInputVariables;
     
    9193
    9294      k = original.k;
    93       targetVariable = original.targetVariable;
    9495      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    9596      if (original.classValues != null)
    9697        this.classValues = (double[])original.classValues.Clone();
    9798    }
    98     public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null) {
     99    public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
     100      : base(targetVariable) {
    99101      Name = ItemName;
    100102      Description = ItemDescription;
    101103      this.k = k;
    102       this.targetVariable = targetVariable;
    103104      this.allowedInputVariables = allowedInputVariables.ToArray();
    104105
     
    163164    }
    164165
    165     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     166    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    166167      if (classValues == null) throw new InvalidOperationException("No class values are defined.");
    167168      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     
    201202    }
    202203
    203     public INearestNeighbourRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    204       return new NearestNeighbourRegressionSolution(new RegressionProblemData(problemData), this);
    205     }
     204
    206205    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    207       return CreateRegressionSolution(problemData);
    208     }
    209     public INearestNeighbourClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    210       return new NearestNeighbourClassificationSolution(new ClassificationProblemData(problemData), this);
    211     }
    212     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    213       return CreateClassificationSolution(problemData);
     206      return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData));
     207    }
     208    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     209      return new NearestNeighbourClassificationSolution(this, new ClassificationProblemData(problemData));
    214210    }
    215211
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs

    r13238 r15280  
    8080    public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k) {
    8181      var clonedProblemData = (IRegressionProblemData)problemData.Clone();
    82       return new NearestNeighbourRegressionSolution(clonedProblemData, Train(problemData, k));
     82      return new NearestNeighbourRegressionSolution(Train(problemData, k), clonedProblemData);
    8383    }
    8484
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegressionSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourRegressionSolution(IRegressionProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourRegressionSolution(INearestNeighbourModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs

    r13238 r15280  
    220220
    221221      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    222       return new NeuralNetworkClassificationSolution(problemDataClone, new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()));
     222      return new NeuralNetworkClassificationSolution(new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()), problemDataClone);
    223223    }
    224224    #endregion
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassificationSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkClassificationSolution(IClassificationProblemData problemData, INeuralNetworkModel nnModel)
     45    public NeuralNetworkClassificationSolution(INeuralNetworkModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs

    r13238 r15280  
    204204      relClassError = alglib.mlperelclserror(mlpEnsemble, inputMatrix, nRows);
    205205      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    206       return new NeuralNetworkEnsembleClassificationSolution(problemDataClone, new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()));
     206      return new NeuralNetworkEnsembleClassificationSolution(new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()), problemDataClone);
    207207    }
    208208    #endregion
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassificationSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkEnsembleClassificationSolution(IClassificationProblemData problemData, INeuralNetworkEnsembleModel nnModel)
     45    public NeuralNetworkEnsembleClassificationSolution(INeuralNetworkEnsembleModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r12509 r15280  
    3434  [StorableClass]
    3535  [Item("NeuralNetworkEnsembleModel", "Represents a neural network ensemble for regression and classification.")]
    36   public sealed class NeuralNetworkEnsembleModel : NamedItem, INeuralNetworkEnsembleModel {
     36  public sealed class NeuralNetworkEnsembleModel : ClassificationModel, INeuralNetworkEnsembleModel {
    3737
    3838    private alglib.mlpensemble mlpEnsemble;
     
    4646        }
    4747      }
     48    }
     49
     50    public override IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
    4852    }
    4953
     
    7276    }
    7377    public NeuralNetworkEnsembleModel(alglib.mlpensemble mlpEnsemble, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
    74       : base() {
     78      : base(targetVariable) {
    7579      this.name = ItemName;
    7680      this.description = ItemDescription;
     
    103107    }
    104108
    105     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     109    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    106110      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    107111
     
    129133    }
    130134
    131     public INeuralNetworkEnsembleRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    132       return new NeuralNetworkEnsembleRegressionSolution(new RegressionEnsembleProblemData(problemData), this);
    133     }
    134     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    135       return CreateRegressionSolution(problemData);
    136     }
    137     public INeuralNetworkEnsembleClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    138       return new NeuralNetworkEnsembleClassificationSolution(new ClassificationEnsembleProblemData(problemData), this);
    139     }
    140     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    141       return CreateClassificationSolution(problemData);
     135    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     136      return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData));
     137    }
     138    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     139      return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData));
    142140    }
    143141
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs

    r13238 r15280  
    190190      avgRelError = alglib.mlpeavgrelerror(mlpEnsemble, inputMatrix, nRows);
    191191
    192       return new NeuralNetworkEnsembleRegressionSolution((IRegressionProblemData)problemData.Clone(), new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables));
     192      return new NeuralNetworkEnsembleRegressionSolution(new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone());
    193193    }
    194194    #endregion
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegressionSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkEnsembleRegressionSolution(IRegressionProblemData problemData, INeuralNetworkEnsembleModel nnModel)
     45    public NeuralNetworkEnsembleRegressionSolution(INeuralNetworkEnsembleModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747      RecalculateResults();
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r12817 r15280  
    3434  [StorableClass]
    3535  [Item("NeuralNetworkModel", "Represents a neural network for regression and classification.")]
    36   public sealed class NeuralNetworkModel : NamedItem, INeuralNetworkModel {
     36  public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel {
    3737
    3838    private alglib.multilayerperceptron multiLayerPerceptron;
     
    4848    }
    4949
    50     [Storable]
    51     private string targetVariable;
     50    public override IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
    5254    [Storable]
    5355    private string[] allowedInputVariables;
     
    7476      multiLayerPerceptron.innerobj.x = (double[])original.multiLayerPerceptron.innerobj.x.Clone();
    7577      multiLayerPerceptron.innerobj.y = (double[])original.multiLayerPerceptron.innerobj.y.Clone();
    76       targetVariable = original.targetVariable;
    7778      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    7879      if (original.classValues != null)
     
    8081    }
    8182    public NeuralNetworkModel(alglib.multilayerperceptron multiLayerPerceptron, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
    82       : base() {
     83      : base(targetVariable) {
    8384      this.name = ItemName;
    8485      this.description = ItemDescription;
    8586      this.multiLayerPerceptron = multiLayerPerceptron;
    86       this.targetVariable = targetVariable;
    8787      this.allowedInputVariables = allowedInputVariables.ToArray();
    8888      if (classValues != null)
     
    111111    }
    112112
    113     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     113    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    114114      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    115115
     
    137137    }
    138138
    139     public INeuralNetworkRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    140       return new NeuralNetworkRegressionSolution(new RegressionProblemData(problemData), this);
    141     }
    142     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    143       return CreateRegressionSolution(problemData);
    144     }
    145     public INeuralNetworkClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    146       return new NeuralNetworkClassificationSolution(new ClassificationProblemData(problemData), this);
    147     }
    148     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    149       return CreateClassificationSolution(problemData);
     139    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     140      return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData));
     141    }
     142    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     143      return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData));
    150144    }
    151145
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs

    r13238 r15280  
    207207      avgRelError = alglib.mlpavgrelerror(multiLayerPerceptron, inputMatrix, nRows);
    208208
    209       return new NeuralNetworkRegressionSolution((IRegressionProblemData)problemData.Clone(), new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables));
     209      return new NeuralNetworkRegressionSolution(new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone());
    210210    }
    211211    #endregion
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegressionSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkRegressionSolution(IRegressionProblemData problemData, INeuralNetworkModel nnModel)
     45    public NeuralNetworkRegressionSolution(INeuralNetworkModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/Plugin.cs.frame

    r13321 r15280  
    2929  [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
     31  [PluginDependency("HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm", "3.3")] // for GBM
    3132  [PluginDependency("HeuristicLab.Algorithms.GradientDescent", "3.3")]
    3233  [PluginDependency("HeuristicLab.Analysis", "3.3")]
     
    5051  [PluginDependency("HeuristicLab.LibSVM", "3.12")]
    5152  [PluginDependency("HeuristicLab.Random", "3.3")]
     53  [PluginDependency("HeuristicLab.Selection", "3.3")]
    5254  public class HeuristicLabAlgorithmsDataAnalysisPlugin : PluginBase {
    5355  }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs

    r13238 r15280  
    143143
    144144      if (CreateSolution) {
    145         var solution = new RandomForestClassificationSolution((IClassificationProblemData)Problem.ProblemData.Clone(), model);
     145        var solution = new RandomForestClassificationSolution(model, (IClassificationProblemData)Problem.ProblemData.Clone());
    146146        Results.Add(new Result(RandomForestClassificationModelResultName, "The random forest classification solution.", solution));
    147147      }
    148148    }
    149    
     149
    150150    // keep for compatibility with old API
    151151    public static RandomForestClassificationSolution CreateRandomForestClassificationSolution(IClassificationProblemData problemData, int nTrees, double r, double m, int seed,
    152152      out double rmsError, out double relClassificationError, out double outOfBagRmsError, out double outOfBagRelClassificationError) {
    153153      var model = CreateRandomForestClassificationModel(problemData, nTrees, r, m, seed, out rmsError, out relClassificationError, out outOfBagRmsError, out outOfBagRelClassificationError);
    154       return new RandomForestClassificationSolution((IClassificationProblemData)problemData.Clone(), model);
     154      return new RandomForestClassificationSolution(model, (IClassificationProblemData)problemData.Clone());
    155155    }
    156156
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassificationSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public RandomForestClassificationSolution(IClassificationProblemData problemData, IRandomForestModel randomForestModel)
     45    public RandomForestClassificationSolution(IRandomForestModel randomForestModel, IClassificationProblemData problemData)
    4646      : base(randomForestModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r12509 r15280  
    3434  [StorableClass]
    3535  [Item("RandomForestModel", "Represents a random forest for regression and classification.")]
    36   public sealed class RandomForestModel : NamedItem, IRandomForestModel {
     36  public sealed class RandomForestModel : ClassificationModel, IRandomForestModel {
    3737    // not persisted
    3838    private alglib.decisionforest randomForest;
     
    4444      }
    4545    }
     46
     47    public override IEnumerable<string> VariablesUsedForPrediction {
     48      get { return originalTrainingData.AllowedInputVariables; }
     49    }
     50
    4651
    4752    // instead of storing the data of the model itself
     
    9196
    9297    // random forest models can only be created through the static factory methods CreateRegressionModel and CreateClassificationModel
    93     private RandomForestModel(alglib.decisionforest randomForest,
     98    private RandomForestModel(string targetVariable, alglib.decisionforest randomForest,
    9499      int seed, IDataAnalysisProblemData originalTrainingData,
    95100      int nTrees, double r, double m, double[] classValues = null)
    96       : base() {
     101      : base(targetVariable) {
    97102      this.name = ItemName;
    98103      this.description = ItemDescription;
     
    147152    }
    148153
    149     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     154    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    150155      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows);
    151156      AssertInputMatrix(inputData);
     
    174179    }
    175180
    176     public IRandomForestRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    177       return new RandomForestRegressionSolution(new RegressionProblemData(problemData), this);
    178     }
    179     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    180       return CreateRegressionSolution(problemData);
    181     }
    182     public IRandomForestClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    183       return new RandomForestClassificationSolution(new ClassificationProblemData(problemData), this);
    184     }
    185     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    186       return CreateClassificationSolution(problemData);
     181
     182    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     183      return new RandomForestRegressionSolution(this, new RegressionProblemData(problemData));
     184    }
     185    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     186      return new RandomForestClassificationSolution(this, new ClassificationProblemData(problemData));
    187187    }
    188188
     
    205205      outOfBagRmsError = rep.oobrmserror;
    206206
    207       return new RandomForestModel(dForest, seed, problemData, nTrees, r, m);
     207      return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m);
    208208    }
    209209
     
    242242      outOfBagRelClassificationError = rep.oobrelclserror;
    243243
    244       return new RandomForestModel(dForest, seed, problemData, nTrees, r, m, classValues);
     244      return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m, classValues);
    245245    }
    246246
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs

    r13238 r15280  
    143143
    144144      if (CreateSolution) {
    145         var solution = new RandomForestRegressionSolution((IRegressionProblemData)Problem.ProblemData.Clone(), model);
     145        var solution = new RandomForestRegressionSolution(model, (IRegressionProblemData)Problem.ProblemData.Clone());
    146146        Results.Add(new Result(RandomForestRegressionModelResultName, "The random forest regression solution.", solution));
    147147      }
     
    153153      var model = CreateRandomForestRegressionModel(problemData, nTrees, r, m, seed,
    154154        out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
    155       return new RandomForestRegressionSolution((IRegressionProblemData)problemData.Clone(), model);
     155      return new RandomForestRegressionSolution(model, (IRegressionProblemData)problemData.Clone());
    156156    }
    157157
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegressionSolution.cs

    r12012 r15280  
    4343      : base(original, cloner) {
    4444    }
    45     public RandomForestRegressionSolution(IRegressionProblemData problemData, IRandomForestModel randomForestModel)
     45    public RandomForestRegressionSolution(IRandomForestModel randomForestModel, IRegressionProblemData problemData)
    4646      : base(randomForestModel, problemData) {
    4747    }
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs

    r12509 r15280  
    3737  [StorableClass]
    3838  [Item("SupportVectorMachineModel", "Represents a support vector machine model.")]
    39   public sealed class SupportVectorMachineModel : NamedItem, ISupportVectorMachineModel {
     39  public sealed class SupportVectorMachineModel : ClassificationModel, ISupportVectorMachineModel {
     40    public override IEnumerable<string> VariablesUsedForPrediction {
     41      get { return allowedInputVariables; }
     42    }
     43
    4044
    4145    private svm_model model;
     
    8387
    8488    [Storable]
    85     private string targetVariable;
    86     [Storable]
    8789    private string[] allowedInputVariables;
    8890    [Storable]
     
    9698      this.model = original.model;
    9799      this.rangeTransform = original.rangeTransform;
    98       this.targetVariable = original.targetVariable;
    99100      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    100101      if (original.classValues != null)
     
    106107    }
    107108    public SupportVectorMachineModel(svm_model model, RangeTransform rangeTransform, string targetVariable, IEnumerable<string> allowedInputVariables)
    108       : base() {
     109      : base(targetVariable) {
    109110      this.name = ItemName;
    110111      this.description = ItemDescription;
    111112      this.model = model;
    112113      this.rangeTransform = rangeTransform;
    113       this.targetVariable = targetVariable;
    114114      this.allowedInputVariables = allowedInputVariables.ToArray();
    115115    }
     
    123123      return GetEstimatedValuesHelper(dataset, rows);
    124124    }
    125     public SupportVectorRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     125    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    126126      return new SupportVectorRegressionSolution(this, new RegressionProblemData(problemData));
    127127    }
    128     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    129       return CreateRegressionSolution(problemData);
    130     }
    131128    #endregion
    132129
    133130    #region IClassificationModel Members
    134     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     131    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    135132      if (classValues == null) throw new NotSupportedException();
    136133      // return the original class value instead of the predicted value of the model
     
    152149    }
    153150
    154     public SupportVectorClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     151    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    155152      return new SupportVectorClassificationSolution(this, new ClassificationProblemData(problemData));
    156     }
    157     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    158       return CreateClassificationSolution(problemData);
    159153    }
    160154    #endregion
    161155    private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) {
    162156      // calculate predictions for the currently requested rows
    163       svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows);
     157      svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, TargetVariable, allowedInputVariables, rows);
    164158      svm_problem scaledProblem = rangeTransform.Scale(problem);
    165159
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs

    r13238 r15280  
    134134
    135135      var interpreter = new SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(problemData.TargetVariable);
    136       var model = new SymbolicTimeSeriesPrognosisModel(tree, interpreter);
     136      var model = new SymbolicTimeSeriesPrognosisModel(problemData.TargetVariable, tree, interpreter);
    137137      var solution = model.CreateTimeSeriesPrognosisSolution((ITimeSeriesPrognosisProblemData)problemData.Clone());
    138138      return solution;
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs

    r12509 r15280  
    3737    public static new Image StaticItemImage {
    3838      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
     39    }
     40
     41    public IEnumerable<string> VariablesUsedForPrediction {
     42      get { return allowedInputVariables; }
    3943    }
    4044
Note: See TracChangeset for help on using the changeset viewer.