Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/16 13:47:35 (8 years ago)
Author:
pfleck
Message:

#2591 Made the creation of a GaussianProcessModel faster by avoiding additional iterators during calculation of the hyperparameter gradients.
The gradients of the hyperparameters are now calculated in one sweep and returned as IList, instead of returning an iterator (with yield return).
This avoids a large amount of Move-calls of the iterator, especially for covariance functions with a lot of hyperparameters.
Besides, the signature of the CovarianceGradientFunctionDelegate is changed, to return an IList instead of an IEnumerable to avoid unnececary ToList or ToArray calls.

File:
1 edited

Legend:

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

    r13721 r13784  
    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, int[] columnIndices,
     183    private static IList<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();
    186186      int numberOfVariables = lengthScale.Length / maxQ;
    187187
     188      var g = new List<double>((!fixedWeight ? maxQ : 0) + (!fixedFrequency ? maxQ * columnIndices.Length : 0) + (!fixedLengthScale ? maxQ * columnIndices.Length : 0));
    188189      if (!fixedWeight) {
    189190        // weight
     
    198199            idx++;
    199200          }
    200           yield return k;
     201          g.Add(k);
    201202        }
    202203      }
     
    213214                       Math.Sin(2 * Math.PI * tau[idx] * frequency[q * numberOfVariables + c]);
    214215            idx++;
    215             yield return weight[q] * k;
     216            g.Add(weight[q] * k);
    216217          }
    217218        }
     
    229230                       f2(tau[idx], frequency[q * numberOfVariables + c]);
    230231            idx++;
    231             yield return weight[q] * k;
     232            g.Add(weight[q] * k);
    232233          }
    233234        }
    234235      }
     236
     237      return g;
    235238    }
    236239  }
Note: See TracChangeset for help on using the changeset viewer.