Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/14 17:30:38 (11 years ago)
Author:
mkommend
Message:

#1998: Updated classification model comparision branch with trunk changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs

    r8982 r10553  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    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 (ScaleParameter.Value != null) {
     98      if (HasFixedInverseLengthParameter) {
     99        inverseLength = InverseLengthParameter.Value.Value;
     100      } else {
     101        inverseLength = 1.0 / Math.Exp(p[c]);
     102        c++;
     103      }
     104      if (HasFixedScaleParameter) {
    87105        scale = ScaleParameter.Value.Value;
    88106      } else {
     
    90108        c++;
    91109      }
    92       if (ShapeParameter.Value != null) {
     110      if (HasFixedShapeParameter) {
    93111        shape = ShapeParameter.Value.Value;
    94112      } else {
    95113        shape = Math.Exp(p[c]);
    96         c++;
    97       }
    98       if (InverseLengthParameter.Value != null) {
    99         inverseLength = InverseLengthParameter.Value.Value;
    100       } else {
    101         inverseLength = 1.0 / Math.Exp(p[c]);
    102114        c++;
    103115      }
     
    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();
     
    114129                    ? 0.0
    115130                    : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    116         return shape * Math.Pow(1 + 0.5 * d / shape, -shape);
     131        return scale * Math.Pow(1 + 0.5 * d / shape, -shape);
    117132      };
    118133      cov.CrossCovariance = (x, xt, i, j) => {
     
    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.