Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/14 17:30:38 (10 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/CovarianceSquaredExponentialIso.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.
     
    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
    118     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices) {
     128    // order of returned gradients must match the order in GetParameterValues!
     129    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices,
     130      bool fixedInverseLength, bool fixedScale) {
    119131      double d = i == j
    120132                   ? 0.0
    121133                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    122134      double g = Math.Exp(-d / 2.0);
    123       yield return sf2 * g * d;
    124       yield return 2.0 * sf2 * g;
     135      if (!fixedInverseLength) yield return sf2 * g * d;
     136      if (!fixedScale) yield return 2.0 * sf2 * g;
    125137    }
    126138  }
Note: See TracChangeset for help on using the changeset viewer.