Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/16 16:19:04 (9 years ago)
Author:
mkommend
Message:

#2591: Changed all GP covariance and mean functions to use int[] for column indices instead of IEnumerable<int>. Changed GP utils, GPModel and StudentTProcessModell as well to use fewer iterators and adapted unit tests to new interface.

File:
1 edited

Legend:

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

    r12012 r13721  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Linq.Expressions;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    131130    }
    132131
    133     public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     132    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) {
    134133      double[] weight, frequency, lengthScale;
    135134      GetParameterValues(p, out weight, out frequency, out lengthScale);
     
    152151    }
    153152
    154     private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int> columnIndices) {
     153    private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices) {
    155154      // tau = x - x' (only for selected variables)
    156155      double[] tau =
     
    164163        int idx = 0; // helper index for tau
    165164        // for each selected variable
    166         foreach (var c in columnIndices) {
    167           kc *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]);
     165        for (int c = 0; c < columnIndices.Length; c++) {
     166          var col = columnIndices[c];
     167          kc *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]);
    168168          idx++;
    169169        }
     
    181181
    182182    // order of returned gradients must match the order in GetParameterValues!
    183     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int> columnIndices,
     183    private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices,
    184184      bool fixedWeight, bool fixedFrequency, bool fixedLengthScale) {
    185185      double[] tau = Util.GetRow(x, i, columnIndices).Zip(Util.GetRow(x, j, columnIndices), (xi, xj) => xi - xj).ToArray();
     
    193193          int idx = 0; // helper index for tau
    194194          // for each selected variable
    195           foreach (var c in columnIndices) {
    196             k *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]);
     195          for (int c = 0; c < columnIndices.Length; c++) {
     196            var col = columnIndices[c];
     197            k *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]);
    197198            idx++;
    198199          }
Note: See TracChangeset for help on using the changeset viewer.