Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Feynman/FeynmanBonus11.cs @ 18106

Last change on this file since 18106 was 18032, checked in by chaider, 3 years ago

#3075 noise generation method to ValueGenerator; use same method for generating noise in friedman and feynman instances

File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Random;
6
7namespace HeuristicLab.Problems.Instances.DataAnalysis {
8  public class FeynmanBonus11 : FeynmanDescriptor {
9    private readonly int testSamples;
10    private readonly int trainingSamples;
11
12    public FeynmanBonus11() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { }
13
14    public FeynmanBonus11(int seed) {
15      Seed            = seed;
16      trainingSamples = 10000;
17      testSamples     = 10000;
18      noiseRatio      = null;
19    }
20
21    public FeynmanBonus11(int seed, int trainingSamples, int testSamples, double? noiseRatio) {
22      Seed                 = seed;
23      this.trainingSamples = trainingSamples;
24      this.testSamples     = testSamples;
25      this.noiseRatio      = noiseRatio;
26    }
27
28    public override string Name {
29      get {
30        return string.Format(
31          "Goldstein 3.99: sqrt(1+2*epsilon**2*E_n*L**2/(m*(Z_1*Z_2*q**2)**2)) | {0}",
32          noiseRatio == null ? "no noise" : string.Format(System.Globalization.CultureInfo.InvariantCulture, "noise={0:g}",noiseRatio));
33      }
34    }
35
36    protected override string TargetVariable { get { return noiseRatio == null ? "alpha" : "alpha_noise"; } }
37
38    protected override string[] VariableNames {
39      get { return noiseRatio == null ? new[] { "epsilon", "L", "m", "Z_1", "Z_2", "q", "E_n", "alpha" } : new[] { "epsilon", "L", "m", "Z_1", "Z_2", "q", "E_n", "alpha", "alpha_noise" }; }
40    }
41
42    protected override string[] AllowedInputVariables {
43      get { return new[] {"epsilon", "L", "m", "Z_1", "Z_2", "q", "E_n"}; }
44    }
45
46    public int Seed { get; private set; }
47
48    protected override int TrainingPartitionStart { get { return 0; } }
49    protected override int TrainingPartitionEnd { get { return trainingSamples; } }
50    protected override int TestPartitionStart { get { return trainingSamples; } }
51    protected override int TestPartitionEnd { get { return trainingSamples + testSamples; } }
52
53    protected override List<List<double>> GenerateValues() {
54      var rand = new MersenneTwister((uint) Seed);
55
56      var data    = new List<List<double>>();
57      var epsilon = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
58      var L       = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
59      var m       = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
60      var Z_1     = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
61      var Z_2     = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
62      var q       = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
63      var E_n     = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
64
65      var alpha = new List<double>();
66
67      data.Add(epsilon);
68      data.Add(L);
69      data.Add(m);
70      data.Add(Z_1);
71      data.Add(Z_2);
72      data.Add(q);
73      data.Add(E_n);
74      data.Add(alpha);
75
76      for (var i = 0; i < epsilon.Count; i++) {
77        var res = Math.Sqrt(1 + 2 * Math.Pow(epsilon[i], 2) * E_n[i] * Math.Pow(L[i], 2) /
78                            (m[i] * Math.Pow(Z_1[i] * Z_2[i] * Math.Pow(q[i], 2), 2)));
79        alpha.Add(res);
80      }
81
82      var targetNoise = ValueGenerator.GenerateNoise(alpha, rand, noiseRatio);
83      if (targetNoise != null) data.Add(targetNoise);
84
85      return data;
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.