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

    r13721 r13784  
    100100    }
    101101
    102     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, ParameterizedCovarianceFunction cov,
     102    private static IList<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, ParameterizedCovarianceFunction cov,
    103103      bool fixedScale) {
     104      var gr = new List<double>((!fixedScale ? 1 : 0) + cov.CovarianceGradient(x, i, j).Count);
    104105      if (!fixedScale) {
    105         yield return 2 * scale * cov.Covariance(x, i, j);
     106        gr.Add(2 * scale * cov.Covariance(x, i, j));
    106107      }
    107108      foreach (var g in cov.CovarianceGradient(x, i, j))
    108         yield return scale * g;
     109        gr.Add(scale * g);
     110      return gr;
    109111    }
    110112  }
Note: See TracChangeset for help on using the changeset viewer.