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 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 {
|
---|
40 | return new[] {"epsilon", "L", "m", "Z_1", "Z_2", "q", "E_n", noiseRatio == null ? "alpha" : "alpha_noise"};
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected override string[] AllowedInputVariables {
|
---|
45 | get { return new[] {"epsilon", "L", "m", "Z_1", "Z_2", "q", "E_n"}; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public int Seed { get; private set; }
|
---|
49 |
|
---|
50 | protected override int TrainingPartitionStart { get { return 0; } }
|
---|
51 | protected override int TrainingPartitionEnd { get { return trainingSamples; } }
|
---|
52 | protected override int TestPartitionStart { get { return trainingSamples; } }
|
---|
53 | protected override int TestPartitionEnd { get { return trainingSamples + testSamples; } }
|
---|
54 |
|
---|
55 | protected override List<List<double>> GenerateValues() {
|
---|
56 | var rand = new MersenneTwister((uint) Seed);
|
---|
57 |
|
---|
58 | var data = new List<List<double>>();
|
---|
59 | var epsilon = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
60 | var L = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
61 | var m = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
62 | var Z_1 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
63 | var Z_2 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
64 | var q = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
65 | var E_n = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 3).ToList();
|
---|
66 |
|
---|
67 | var alpha = new List<double>();
|
---|
68 |
|
---|
69 | data.Add(epsilon);
|
---|
70 | data.Add(L);
|
---|
71 | data.Add(m);
|
---|
72 | data.Add(Z_1);
|
---|
73 | data.Add(Z_2);
|
---|
74 | data.Add(q);
|
---|
75 | data.Add(E_n);
|
---|
76 | data.Add(alpha);
|
---|
77 |
|
---|
78 | for (var i = 0; i < epsilon.Count; i++) {
|
---|
79 | var res = Math.Sqrt(1 + 2 * Math.Pow(epsilon[i], 2) * E_n[i] * Math.Pow(L[i], 2) /
|
---|
80 | (m[i] * Math.Pow(Z_1[i] * Z_2[i] * Math.Pow(q[i], 2), 2)));
|
---|
81 | alpha.Add(res);
|
---|
82 | }
|
---|
83 |
|
---|
84 | if (noiseRatio != null) {
|
---|
85 | var alpha_noise = new List<double>();
|
---|
86 | var sigma_noise = (double) Math.Sqrt(noiseRatio.Value) * alpha.StandardDeviationPop();
|
---|
87 | alpha_noise.AddRange(alpha.Select(md => md + NormalDistributedRandom.NextDouble(rand, 0, sigma_noise)));
|
---|
88 | data.Remove(alpha);
|
---|
89 | data.Add(alpha_noise);
|
---|
90 | }
|
---|
91 |
|
---|
92 | return data;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | } |
---|