Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4038


Ignore:
Timestamp:
07/15/10 14:01:09 (14 years ago)
Author:
mkommend
Message:

corrected bug in SymbolicRegressionEvaluator (ticket #1082)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs

    r4035 r4038  
    3535using HeuristicLab.Operators;
    3636using HeuristicLab.Problems.DataAnalysis.Symbolic;
     37using HeuristicLab.Random;
    3738
    3839namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    131132
    132133    public override IOperation Apply() {
    133       IEnumerable<int> rows = GenerateRowsToEvaluate(RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value);
     134      uint seed = (uint)Random.Next();
     135      IEnumerable<int> rows = GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value);
    134136      double quality = Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset,
    135137        RegressionProblemData.TargetVariable, rows);
     
    140142
    141143    //algorithm taken from progamming pearls page 127
    142     private IEnumerable<int> GenerateRowsToEvaluate(double relativeAmount, int start, int end) {
     144    //IMPORTANT because IEnumerables with yield are used the seed must best be specified to return always
     145    //the same sequence of numbers without caching the values.
     146    private static IEnumerable<int> GenerateRowsToEvaluate(uint seed, double relativeAmount, int start, int end) {
    143147      if (end < start) throw new ArgumentException("Start value is larger than end value.");
    144148      int count = (int)((end - start) * relativeAmount);
     
    146150
    147151      int remaining = end - start;
     152      MersenneTwister random = new MersenneTwister(seed);
    148153      for (int i = start; i < end && count > 0; i++) {
    149         double probabilty = Random.NextDouble();
     154        double probabilty = random.NextDouble();
    150155        if (probabilty < ((double)count) / remaining) {
    151156          count--;
Note: See TracChangeset for help on using the changeset viewer.