Free cookie consent management tool by TermsFeed Policy Generator

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.