Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/29/17 17:35:55 (7 years ago)
Author:
gkronber
Message:

#2782: implemented calculation of LOO predictive probability for Gaussian process regression

File:
1 edited

Legend:

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

    r14854 r14899  
    4646
    4747    [Storable]
     48    private double negativeLooPredictiveProbability;
     49    public double NegativeLooPredictiveProbability {
     50      get { return negativeLooPredictiveProbability; }
     51    }
     52
     53    [Storable]
    4854    private double[] hyperparameterGradients;
    4955    public double[] HyperparameterGradients {
     
    128134      this.trainingDataset = cloner.Clone(original.trainingDataset);
    129135      this.negativeLogLikelihood = original.negativeLogLikelihood;
     136      this.negativeLooPredictiveProbability = original.negativeLooPredictiveProbability;
    130137      this.sqrSigmaNoise = original.sqrSigmaNoise;
    131138      if (original.meanParameter != null) {
     
    217224      alglib.spdmatrixcholeskyinverse(ref lCopy, n, false, out info, out matInvRep);
    218225      if (info != 1) throw new ArgumentException("Can't invert matrix to calculate gradients.");
     226
     227      // LOOCV log predictive probability (GPML page 116 and 117)
     228      var sumLoo = 0.0;
     229      var ki = new double[n];
     230      for (int i = 0; i < n; i++) {
     231        for (int j = 0; j < n; j++) ki[j] = cov.Covariance(x, i, j);
     232        var yi = Util.ScalarProd(ki, alpha);
     233        // r = [inv(K)]_i,i
     234        var yi_loo = yi - alpha[i] / lCopy[i, i] / sqrSigmaNoise;
     235        var s2_loo = sqrSigmaNoise / lCopy[i, i];
     236        var err = ym[i] - yi_loo;
     237        var nll_loo = Math.Log(s2_loo) + err * err / s2_loo;
     238        sumLoo += nll_loo;
     239      }
     240      sumLoo += n * Math.Log(2 * Math.PI);
     241      negativeLooPredictiveProbability = 0.5 * sumLoo;
     242
    219243      for (int i = 0; i < n; i++) {
    220244        for (int j = 0; j <= i; j++)
Note: See TracChangeset for help on using the changeset viewer.