Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/04/14 11:30:58 (11 years ago)
Author:
gkronber
Message:

#2125: merged r10489:10491 and r10493 from trunk into stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs

    r9456 r10530  
    4444      get { return (IValueParameter<DoubleValue>)Parameters["Shape"]; }
    4545    }
     46
     47    private bool HasFixedScaleParameter {
     48      get { return ScaleParameter.Value != null; }
     49    }
     50    private bool HasFixedInverseLengthParameter {
     51      get { return InverseLengthParameter.Value != null; }
     52    }
     53    private bool HasFixedShapeParameter {
     54      get { return ShapeParameter.Value != null; }
     55    }
     56
     57
    4658    [StorableConstructor]
    4759    private CovarianceRationalQuadraticIso(bool deserializing)
     
    6880
    6981    public int GetNumberOfParameters(int numberOfVariables) {
    70       return (ScaleParameter.Value != null ? 0 : 1) +
    71         (ShapeParameter.Value != null ? 0 : 1) +
    72         (InverseLengthParameter.Value != null ? 0 : 1);
     82      return (HasFixedScaleParameter ? 0 : 1) +
     83        (HasFixedShapeParameter ? 0 : 1) +
     84        (HasFixedInverseLengthParameter ? 0 : 1);
    7385    }
    7486
     
    8496      int c = 0;
    8597      // gather parameter values
    86       if (InverseLengthParameter.Value != null) {
     98      if (HasFixedInverseLengthParameter) {
    8799        inverseLength = InverseLengthParameter.Value.Value;
    88100      } else {
     
    90102        c++;
    91103      }
    92       if (ScaleParameter.Value != null) {
     104      if (HasFixedScaleParameter) {
    93105        scale = ScaleParameter.Value.Value;
    94106      } else {
     
    96108        c++;
    97109      }
    98       if (ShapeParameter.Value != null) {
     110      if (HasFixedShapeParameter) {
    99111        shape = ShapeParameter.Value.Value;
    100112      } else {
     
    108120      double scale, shape, inverseLength;
    109121      GetParameterValues(p, out scale, out shape, out inverseLength);
     122      var fixedInverseLength = HasFixedInverseLengthParameter;
     123      var fixedScale = HasFixedScaleParameter;
     124      var fixedShape = HasFixedShapeParameter;
    110125      // create functions
    111126      var cov = new ParameterizedCovarianceFunction();
     
    120135        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    121136      };
    122       cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength);
     137      cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength, fixedInverseLength, fixedScale, fixedShape);
    123138      return cov;
    124139    }
    125140
    126     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double inverseLength) {
     141    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double shape, double inverseLength,
     142      bool fixedInverseLength, bool fixedScale, bool fixedShape) {
    127143      double d = i == j
    128144                   ? 0.0
     
    130146
    131147      double b = 1 + 0.5 * d / shape;
    132       yield return scale * Math.Pow(b, -shape - 1) * d;
    133       yield return 2 * scale * Math.Pow(b, -shape);
    134       yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
     148      if (!fixedInverseLength) yield return scale * Math.Pow(b, -shape - 1) * d;
     149      if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape);
     150      if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));
    135151    }
    136152  }
Note: See TracChangeset for help on using the changeset viewer.