Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/17/15 19:04:45 (9 years ago)
Author:
gkronber
Message:

#1967: synchronized access to PRNG in GaussianProcessCovarianceOptimizationProblem.Evaluate() and added a comment

File:
1 edited

Legend:

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

    r13209 r13234  
    192192    }
    193193
     194    // Does not produce the same result for the same seed when using parallel engine (see below)!
    194195    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
    195196      var meanFunction = new MeanConst();
     
    220221        hyperParameters[0] = ds.GetDoubleValues(targetVariable).Average(); // mean const
    221222
    222         for (int i = 0; i < covarianceFunction.GetNumberOfParameters(nVars); i++) {
    223           hyperParameters[1 + i] = random.NextDouble() * 2.0 - 1.0;
     223        // Evaluate might be called concurrently therefore access to random has to be synchronized.
     224        // However, results of multiple runs with the same seed will be different when using the parallel engine.
     225        lock (random) {
     226          for (int i = 0; i < covarianceFunction.GetNumberOfParameters(nVars); i++) {
     227            hyperParameters[1 + i] = random.NextDouble() * 2.0 - 1.0;
     228          }
    224229        }
    225230        hyperParameters[hyperParameters.Length - 1] = 1.0; // s² = exp(2), TODO: other inits better?
Note: See TracChangeset for help on using the changeset viewer.