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

    r9456 r10489  
    4242    }
    4343
     44    private bool HasFixedInverseLengthParameter {
     45      get { return InverseLengthParameter.Value != null; }
     46    }
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50
    4451    [StorableConstructor]
    4552    private CovarianceSquaredExponentialIso(bool deserializing)
     
    6673    public int GetNumberOfParameters(int numberOfVariables) {
    6774      return
    68         (ScaleParameter.Value != null ? 0 : 1) +
    69         (InverseLengthParameter.Value != null ? 0 : 1);
     75        (HasFixedScaleParameter ? 0 : 1) +
     76        (HasFixedInverseLengthParameter ? 0 : 1);
    7077    }
    7178
     
    8188      // gather parameter values
    8289      int c = 0;
    83       if (InverseLengthParameter.Value != null) {
     90      if (HasFixedInverseLengthParameter) {
    8491        inverseLength = InverseLengthParameter.Value.Value;
    8592      } else {
     
    8895      }
    8996
    90       if (ScaleParameter.Value != null) {
     97      if (HasFixedScaleParameter) {
    9198        scale = ScaleParameter.Value.Value;
    9299      } else {
     
    100107      double inverseLength, scale;
    101108      GetParameterValues(p, out scale, out inverseLength);
     109      var fixedInverseLength = HasFixedInverseLengthParameter;
     110      var fixedScale = HasFixedScaleParameter;
    102111      // create functions
    103112      var cov = new ParameterizedCovarianceFunction();
     
    112121        return scale * Math.Exp(-d / 2.0);
    113122      };
    114       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices);
     123      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices,
     124        fixedInverseLength, fixedScale);
    115125      return cov;
    116126    }
    117127
    118128    // order of returned gradients must match the order in GetParameterValues!
    119     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices) {
     129    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices,
     130      bool fixedInverseLength, bool fixedScale) {
    120131      double d = i == j
    121132                   ? 0.0
    122133                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    123134      double g = Math.Exp(-d / 2.0);
    124       yield return sf2 * g * d;
    125       yield return 2.0 * sf2 * g;
     135      if (!fixedInverseLength) yield return sf2 * g * d;
     136      if (!fixedScale) yield return 2.0 * sf2 * g;
    126137    }
    127138  }
Note: See TracChangeset for help on using the changeset viewer.