Ignore:
Timestamp:
04/22/16 13:47:35 (5 years ago)
Author:
pfleck
Message:

#2591 Made the creation of a GaussianProcessModel faster by avoiding additional iterators during calculation of the hyperparameter gradients.
The gradients of the hyperparameters are now calculated in one sweep and returned as IList, instead of returning an iterator (with yield return).
This avoids a large amount of Move-calls of the iterator, especially for covariance functions with a lot of hyperparameters.
Besides, the signature of the CovarianceGradientFunctionDelegate is changed, to return an IList instead of an IEnumerable to avoid unnececary ToList or ToArray calls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs

    r13721 r13784  
    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, int[] columnIndices) {
     98    private static IList<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, int[] columnIndices) {
    9999      int k = 0;
     100      var g = new List<double>(columnIndices.Length);
    100101      for (int c = 0; c < columnIndices.Length; c++) {
    101102        var columnIndex = columnIndices[c];
    102         yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k];
     103        g.Add(-2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k]);
    103104        k++;
    104105      }
     106      return g;
    105107    }
    106108  }
Note: See TracChangeset for help on using the changeset viewer.