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/CovarianceRationalQuadraticIso.cs

    r13721 r13784  
    139139    }
    140140
    141     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, 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
     
    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  }
Note: See TracChangeset for help on using the changeset viewer.