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

    r13721 r13784  
    126126
    127127    // order of returned gradients must match the order in GetParameterValues!
    128     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, int[] columnIndices,
     128    private static IList<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, int[] columnIndices,
    129129      bool fixedInverseLength, bool fixedScale) {
    130130      double d = i == j
     
    132132                   : Util.SqrDist(x, i, j, columnIndices, inverseLength);
    133133      double g = Math.Exp(-d / 2.0);
    134       if (!fixedInverseLength) yield return sf2 * g * d;
    135       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;
    136138    }
    137139  }
Note: See TracChangeset for help on using the changeset viewer.