Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/02/16 18:09:47 (8 years ago)
Author:
gkronber
Message:

#2371: added constructors to allow specification of random seeds for randomly generated regression problem instances (primarily for unit tests)

Location:
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/BreimanOne.cs

    r14185 r14228  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Core;
    2526using HeuristicLab.Random;
    2627
     
    4344    protected override int TestPartitionEnd { get { return 10001; } }
    4445
    45     protected static FastRandom rand = new FastRandom();
     46    public int Seed { get; }
     47
     48    public BreimanOne() : this((int)DateTime.Now.Ticks) { }
     49    public BreimanOne(int seed) : base() {
     50      Seed = seed;
     51    }
    4652
    4753    protected override List<List<double>> GenerateValues() {
    4854      List<List<double>> data = new List<List<double>>();
    4955      List<int> values = new List<int>() { -1, 1 };
    50       data.Add(GenerateUniformIntegerDistribution(values, TestPartitionEnd));
     56      var rand = new MersenneTwister((uint)Seed);
     57      data.Add(GenerateUniformIntegerDistribution(rand, values, TestPartitionEnd));
    5158      values.Add(0);
    5259      for (int i = 0; i < AllowedInputVariables.Count() - 1; i++) {
    53         data.Add(GenerateUniformIntegerDistribution(values, TestPartitionEnd));
     60        data.Add(GenerateUniformIntegerDistribution(rand, values, TestPartitionEnd));
    5461      }
    55 
    5662      double x1, x2, x3, x4, x5, x6, x7;
    5763      double f;
     
    7985    }
    8086
    81     private List<double> GenerateUniformIntegerDistribution(List<int> classes, int amount) {
     87    private List<double> GenerateUniformIntegerDistribution(IRandom rand, List<int> classes, int amount) {
    8288      List<double> values = new List<double>();
    8389      for (int i = 0; i < amount; i++) {
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/FriedmanOne.cs

    r14185 r14228  
    4242    protected override int TestPartitionStart { get { return 5000; } }
    4343    protected override int TestPartitionEnd { get { return 10000; } }
     44    public int Seed { get; }
    4445
    45     protected static FastRandom rand = new FastRandom();
     46    public FriedmanOne() : this((int)DateTime.Now.Ticks) { }
     47
     48    public FriedmanOne(int seed) : base() {
     49      Seed = seed;
     50    }
    4651
    4752    protected override List<List<double>> GenerateValues() {
    4853      List<List<double>> data = new List<List<double>>();
     54      var rand = new MersenneTwister((uint)Seed);
    4955      for (int i = 0; i < AllowedInputVariables.Count(); i++) {
    50         data.Add(ValueGenerator.GenerateUniformDistributedValues(10000, 0, 1).ToList());
     56        data.Add(ValueGenerator.GenerateUniformDistributedValues(rand.Next(), 10000, 0, 1).ToList());
    5157      }
    5258
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/FriedmanTwo.cs

    r14185 r14228  
    4343    protected override int TestPartitionEnd { get { return 10000; } }
    4444
    45     protected static FastRandom rand = new FastRandom();
     45    public int Seed { get; }
    4646
     47    public FriedmanTwo() : this((int)DateTime.Now.Ticks) { }
     48
     49    public FriedmanTwo(int seed) : base() {
     50      Seed = seed;
     51    }
    4752    protected override List<List<double>> GenerateValues() {
    4853      List<List<double>> data = new List<List<double>>();
     54      var rand = new MersenneTwister((uint)Seed);
     55
    4956      for (int i = 0; i < AllowedInputVariables.Count(); i++) {
    50         data.Add(ValueGenerator.GenerateUniformDistributedValues(10000, 0, 1).ToList());
     57        data.Add(ValueGenerator.GenerateUniformDistributedValues(rand.Next(), 10000, 0, 1).ToList());
    5158      }
    5259
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/PolyTen.cs

    r14185 r14228  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Random;
    2526
    2627namespace HeuristicLab.Problems.Instances.DataAnalysis {
     
    4546    protected override int TestPartitionStart { get { return 250; } }
    4647    protected override int TestPartitionEnd { get { return 500; } }
     48    public int Seed { get; }
    4749
     50    public PolyTen() : this((int)DateTime.Now.Ticks) { }
     51
     52    public PolyTen(int seed) : base() {
     53      Seed = seed;
     54    }
    4855    protected override List<List<double>> GenerateValues() {
    4956      List<List<double>> data = new List<List<double>>();
     57      var rand = new MersenneTwister((uint)Seed);
     58
    5059      for (int i = 0; i < AllowedInputVariables.Count(); i++) {
    51         data.Add(ValueGenerator.GenerateUniformDistributedValues(TestPartitionEnd, -1, 1).ToList());
     60        data.Add(ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, -1, 1).ToList());
    5261      }
    5362
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/SpatialCoevolution.cs

    r14185 r14228  
    2424using System.Linq;
    2525using HeuristicLab.Common;
     26using HeuristicLab.Random;
    2627
    2728namespace HeuristicLab.Problems.Instances.DataAnalysis {
     
    5051    protected override int TestPartitionStart { get { return 676; } }
    5152    protected override int TestPartitionEnd { get { return 1676; } }
     53    public int Seed { get; }
    5254
     55    public SpatialCoevolution() : this((int)DateTime.Now.Ticks) { }
     56
     57    public SpatialCoevolution(int seed) : base() {
     58      Seed = seed;
     59    }
    5360    protected override List<List<double>> GenerateValues() {
    5461      List<List<double>> data = new List<List<double>>();
     
    5764      List<List<double>> trainingData = new List<List<double>>() { evenlySpacedSequence, evenlySpacedSequence };
    5865      var combinations = ValueGenerator.GenerateAllCombinationsOfValuesInLists(trainingData).ToList();
     66      var rand = new MersenneTwister((uint)Seed);
    5967
    6068      for (int i = 0; i < AllowedInputVariables.Count(); i++) {
    6169        data.Add(combinations[i].ToList());
    62         data[i].AddRange(ValueGenerator.GenerateUniformDistributedValues(1000, -5, 5).ToList());
     70        data[i].AddRange(ValueGenerator.GenerateUniformDistributedValues(rand.Next(), 1000, -5, 5).ToList());
    6371      }
    6472
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/VariousInstanceProvider.cs

    r14185 r14228  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Random;
    2425
    2526namespace HeuristicLab.Problems.Instances.DataAnalysis {
     
    3738      get { return ""; }
    3839    }
     40    public int Seed { get; }
    3941
     42    public VariousInstanceProvider() : this((int)DateTime.Now.Ticks) { }
     43
     44    public VariousInstanceProvider(int seed) : base() {
     45      Seed = seed;
     46    }
    4047    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    4148      List<IDataDescriptor> descriptorList = new List<IDataDescriptor>();
    42       descriptorList.Add(new BreimanOne());
    43       descriptorList.Add(new FriedmanOne());
    44       descriptorList.Add(new FriedmanTwo());
    45       descriptorList.Add(new PolyTen());
    46       descriptorList.Add(new SpatialCoevolution());
     49      var rand = new MersenneTwister((uint)Seed);
     50      descriptorList.Add(new BreimanOne(rand.Next()));
     51      descriptorList.Add(new FriedmanOne(rand.Next()));
     52      descriptorList.Add(new FriedmanTwo(rand.Next()));
     53      descriptorList.Add(new PolyTen(rand.Next()));
     54      descriptorList.Add(new SpatialCoevolution(rand.Next()));
    4755      return descriptorList;
    4856    }
Note: See TracChangeset for help on using the changeset viewer.