1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Random;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Problems.Instances.DataAnalysis {
|
---|
8 | public class FeynmanBonus8 : FeynmanDescriptor {
|
---|
9 | private readonly int testSamples;
|
---|
10 | private readonly int trainingSamples;
|
---|
11 |
|
---|
12 | public FeynmanBonus8() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { }
|
---|
13 |
|
---|
14 | public FeynmanBonus8(int seed) {
|
---|
15 | Seed = seed;
|
---|
16 | trainingSamples = 10000;
|
---|
17 | testSamples = 10000;
|
---|
18 | noiseRatio = null;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public FeynmanBonus8(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.55: m*k_G/L**2*(1+sqrt(1+2*E_n*L**2/(m*k_G**2))*cos(theta1-theta2)) | {0} samples | {1}",
|
---|
32 | trainingSamples, 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 ? "k" : "k_noise"; } }
|
---|
37 |
|
---|
38 | protected override string[] VariableNames {
|
---|
39 | get { return new[] {"m", "k_G", "L", "E_n", "theta1", "theta2", noiseRatio == null ? "k" : "k_noise"}; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override string[] AllowedInputVariables {
|
---|
43 | get { return new[] {"m", "k_G", "L", "E_n", "theta1", "theta2"}; }
|
---|
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 m = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
58 | var k_G = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
59 | var L = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
60 | var E_n = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
61 | var theta1 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 0, 6).ToList();
|
---|
62 | var theta2 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 0, 6).ToList();
|
---|
63 |
|
---|
64 | var k = new List<double>();
|
---|
65 |
|
---|
66 | data.Add(m);
|
---|
67 | data.Add(k_G);
|
---|
68 | data.Add(L);
|
---|
69 | data.Add(E_n);
|
---|
70 | data.Add(theta1);
|
---|
71 | data.Add(theta2);
|
---|
72 | data.Add(k);
|
---|
73 |
|
---|
74 | for (var i = 0; i < m.Count; i++) {
|
---|
75 | var res = m[i] * k_G[i] / Math.Pow(L[i], 2) *
|
---|
76 | (1 + Math.Sqrt(1 + 2 * E_n[i] * Math.Pow(L[i], 2) / (m[i] * Math.Pow(k_G[i], 2))) *
|
---|
77 | Math.Cos(theta1[i] - theta2[i]));
|
---|
78 | k.Add(res);
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (noiseRatio != null) {
|
---|
82 | var k_noise = new List<double>();
|
---|
83 | var sigma_noise = (double) noiseRatio * k.StandardDeviationPop();
|
---|
84 | k_noise.AddRange(k.Select(md => md + NormalDistributedRandom.NextDouble(rand, 0, sigma_noise)));
|
---|
85 | data.Remove(k);
|
---|
86 | data.Add(k_noise);
|
---|
87 | }
|
---|
88 |
|
---|
89 | return data;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | } |
---|