Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15188


Ignore:
Timestamp:
07/10/17 19:19:26 (7 years ago)
Author:
gkronber
Message:

#2782: merged r14899,r14918,r15160,r15163,r15165,r15187 from trunk to stable

Location:
stable
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r15143 r15188  
    4646
    4747    [Storable]
     48    private double loocvNegLogPseudoLikelihood;
     49    public double LooCvNegativeLogPseudoLikelihood {
     50      get { return loocvNegLogPseudoLikelihood; }
     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.loocvNegLogPseudoLikelihood = original.loocvNegLogPseudoLikelihood;
    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 pseudo-likelihood (or 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        ki[i] += sqrSigmaNoise;
     233
     234        var yi = Util.ScalarProd(ki, alpha);
     235        var yi_loo = yi - alpha[i] / (lCopy[i, i] / sqrSigmaNoise);
     236        var s2_loo = 1.0 / (lCopy[i, i] / sqrSigmaNoise);
     237        var err = ym[i] - yi_loo;
     238        var nll_loo = 0.5 * Math.Log(2 * Math.PI * s2_loo) + 0.5 * err * err / s2_loo;
     239        sumLoo += nll_loo;
     240      }
     241      loocvNegLogPseudoLikelihood = sumLoo;
     242
    219243      for (int i = 0; i < n; i++) {
    220244        for (int j = 0; j <= i; j++)
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs

    r14186 r15188  
    3737    private const string ModelParameterName = "Model";
    3838    private const string NegativeLogLikelihoodParameterName = "NegativeLogLikelihood";
     39    private const string NegativeLogPseudoLikelihoodParameterName = "NegativeLogPseudoLikelihood (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> NegativeLogPseudoLikelihoodParameter {
     65      get { return (ILookupParameter<DoubleValue>)Parameters[NegativeLogPseudoLikelihoodParameterName]; }
    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>(NegativeLogPseudoLikelihoodParameterName, "The leave-one-out-cross-validation negative log pseudo-likelihood of the produced Gaussian process model given the data."));
    8893
    8994
     
    100105        Parameters[ScaleInputValuesParameterName].Hidden = true;
    101106      }
     107      if (!Parameters.ContainsKey(NegativeLogPseudoLikelihoodParameterName)) {
     108        Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogPseudoLikelihoodParameterName,
     109          "The leave-one-out-cross-validation negative log pseudo-likelihood of the produced Gaussian process model given the data."));
     110      }
    102111    }
    103112  }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs

    r14186 r15188  
    6565        ModelParameter.ActualValue = model;
    6666        NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood);
     67        NegativeLogPseudoLikelihoodParameter.ActualValue = new DoubleValue(model.LooCvNegativeLogPseudoLikelihood);
    6768        HyperparameterGradientsParameter.ActualValue = new RealVector(model.HyperparameterGradients);
    6869        return base.Apply();
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionSolutionCreator.cs

    r14186 r15188  
    4141    private const string TestRSquaredResultName = "Test R²";
    4242    private const string CreateSolutionParameterName = "CreateSolution";
     43    private const string NegLogPseudoLikelihood = "Negative log pseudo-likelihood (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(NegLogPseudoLikelihood,
     112                                 "The negative log pseudo-likelihood (from leave-one-out-cross-validation).",
     113                                 new DoubleValue(m.LooCvNegativeLogPseudoLikelihood)));
    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[NegLogPseudoLikelihood].Value = new DoubleValue(m.LooCvNegativeLogPseudoLikelihood);
    114119        }
    115120      }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModel.cs

    r14186 r15188  
    2828  public interface IGaussianProcessModel : IConfidenceRegressionModel {
    2929    double NegativeLogLikelihood { get; }
     30    double LooCvNegativeLogPseudoLikelihood { get; }
    3031    double SigmaNoise { get; }
    3132    IMeanFunction MeanFunction { get; }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Interfaces/IGaussianProcessModelCreator.cs

    r14186 r15188  
    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> NegativeLogPseudoLikelihoodParameter { get; }
    3838  }
    3939}
Note: See TracChangeset for help on using the changeset viewer.