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/CovariancePiecewisePolynomial.cs

    r9543 r10489  
    4545      get { return (IConstrainedValueParameter<IntValue>)Parameters["V"]; }
    4646    }
     47    private bool HasFixedLengthParameter {
     48      get { return LengthParameter.Value != null; }
     49    }
     50    private bool HasFixedScaleParameter {
     51      get { return ScaleParameter.Value != null; }
     52    }
    4753
    4854    [StorableConstructor]
     
    7783    public int GetNumberOfParameters(int numberOfVariables) {
    7884      return
    79         (LengthParameter.Value != null ? 0 : 1) +
    80         (ScaleParameter.Value != null ? 0 : 1);
     85        (HasFixedLengthParameter ? 0 : 1) +
     86        (HasFixedScaleParameter ? 0 : 1);
    8187    }
    8288
     
    9197      // gather parameter values
    9298      int n = 0;
    93       if (LengthParameter.Value != null) {
     99      if (HasFixedLengthParameter) {
    94100        length = LengthParameter.Value.Value;
    95101      } else {
     
    98104      }
    99105
    100       if (ScaleParameter.Value != null) {
     106      if (HasFixedScaleParameter) {
    101107        scale = ScaleParameter.Value.Value;
    102108      } else {
     
    111117      int v = VParameter.Value.Value;
    112118      GetParameterValues(p, out length, out scale);
     119      var fixedLength = HasFixedLengthParameter;
     120      var fixedScale = HasFixedScaleParameter;
    113121      int exp = (int)Math.Floor(columnIndices.Count() / 2.0) + v + 1;
    114122
     
    147155        return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
    148156      };
    149       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, length, scale, v, exp, f, df, columnIndices);
     157      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, length, scale, v, exp, f, df, columnIndices, fixedLength, fixedScale);
    150158      return cov;
    151159    }
    152160
    153     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, IEnumerable<int> columnIndices) {
     161    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, IEnumerable<int> columnIndices,
     162      bool fixedLength, bool fixedScale) {
    154163      double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));
    155       yield return scale * Math.Pow(Math.Max(1.0 - k, 0), exp + v - 1) * k * ((exp + v) * f(k) - Math.Max(1 - k, 0) * df(k));
    156       yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
     164      if (!fixedLength) yield return scale * Math.Pow(Math.Max(1.0 - k, 0), exp + v - 1) * k * ((exp + v) * f(k) - Math.Max(1 - k, 0) * df(k));
     165      if (!fixedScale) yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);
    157166    }
    158167  }
Note: See TracChangeset for help on using the changeset viewer.