Changeset 14899


Ignore:
Timestamp:
04/29/17 17:35:55 (3 months ago)
Author:
gkronber
Message:

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

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4
Files:
6 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++)
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs

    r14185 r14899  
    3737    private const string ModelParameterName = "Model";
    3838    private const string NegativeLogLikelihoodParameterName = "NegativeLogLikelihood";
     39    private const string NegativeLogPredictiveProbabilityParameterName = "NegativeLogPredictiveProbability (LOOCV)";
    3940    private const string HyperparameterGradientsParameterName = "HyperparameterGradients";
    4041    protected const string ScaleInputValuesParameterName = "ScaleInputValues";
     
    6061    public ILookupParameter<DoubleValue> NegativeLogLikelihoodParameter {
    6162      get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogLikelihoodParameterName]; }
     63    }
     64    public ILookupParameter<DoubleValue> NegativeLogPredictiveProbabilityParameter {
     65      get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogPredictiveProbabilityParameterName]; }
    6266    }
    6367    public ILookupParameter<BoolValue> ScaleInputValuesParameter {
     
    8690      Parameters.Add(new LookupParameter<RealVector>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)"));
    8791      Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogLikelihoodParameterName, "The negative log-likelihood of the produced Gaussian process model given the data."));
     92      Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogPredictiveProbabilityParameterName, "The leave-one-out-cross-validation negative log predictive probability of the produced Gaussian process model given the data."));
    8893
    8994
     
    100105        Parameters[ScaleInputValuesParameterName].Hidden = true;
    101106      }
     107      if (!Parameters.ContainsKey(NegativeLogPredictiveProbabilityParameterName)) {
     108        Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogPredictiveProbabilityParameterName,
     109          "The leave-one-out-cross-validation negative log predictive probability of the produced Gaussian process model given the data."));
     110      }
    102111    }
    103112  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs

    r14185 r14899  
    6565        ModelParameter.ActualValue = model;
    6666        NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood);
     67        NegativeLogPredictiveProbabilityParameter.ActualValue = new DoubleValue(model.NegativeLooPredictiveProbability);
    6768        HyperparameterGradientsParameter.ActualValue = new RealVector(model.HyperparameterGradients);
    6869        return base.Apply();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionSolutionCreator.cs

    r14185 r14899  
    4141    private const string TestRSquaredResultName = "Test R²";
    4242    private const string CreateSolutionParameterName = "CreateSolution";
     43    private const string NegLogPredictiveProbability = "NegativeLogPredictiveProbability (LOO-CV)";
    4344
    4445    #region Parameter Properties
     
    108109                                 "The Pearson's R² of the Gaussian process solution on the test partition.",
    109110                                 new DoubleValue(s.TestRSquared)));
     111          results.Add(new Result(NegLogPredictiveProbability,
     112                                 "The leave-one-out-cross-validation negative log predictive probability.",
     113                                 new DoubleValue(m.NegativeLooPredictiveProbability)));
    110114        } else {
    111115          results[SolutionParameterName].Value = s;
    112116          results[TrainingRSquaredResultName].Value = new DoubleValue(s.TrainingRSquared);
    113117          results[TestRSquaredResultName].Value = new DoubleValue(s.TestRSquared);
     118          results[NegLogPredictiveProbability].Value = new DoubleValue(m.NegativeLooPredictiveProbability);
    114119        }
    115120      }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModel.cs

    r14185 r14899  
    2828  public interface IGaussianProcessModel : IConfidenceRegressionModel {
    2929    double NegativeLogLikelihood { get; }
     30    double NegativeLooPredictiveProbability { get; }
    3031    double SigmaNoise { get; }
    3132    IMeanFunction MeanFunction { get; }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModelCreator.cs

    r14185 r14899  
    2323using HeuristicLab.Data;
    2424using HeuristicLab.Encodings.RealVectorEncoding;
    25 using HeuristicLab.Problems.DataAnalysis;
    2625
    2726namespace HeuristicLab.Algorithms.DataAnalysis {
     
    3635    ILookupParameter<RealVector> HyperparameterGradientsParameter { get; }
    3736    ILookupParameter<DoubleValue> NegativeLogLikelihoodParameter { get; }
     37    ILookupParameter<DoubleValue> NegativeLogPredictiveProbabilityParameter { get; }
    3838  }
    3939}
Note: See TracChangeset for help on using the changeset viewer.