Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8933


Ignore:
Timestamp:
11/20/12 14:04:29 (11 years ago)
Author:
gkronber
Message:

#1902 corrected handling of length-parameter arrays in ARD functions and prevented stacking of mask covariance functions to make sure that the length-parameter and the enumerable of selected column indexes are equally long.

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs

    r8932 r8933  
    9999      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    100100
     101      int k = 0;
    101102      foreach (int columnIndex in columnIndices) {
    102         yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[columnIndex] * inverseLength[columnIndex];
     103        yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k];
     104        k++;
    103105      }
    104106    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMask.cs

    r8929 r8933  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    111112
    112113    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     114      // cov mask overwrites the previously selected columnIndices
     115      // -> stacking of CovarianceMask is not supported
     116      if (columnIndices != null && columnIndices.Count() != x.GetLength(1))
     117        throw new InvalidOperationException("Stacking of masking covariance functions is not supported.");
     118
    113119      return cov.GetCovariance(x, i, j, selectedDimensions);
    114120    }
    115121
    116122    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     123      if (columnIndices != null && columnIndices.Count() != x.GetLength(1))
     124        throw new InvalidOperationException("Stacking of masking covariance functions is not supported.");
     125
    117126      return cov.GetGradient(x, i, j, selectedDimensions);
    118127    }
    119128
    120129    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     130      if (columnIndices != null && columnIndices.Count() != x.GetLength(1))
     131        throw new InvalidOperationException("Stacking of masking covariance functions is not supported.");
     132
    121133      return cov.GetCrossCovariance(x, xt, i, j, selectedDimensions);
    122134    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs

    r8932 r8933  
    148148                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    149149      double b = 1 + 0.5 * d / shape;
     150      int k = 0;
    150151      foreach (var columnIndex in columnIndices) {
    151         yield return sf2 * Math.Pow(b, -shape - 1) * Util.SqrDist(x[i, columnIndex] * inverseLength[columnIndex], x[j, columnIndex] * inverseLength[columnIndex]);
     152        yield return sf2 * Math.Pow(b, -shape - 1) * Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
     153        k++;
    152154      }
    153155      yield return 2 * sf2 * Math.Pow(b, -shape);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs

    r8932 r8933  
    122122                   ? 0.0
    123123                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    124 
     124      int k = 0;
    125125      foreach (var columnIndex in columnIndices) {
    126         double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[columnIndex], x[j, columnIndex] * inverseLength[columnIndex]);
     126        double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]);
    127127        yield return sf2 * Math.Exp(-d / 2.0) * sqrDist;
     128        k++;
    128129      }
    129130
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs

    r8827 r8933  
    4848      double ss = 0.0;
    4949      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    50       foreach (int k in columnIndices) {
    51         double d = x[i, k] - xt[j, k];
     50      foreach (int columnIndex in columnIndices) {
     51        double d = x[i, columnIndex] - xt[j, columnIndex];
    5252        ss += d * d;
    5353      }
     
    6363      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    6464      int scaleIndex = 0;
    65       foreach (int k in columnIndices) {
    66         double d = x[i, k] - xt[j, k];
     65      foreach (int columnIndex in columnIndices) {
     66        double d = x[i, columnIndex] - xt[j, columnIndex];
    6767        ss += d * d * scale[scaleIndex] * scale[scaleIndex];
    6868        scaleIndex++;
    6969      }
     70      // must be at the end of scale after iterating over columnIndices
     71      if (scaleIndex != scale.Length)
     72        throw new ArgumentException("Lengths of scales and covariance functions does not match.");
    7073      return ss;
    7174    }
     
    7780      double sum = 0.0;
    7881      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    79       foreach (int k in columnIndices) {
    80         sum += x[i, k] * xt[j, k];
     82      foreach (int columnIndex in columnIndices) {
     83        sum += x[i, columnIndex] * xt[j, columnIndex];
    8184      }
    8285      return scale * scale * sum;
     
    9093      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
    9194      int scaleIndex = 0;
    92       foreach (int k in columnIndices) {
    93         sum += x[i, k] * scale[scaleIndex] * xt[j, k] * scale[scaleIndex];
     95      foreach (int columnIndex in columnIndices) {
     96        sum += x[i, columnIndex] * scale[scaleIndex] * xt[j, columnIndex] * scale[scaleIndex];
    9497        scaleIndex++;
    9598      }
     99      // must be at the end of scale after iterating over columnIndices
     100      if (scaleIndex != scale.Length)
     101        throw new ArgumentException("Lengths of scales and covariance functions does not match.");
     102
    96103      return sum;
    97104    }
Note: See TracChangeset for help on using the changeset viewer.