Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Feynman/Feynman5.cs

Last change on this file 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.7 KB
RevLine 
[17647]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Random;
6
7namespace HeuristicLab.Problems.Instances.DataAnalysis {
8  public class Feynman5 : FeynmanDescriptor {
9    private readonly int testSamples;
10    private readonly int trainingSamples;
11
12    public Feynman5() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { }
13
14    public Feynman5(int seed) {
15      Seed            = seed;
16      trainingSamples = 10000;
17      testSamples     = 10000;
18      noiseRatio      = null;
19    }
20
21    public Feynman5(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 {
[17805]30        return string.Format("I.9.18 G*m1*m2/((x2-x1)**2+(y2-y1)**2+(z2-z1)**2) | {0}",
31          noiseRatio == null ? "no noise" : string.Format(System.Globalization.CultureInfo.InvariantCulture, "noise={0:g}",noiseRatio));
[17647]32      }
33    }
34
35    protected override string TargetVariable { get { return noiseRatio == null ? "F" : "F_noise"; } }
36
37    protected override string[] VariableNames {
[17973]38      get { return noiseRatio == null ? new[] { "m1", "m2", "G", "x1", "x2", "y1", "y2", "z1", "z2", "F" } : new[] { "m1", "m2", "G", "x1", "x2", "y1", "y2", "z1", "z2", "F", "F_noise" }; }
[17647]39    }
40
41    protected override string[] AllowedInputVariables {
42      get { return new[] {"m1", "m2", "G", "x1", "x2", "y1", "y2", "z1", "z2"}; }
43    }
44
45    public int Seed { get; private set; }
46
47    protected override int TrainingPartitionStart { get { return 0; } }
48    protected override int TrainingPartitionEnd { get { return trainingSamples; } }
49    protected override int TestPartitionStart { get { return trainingSamples; } }
50    protected override int TestPartitionEnd { get { return trainingSamples + testSamples; } }
51
52    protected override List<List<double>> GenerateValues() {
53      var rand = new MersenneTwister((uint) Seed);
54
55      var data = new List<List<double>>();
56      var m1   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
57      var m2   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
58      var G    = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
59      var x1   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 3, 4).ToList();
60      var x2   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
61      var y1   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 3, 4).ToList();
62      var y2   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
63      var z1   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 3, 4).ToList();
64      var z2   = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
65
66      var F = new List<double>();
67
68      data.Add(m1);
69      data.Add(m2);
70      data.Add(G);
71      data.Add(x1);
72      data.Add(x2);
73      data.Add(y1);
74      data.Add(y2);
75      data.Add(z1);
76      data.Add(z2);
77      data.Add(F);
78
79      for (var i = 0; i < m1.Count; i++) {
80        var res = G[i] * m1[i] * m2[i] /
81                  (Math.Pow(x2[i] - x1[i], 2) + Math.Pow(y2[i] - y1[i], 2) + Math.Pow(z2[i] - z1[i], 2));
82        F.Add(res);
83      }
84
[18032]85      var targetNoise = ValueGenerator.GenerateNoise(F, rand, noiseRatio);
[17973]86      if (targetNoise != null) data.Add(targetNoise);
[17647]87
88      return data;
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.