Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3075_aifeynman_instances/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Feynman/Feynman90.cs @ 17676

Last change on this file since 17676 was 17674, checked in by gkronber, 4 years ago

#3075 small changes while reviewing

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 Feynman90 : FeynmanDescriptor {
9    private readonly int testSamples;
10    private readonly int trainingSamples;
11
12    public Feynman90() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { }
13
14    public Feynman90(int seed) {
15      Seed            = seed;
16      trainingSamples = 10000;
17      testSamples     = 10000;
18      noiseRatio      = null;
19    }
20
21    public Feynman90(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          "III.9.52 (p_d*Ef*t/h*sin((omega-omega_0)*t/2)**2/((omega-omega_0)*t/2)**2 | {0} samples | noise ({1})",
32          trainingSamples, noiseRatio == null ? "no noise" : noiseRatio.ToString());
33      }
34    }
35
36    protected override string TargetVariable { get { return noiseRatio == null ? "prob" : "prob_noise"; } }
37
38    protected override string[] VariableNames {
39      get { return new[] {"p_d", "Ef", "t", "h", "omega", "omega_0", noiseRatio == null ? "prob" : "prob_noise"}; }
40    }
41
42    protected override string[] AllowedInputVariables {
43      get { return new[] {"p_d", "Ef", "t", "h", "omega", "omega_0"}; }
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 p_d     = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
58      var Ef      = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
59      var t       = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
60      var h       = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
61      var omega   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList();
62      var omega_0 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList();
63
64      var prob = new List<double>();
65
66      data.Add(p_d);
67      data.Add(Ef);
68      data.Add(t);
69      data.Add(h);
70      data.Add(omega);
71      data.Add(omega_0);
72      data.Add(prob);
73
74      for (var i = 0; i < p_d.Count; i++) {
75        var res = p_d[i] * Ef[i] * t[i] / h[i] *
76                  Math.Pow(Math.Sin((omega[i] - omega_0[i]) * t[i] / 2), 2) /
77                  Math.Pow((omega[i] - omega_0[i]) * t[i] / 2, 2);
78        prob.Add(res);
79      }
80
81      if (noiseRatio != null) {
82        var prob_noise  = new List<double>();
83        var sigma_noise = (double) noiseRatio * prob.StandardDeviationPop();
84        prob_noise.AddRange(prob.Select(md => md + NormalDistributedRandom.NextDouble(rand, 0, sigma_noise)));
85        data.Remove(prob);
86        data.Add(prob_noise);
87      }
88
89      return data;
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.