Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Feynman/Feynman90.cs @ 18027

Last change on this file since 18027 was 18027, checked in by dpiringe, 3 years ago

#3026

  • merged trunk into branch
File size: 3.4 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}",
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 ? "prob" : "prob_noise"; } }
37
38    protected override string[] VariableNames {
39      get { return noiseRatio == null ? new[] { "p_d", "Ef", "t", "h", "omega", "omega_0", "prob" } : new[] { "p_d", "Ef", "t", "h", "omega", "omega_0", "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      var targetNoise = GetNoisyTarget(prob, rand);
82      if (targetNoise != null) data.Add(targetNoise);
83
84      return data;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.