Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13721


Ignore:
Timestamp:
03/23/16 16:19:04 (8 years ago)
Author:
mkommend
Message:

#2591: Changed all GP covariance and mean functions to use int[] for column indices instead of IEnumerable<int>. Changed GP utils, GPModel and StudentTProcessModell as well to use fewer iterators and adapted unit tests to new interface.

Location:
trunk/sources
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r13707 r13721  
    317317          // just produce an ensemble solution for now (TODO: correct scaling or linear regression for ensemble model weights)
    318318
    319           var ensembleModel = new RegressionEnsembleModel(models) { AverageModelEstimates = false };
    320           var ensembleSolution = ensembleModel.CreateRegressionSolution((IRegressionProblemData)problemData.Clone());
     319          var ensembleSolution = CreateEnsembleSolution(models, (IRegressionProblemData)problemData.Clone());
    321320          Results.Add(new Result("EnsembleSolution", ensembleSolution));
    322321        }
     
    326325        alg.Prepare(true);
    327326      }
     327    }
     328
     329    private static IRegressionEnsembleSolution CreateEnsembleSolution(List<IRegressionModel> models,
     330      IRegressionProblemData problemData) {
     331      var rows = problemData.TrainingPartition.Size;
     332      var features = models.Count;
     333      double[,] inputMatrix = new double[rows, features + 1];
     334
     335      //add model estimates
     336      for (int m = 0; m < models.Count; m++) {
     337        var model = models[m];
     338        var estimates = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices);
     339        int estimatesCounter = 0;
     340        foreach (var estimate in estimates) {
     341          inputMatrix[estimatesCounter, m] = estimate;
     342          estimatesCounter++;
     343        }
     344      }
     345
     346      //add target
     347      var targets = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
     348      int targetCounter = 0;
     349      foreach (var target in targets) {
     350        inputMatrix[targetCounter, models.Count] = target;
     351        targetCounter++;
     352      }
     353
     354      alglib.linearmodel lm = new alglib.linearmodel();
     355      alglib.lrreport ar = new alglib.lrreport();
     356      double[] coefficients;
     357      int retVal = 1;
     358      alglib.lrbuildz(inputMatrix, rows, features, out retVal, out lm, out ar);
     359      if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution");
     360
     361      alglib.lrunpack(lm, out coefficients, out features);
     362
     363      var ensembleModel = new RegressionEnsembleModel(models, coefficients.Take(models.Count)) { AverageModelEstimates = false };
     364      var ensembleSolution = ensembleModel.CreateRegressionSolution((IRegressionProblemData)problemData.Clone());
     365      return ensembleSolution;
    328366    }
    329367
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceConst.cs

    r12012 r13721  
    8383    }
    8484
    85     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     85    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    8686      double scale;
    8787      GetParameterValues(p, out scale);
     
    9898    }
    9999
    100     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double scale, IEnumerable<int> columnIndices) {
     100    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double scale, int[] columnIndices) {
    101101      yield return 2.0 * scale;
    102102    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinear.cs

    r12012 r13721  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Common;
     
    5251    }
    5352
    54     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     53    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    5554      if (p.Length > 0) throw new ArgumentException("No parameters are allowed for the linear covariance function.");
    5655      // create functions
    5756      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);
     57      cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, columnIndices, 1.0);
     58      cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, columnIndices, 1.0);
    6059      cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
    6160      return cov;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs

    r12012 r13721  
    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);
     
    9696    }
    9797
    98     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, IEnumerable<int> columnIndices) {
     98    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, int[] columnIndices) {
    9999      int k = 0;
    100       foreach (int columnIndex in columnIndices) {
     100      for (int c = 0; c < columnIndices.Length; c++) {
     101        var columnIndex = columnIndices[c];
    101102        yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k];
    102103        k++;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMask.cs

    r12012 r13721  
    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  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMaternIso.cs

    r12012 r13721  
    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      };
     
    156156
    157157
    158     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, IEnumerable<int> columnIndices,
     158    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, int[] columnIndices,
    159159      bool fixedInverseLength, bool fixedScale) {
    160160      double dist = i == j
    161161                   ? 0.0
    162                    : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
     162                   : Math.Sqrt(Util.SqrDist(x, i, j, columnIndices, Math.Sqrt(d) * inverseLength));
    163163
    164164      if (!fixedInverseLength) yield return scale * dm(d, dist);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNeuralNetwork.cs

    r12012 r13721  
    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 IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int[] columnIndices,
    141143      bool fixedLength, bool fixedScale) {
    142144      {
     
    144146        double s1 = 1.0;
    145147        double s2 = 1.0;
    146         foreach (var col in columnIndices) {
     148        for (int c = 0; c < columnIndices.Length; c++) {
     149          var col = columnIndices[c];
    147150          sx += x[i, col] * x[j, col];
    148151          s1 += x[i, col] * x[i, col];
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNoise.cs

    r12012 r13721  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Common;
     
    8483    }
    8584
    86     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     85    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    8786      double scale;
    8887      GetParameterValues(p, out scale);
     
    9190      var cov = new ParameterizedCovarianceFunction();
    9291      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;
     92      cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, columnIndices, 1.0) < 1e-9 ? scale : 0.0;
    9493      if (fixedScale)
    9594        cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs

    r12012 r13721  
    117117    }
    118118
    119     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     119    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[]columnIndices) {
    120120      double inverseLength, period, scale;
    121121      GetParameterValues(p, out scale, out period, out inverseLength);
     
    146146
    147147
    148     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double period, double inverseLength,
     148    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double period, double inverseLength,
    149149      bool fixedInverseLength, bool fixedPeriod, bool fixedScale) {
    150150      double k = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period;
     
    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  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePiecewisePolynomial.cs

    r12012 r13721  
    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 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, int[] columnIndices,
    162162      bool fixedLength, bool fixedScale) {
    163       double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));
     163      double k = Math.Sqrt(Util.SqrDist(x, i, x, j, columnIndices, 1.0 / length));
    164164      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));
    165165      if (!fixedScale) yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePolynomial.cs

    r12012 r13721  
    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 IEnumerable<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);
     125      double s = Util.ScalarProd(x, i, j, columnIndices, 1.0);
    127126      if (!fixedConst) yield return c * degree * scale * Math.Pow(c + s, degree - 1);
    128127      if (!fixedScale) yield return 2 * scale * Math.Pow(c + s, degree);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceProduct.cs

    r12012 r13721  
    7676    }
    7777
    78     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     78    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    7979      if (factors.Count == 0) throw new ArgumentException("at least one factor is necessary for the product covariance function.");
    8080      var functions = new List<ParameterizedCovarianceFunction>();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs

    r12012 r13721  
    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 IEnumerable<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
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs

    r12012 r13721  
    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 IEnumerable<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;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceScale.cs

    r12012 r13721  
    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 IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, ParameterizedCovarianceFunction cov,
    103103      bool fixedScale) {
    104104      if (!fixedScale) {
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSpectralMixture.cs

    r12012 r13721  
    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 IEnumerable<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();
     
    193193          int idx = 0; // helper index for tau
    194194          // 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]);
     195          for (int c = 0; c < columnIndices.Length; c++) {
     196            var col = columnIndices[c];
     197            k *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]);
    197198            idx++;
    198199          }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs

    r12012 r13721  
    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 IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double[] inverseLength,
    125125      bool fixedInverseLength, bool fixedScale) {
    126126      double d = i == j
     
    130130      int k = 0;
    131131      if (!fixedInverseLength) {
    132         foreach (var columnIndex in columnIndices) {
     132        for (int c = 0; c < columnIndices.Length; c++) {
     133          var columnIndex = columnIndices[c];
    133134          double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
    134135          yield return scale * Math.Exp(-d / 2.0) * sqrDist;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs

    r12012 r13721  
    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 IEnumerable<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);
    135134      if (!fixedInverseLength) yield return sf2 * g * d;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSum.cs

    r12012 r13721  
    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>();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r13160 r13721  
    167167      try {
    168168        CalculateModel(ds, rows, scaleInputs);
    169       } catch (alglib.alglibexception ae) {
     169      }
     170      catch (alglib.alglibexception ae) {
    170171        // wrap exception so that calling code doesn't have to know about alglib implementation
    171172        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    185186      int n = x.GetLength(0);
    186187
     188      var columns = Enumerable.Range(0, x.GetLength(1)).ToArray();
    187189      // calculate cholesky decomposed (lower triangular) covariance matrix
    188       var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
     190      var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    189191      this.l = CalculateL(x, cov, sqrSigmaNoise);
    190192
    191193      // calculate mean
    192       var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, x.GetLength(1)));
     194      var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    193195      double[] m = Enumerable.Range(0, x.GetLength(0))
    194196        .Select(r => mean.Mean(x, r))
     
    227229      double[] meanGradients = new double[meanFunction.GetNumberOfParameters(nAllowedVariables)];
    228230      for (int k = 0; k < meanGradients.Length; k++) {
    229         var meanGrad = Enumerable.Range(0, alpha.Length)
    230         .Select(r => mean.Gradient(x, r, k));
     231        var meanGrad = new double[alpha.Length];
     232        for (int g = 0; g < meanGrad.Length; g++)
     233          meanGrad[g] = mean.Gradient(x, g, k);
    231234        meanGradients[k] = -Util.ScalarProd(meanGrad, alpha);
    232235      }
     
    320323        int newN = newX.GetLength(0);
    321324
    322         var Ks = new double[newN, n];
    323         var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, newX.GetLength(1)));
     325        var Ks = new double[newN][];
     326        var columns = Enumerable.Range(0, newX.GetLength(1)).ToArray();
     327        var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    324328        var ms = Enumerable.Range(0, newX.GetLength(0))
    325329        .Select(r => mean.Mean(newX, r))
    326330        .ToArray();
    327         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, newX.GetLength(1)));
     331        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    328332        for (int i = 0; i < newN; i++) {
     333          Ks[i] = new double[n];
    329334          for (int j = 0; j < n; j++) {
    330             Ks[i, j] = cov.CrossCovariance(x, newX, j, i);
     335            Ks[i][j] = cov.CrossCovariance(x, newX, j, i);
    331336          }
    332337        }
    333338
    334339        return Enumerable.Range(0, newN)
    335           .Select(i => ms[i] + Util.ScalarProd(Util.GetRow(Ks, i), alpha));
    336       } catch (alglib.alglibexception ae) {
     340          .Select(i => ms[i] + Util.ScalarProd(Ks[i], alpha));
     341      }
     342      catch (alglib.alglibexception ae) {
    337343        // wrap exception so that calling code doesn't have to know about alglib implementation
    338344        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    352358        var kss = new double[newN];
    353359        double[,] sWKs = new double[n, newN];
    354         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
     360        var columns = Enumerable.Range(0, newX.GetLength(1)).ToArray();
     361        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    355362
    356363        if (l == null) {
     
    372379
    373380        for (int i = 0; i < newN; i++) {
    374           var sumV = Util.ScalarProd(Util.GetCol(sWKs, i), Util.GetCol(sWKs, i));
     381          var col = Util.GetCol(sWKs, i).ToArray();
     382          var sumV = Util.ScalarProd(col, col);
    375383          kss[i] += sqrSigmaNoise; // kss is V(f), add noise variance of predictive distibution to get V(y)
    376384          kss[i] -= sumV;
     
    378386        }
    379387        return kss;
    380       } catch (alglib.alglibexception ae) {
     388      }
     389      catch (alglib.alglibexception ae) {
    381390        // wrap exception so that calling code doesn't have to know about alglib implementation
    382391        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/ICovarianceFunction.cs

    r12012 r13721  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq.Expressions;
    2523using HeuristicLab.Core;
    2624
     
    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}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/IMeanFunction.cs

    r12012 r13721  
    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}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanConst.cs

    r12012 r13721  
    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);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanLinear.cs

    r12012 r13721  
    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) => {
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanModel.cs

    r13136 r13721  
    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
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanProduct.cs

    r12012 r13721  
    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);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanSum.cs

    r12012 r13721  
    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);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanZero.cs

    r12012 r13721  
    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();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/StudentTProcessModel.cs

    r13438 r13721  
    171171      try {
    172172        CalculateModel(ds, rows, scaleInputs);
    173       } catch (alglib.alglibexception ae) {
     173      }
     174      catch (alglib.alglibexception ae) {
    174175        // wrap exception so that calling code doesn't have to know about alglib implementation
    175176        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    188189
    189190      int n = x.GetLength(0);
     191      var columns = Enumerable.Range(0, x.GetLength(1)).ToArray();
    190192
    191193      // calculate cholesky decomposed (lower triangular) covariance matrix
    192       var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
     194      var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    193195      this.l = CalculateL(x, cov);
    194196
    195197      // calculate mean
    196       var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, x.GetLength(1)));
     198      var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    197199      double[] m = Enumerable.Range(0, x.GetLength(0))
    198200        .Select(r => mean.Mean(x, r))
     
    240242      double[] meanGradients = new double[meanFunction.GetNumberOfParameters(nAllowedVariables)];
    241243      for (int k = 0; k < meanGradients.Length; k++) {
    242         var meanGrad = Enumerable.Range(0, alpha.Length)
    243         .Select(r => mean.Gradient(x, r, k));
    244         meanGradients[k] = -Util.ScalarProd(meanGrad, alpha); //TODO not working yet, try to fix with gradient check
     244        var meanGrad = new double[alpha.Length];
     245        for (int g = 0; g < meanGrad.Length; g++)
     246          meanGrad[g] = mean.Gradient(x, g, k);
     247        meanGradients[k] = -Util.ScalarProd(meanGrad, alpha);//TODO not working yet, try to fix with gradient check
    245248      }
    246249
     
    336339        double[,] newX = GetData(dataset, allowedInputVariables, rows, inputScaling);
    337340        int newN = newX.GetLength(0);
    338 
    339         var Ks = new double[newN, n];
    340         var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, Enumerable.Range(0, newX.GetLength(1)));
     341        var columns = Enumerable.Range(0, newX.GetLength(1)).ToArray();
     342
     343        var Ks = new double[newN][];
     344        var mean = meanFunction.GetParameterizedMeanFunction(meanParameter, columns);
    341345        var ms = Enumerable.Range(0, newX.GetLength(0))
    342346        .Select(r => mean.Mean(newX, r))
    343347        .ToArray();
    344         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, newX.GetLength(1)));
     348        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, columns);
    345349        for (int i = 0; i < newN; i++) {
     350          Ks[i] = new double[n];
    346351          for (int j = 0; j < n; j++) {
    347             Ks[i, j] = cov.CrossCovariance(x, newX, j, i);
     352            Ks[i][j] = cov.CrossCovariance(x, newX, j, i);
    348353          }
    349354        }
    350355
    351356        return Enumerable.Range(0, newN)
    352           .Select(i => ms[i] + Util.ScalarProd(Util.GetRow(Ks, i), alpha));
    353       } catch (alglib.alglibexception ae) {
     357          .Select(i => ms[i] + Util.ScalarProd(Ks[i], alpha));
     358      }
     359      catch (alglib.alglibexception ae) {
    354360        // wrap exception so that calling code doesn't have to know about alglib implementation
    355361        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    369375        var kss = new double[newN];
    370376        double[,] sWKs = new double[n, newN];
    371         var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)));
    372        
     377        var cov = covarianceFunction.GetParameterizedCovarianceFunction(covarianceParameter, Enumerable.Range(0, x.GetLength(1)).ToArray());
     378
    373379        if (l == null) {
    374380          l = CalculateL(x, cov);
    375381        }
    376        
     382
    377383        // for stddev
    378384        for (int i = 0; i < newN; i++)
    379385          kss[i] = cov.Covariance(newX, i, i);
    380        
     386
    381387        for (int i = 0; i < newN; i++) {
    382388          for (int j = 0; j < n; j++) {
    383             sWKs[j, i] = cov.CrossCovariance(x, newX, j, i) ;
     389            sWKs[j, i] = cov.CrossCovariance(x, newX, j, i);
    384390          }
    385391        }
    386        
     392
    387393        // for stddev
    388394        alglib.ablas.rmatrixlefttrsm(n, newN, l, 0, 0, false, false, 0, ref sWKs, 0, 0);
    389        
     395
    390396        for (int i = 0; i < newN; i++) {
    391           var sumV = Util.ScalarProd(Util.GetCol(sWKs, i), Util.GetCol(sWKs, i));
     397          var col = Util.GetCol(sWKs, i).ToArray();
     398          var sumV = Util.ScalarProd(col, col);
    392399          kss[i] -= sumV;
    393           kss[i] *= (nu + beta -2) / (nu + n - 2);
     400          kss[i] *= (nu + beta - 2) / (nu + n - 2);
    394401          if (kss[i] < 0) kss[i] = 0;
    395402        }
    396403        return kss;
    397       } catch (alglib.alglibexception ae) {
     404      }
     405      catch (alglib.alglibexception ae) {
    398406        // wrap exception so that calling code doesn't have to know about alglib implementation
    399407        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs

    r12012 r13721  
    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
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessFunctionsTest.cs

    r12012 r13721  
    17471747      int rows1 = xt.GetLength(0);
    17481748      var actualCov = new double[rows0, rows1];
    1749       var covFunction = cf.GetParameterizedCovarianceFunction(hyp, Enumerable.Range(0, x.GetLength(1)));
     1749      var covFunction = cf.GetParameterizedCovarianceFunction(hyp, Enumerable.Range(0, x.GetLength(1)).ToArray());
    17501750      for (int i = 0; i < rows0; i++)
    17511751        for (int j = 0; j < rows1; j++)
     
    17691769      int nHyp = mf.GetNumberOfParameters(x.GetLength(1));
    17701770      var hyp = Enumerable.Repeat(hypValue, nHyp).ToArray();
    1771       var meanFunction = mf.GetParameterizedMeanFunction(hyp, Enumerable.Range(0, x.GetLength(1)));
     1771      var meanFunction = mf.GetParameterizedMeanFunction(hyp, Enumerable.Range(0, x.GetLength(1)).ToArray());
    17721772
    17731773      var m = Enumerable.Range(0, xt.GetLength(0)).Select(i => meanFunction.Mean(xt, i)).ToArray();
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs

    r12012 r13721  
    5050      var alg = new GaussianProcessRegression();
    5151      alg.Engine = new HeuristicLab.SequentialEngine.SequentialEngine();
     52      alg.SetSeedRandomly = false;
    5253
    5354      alg.Problem = new RegressionProblem();
Note: See TracChangeset for help on using the changeset viewer.