Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/16 16:19:04 (9 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/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • 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>();
Note: See TracChangeset for help on using the changeset viewer.