Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/14 17:45:06 (10 years ago)
Author:
gkronber
Message:

#2125 fixed the bug that covariance functions returned the full gradient vector even when parameters are partially fixed.
changed the calculation of NN covariance and gradient to direct calculation (instead of AutoDiff)

File:
1 edited

Legend:

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

    r9535 r10489  
    4545      get { return (IValueParameter<IntValue>)Parameters["Degree"]; }
    4646    }
     47    private bool HasFixedConstParameter {
     48      get { return ConstParameter.Value != null; }
     49    }
     50    private bool HasFixedScaleParameter {
     51      get { return ScaleParameter.Value != null; }
     52    }
    4753
    4854    [StorableConstructor]
     
    7177    public int GetNumberOfParameters(int numberOfVariables) {
    7278      return
    73         (ConstParameter.Value != null ? 0 : 1) +
    74         (ScaleParameter.Value != null ? 0 : 1);
     79        (HasFixedConstParameter ? 0 : 1) +
     80        (HasFixedScaleParameter ? 0 : 1);
    7581    }
    7682
     
    8591      // gather parameter values
    8692      int n = 0;
    87       if (ConstParameter.Value != null) {
     93      if (HasFixedConstParameter) {
    8894        @const = ConstParameter.Value.Value;
    8995      } else {
     
    9298      }
    9399
    94       if (ScaleParameter.Value != null) {
     100      if (HasFixedScaleParameter) {
    95101        scale = ScaleParameter.Value.Value;
    96102      } else {
     
    106112      if (degree <= 0) throw new ArgumentException("The degree parameter for CovariancePolynomial must be greater than zero.");
    107113      GetParameterValues(p, out @const, out scale);
     114      var fixedConst = HasFixedConstParameter;
     115      var fixedScale = HasFixedScaleParameter;
    108116      // create functions
    109117      var cov = new ParameterizedCovarianceFunction();
    110118      cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, 1.0, columnIndices), degree);
    111119      cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, 1.0, columnIndices), degree);
    112       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, @const, scale, degree, columnIndices);
     120      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, @const, scale, degree, columnIndices, fixedConst, fixedScale);
    113121      return cov;
    114122    }
    115123
    116     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, IEnumerable<int> columnIndices) {
     124    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, IEnumerable<int> columnIndices,
     125      bool fixedConst, bool fixedScale) {
    117126      double s = Util.ScalarProd(x, i, j, 1.0, columnIndices);
    118       yield return c * degree * scale * Math.Pow(c + s, degree - 1);
    119       yield return 2 * scale * Math.Pow(c + s, degree);
     127      if (!fixedConst) yield return c * degree * scale * Math.Pow(c + s, degree - 1);
     128      if (!fixedScale) yield return 2 * scale * Math.Pow(c + s, degree);
    120129    }
    121130  }
Note: See TracChangeset for help on using the changeset viewer.