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 Feynman33 : FeynmanDescriptor {
|
---|
9 | private readonly int testSamples;
|
---|
10 | private readonly int trainingSamples;
|
---|
11 |
|
---|
12 | public Feynman33() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { }
|
---|
13 |
|
---|
14 | public Feynman33(int seed) {
|
---|
15 | Seed = seed;
|
---|
16 | trainingSamples = 10000;
|
---|
17 | testSamples = 10000;
|
---|
18 | noiseRatio = null;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public Feynman33(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 | "Feynman I.32.17 (1/2*epsilon*c*Ef**2)*(8*pi*r**2/3)*(omega**4/(omega**2-omega_0**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 ? "Pwr" : "Pwr_noise"; } }
|
---|
37 |
|
---|
38 | protected override string[] VariableNames {
|
---|
39 | get { return new[] {"epsilon", "c", "Ef", "r", "omega", "omega_0", noiseRatio == null ? "Pwr" : "Pwr_noise"}; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override string[] AllowedInputVariables {
|
---|
43 | get { return new[] {"epsilon", "c", "Ef", "r", "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 epsilon = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
|
---|
58 | var c = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
|
---|
59 | var Ef = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
|
---|
60 | var r = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
|
---|
61 | var omega = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 2).ToList();
|
---|
62 | var omega_0 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 3, 5).ToList();
|
---|
63 |
|
---|
64 | var Pwr = new List<double>();
|
---|
65 |
|
---|
66 | data.Add(epsilon);
|
---|
67 | data.Add(c);
|
---|
68 | data.Add(Ef);
|
---|
69 | data.Add(r);
|
---|
70 | data.Add(omega);
|
---|
71 | data.Add(omega_0);
|
---|
72 | data.Add(Pwr);
|
---|
73 |
|
---|
74 | for (var i = 0; i < epsilon.Count; i++) {
|
---|
75 | var res = 1.0 / 2 * epsilon[i] * c[i] * Math.Pow(Ef[i], 2) * (8 * Math.PI + Math.Pow(r[i], 2) / 3) *
|
---|
76 | (Math.Pow(omega[i], 4) / Math.Pow(Math.Pow(omega[i], 2) - Math.Pow(omega_0[i], 2), 2));
|
---|
77 | Pwr.Add(res);
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (noiseRatio != null) {
|
---|
81 | var Pwr_noise = new List<double>();
|
---|
82 | var sigma_noise = (double) noiseRatio * Pwr.StandardDeviationPop();
|
---|
83 | Pwr_noise.AddRange(Pwr.Select(md => md + NormalDistributedRandom.NextDouble(rand, 0, sigma_noise)));
|
---|
84 | data.Remove(Pwr);
|
---|
85 | data.Add(Pwr_noise);
|
---|
86 | }
|
---|
87 |
|
---|
88 | return data;
|
---|
89 | }
|
---|
90 | }
|
---|
91 | } |
---|