Changeset 14899
- Timestamp:
- 04/29/17 17:35:55 (8 years ago)
- 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 46 46 47 47 [Storable] 48 private double negativeLooPredictiveProbability; 49 public double NegativeLooPredictiveProbability { 50 get { return negativeLooPredictiveProbability; } 51 } 52 53 [Storable] 48 54 private double[] hyperparameterGradients; 49 55 public double[] HyperparameterGradients { … … 128 134 this.trainingDataset = cloner.Clone(original.trainingDataset); 129 135 this.negativeLogLikelihood = original.negativeLogLikelihood; 136 this.negativeLooPredictiveProbability = original.negativeLooPredictiveProbability; 130 137 this.sqrSigmaNoise = original.sqrSigmaNoise; 131 138 if (original.meanParameter != null) { … … 217 224 alglib.spdmatrixcholeskyinverse(ref lCopy, n, false, out info, out matInvRep); 218 225 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 219 243 for (int i = 0; i < n; i++) { 220 244 for (int j = 0; j <= i; j++) -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs
r14185 r14899 37 37 private const string ModelParameterName = "Model"; 38 38 private const string NegativeLogLikelihoodParameterName = "NegativeLogLikelihood"; 39 private const string NegativeLogPredictiveProbabilityParameterName = "NegativeLogPredictiveProbability (LOOCV)"; 39 40 private const string HyperparameterGradientsParameterName = "HyperparameterGradients"; 40 41 protected const string ScaleInputValuesParameterName = "ScaleInputValues"; … … 60 61 public ILookupParameter<DoubleValue> NegativeLogLikelihoodParameter { 61 62 get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogLikelihoodParameterName]; } 63 } 64 public ILookupParameter<DoubleValue> NegativeLogPredictiveProbabilityParameter { 65 get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogPredictiveProbabilityParameterName]; } 62 66 } 63 67 public ILookupParameter<BoolValue> ScaleInputValuesParameter { … … 86 90 Parameters.Add(new LookupParameter<RealVector>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)")); 87 91 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.")); 88 93 89 94 … … 100 105 Parameters[ScaleInputValuesParameterName].Hidden = true; 101 106 } 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 } 102 111 } 103 112 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs
r14185 r14899 65 65 ModelParameter.ActualValue = model; 66 66 NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood); 67 NegativeLogPredictiveProbabilityParameter.ActualValue = new DoubleValue(model.NegativeLooPredictiveProbability); 67 68 HyperparameterGradientsParameter.ActualValue = new RealVector(model.HyperparameterGradients); 68 69 return base.Apply(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionSolutionCreator.cs
r14185 r14899 41 41 private const string TestRSquaredResultName = "Test R²"; 42 42 private const string CreateSolutionParameterName = "CreateSolution"; 43 private const string NegLogPredictiveProbability = "NegativeLogPredictiveProbability (LOO-CV)"; 43 44 44 45 #region Parameter Properties … … 108 109 "The Pearson's R² of the Gaussian process solution on the test partition.", 109 110 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))); 110 114 } else { 111 115 results[SolutionParameterName].Value = s; 112 116 results[TrainingRSquaredResultName].Value = new DoubleValue(s.TrainingRSquared); 113 117 results[TestRSquaredResultName].Value = new DoubleValue(s.TestRSquared); 118 results[NegLogPredictiveProbability].Value = new DoubleValue(m.NegativeLooPredictiveProbability); 114 119 } 115 120 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModel.cs
r14185 r14899 28 28 public interface IGaussianProcessModel : IConfidenceRegressionModel { 29 29 double NegativeLogLikelihood { get; } 30 double NegativeLooPredictiveProbability { get; } 30 31 double SigmaNoise { get; } 31 32 IMeanFunction MeanFunction { get; } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModelCreator.cs
r14185 r14899 23 23 using HeuristicLab.Data; 24 24 using HeuristicLab.Encodings.RealVectorEncoding; 25 using HeuristicLab.Problems.DataAnalysis;26 25 27 26 namespace HeuristicLab.Algorithms.DataAnalysis { … … 36 35 ILookupParameter<RealVector> HyperparameterGradientsParameter { get; } 37 36 ILookupParameter<DoubleValue> NegativeLogLikelihoodParameter { get; } 37 ILookupParameter<DoubleValue> NegativeLogPredictiveProbabilityParameter { get; } 38 38 } 39 39 }
Note: See TracChangeset
for help on using the changeset viewer.