using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Random; namespace HeuristicLab.Problems.Instances.DataAnalysis { public class Feynman99 : FeynmanDescriptor { private readonly int testSamples; private readonly int trainingSamples; public Feynman99() : this((int) DateTime.Now.Ticks, 10000, 10000, null) { } public Feynman99(int seed) { Seed = seed; trainingSamples = 10000; testSamples = 10000; noiseRatio = null; } public Feynman99(int seed, int trainingSamples, int testSamples, double? noiseRatio) { Seed = seed; this.trainingSamples = trainingSamples; this.testSamples = testSamples; this.noiseRatio = noiseRatio; } public override string Name { get { return string.Format( "III.19.51 -m*q**4/(2*(4*pi*epsilon)**2*h**2)*(1/n**2) | {0}", noiseRatio == null ? "no noise" : string.Format(System.Globalization.CultureInfo.InvariantCulture, "noise={0:g}",noiseRatio)); } } protected override string TargetVariable { get { return noiseRatio == null ? "E_n" : "E_n_noise"; } } protected override string[] VariableNames { get { return noiseRatio == null ? new[] { "m", "q", "h", "n", "epsilon", "E_n" } : new[] { "m", "q", "h", "n", "epsilon", "E_n", "E_n_noise" }; } } protected override string[] AllowedInputVariables { get { return new[] {"m", "q", "h", "n", "epsilon"}; } } public int Seed { get; private set; } protected override int TrainingPartitionStart { get { return 0; } } protected override int TrainingPartitionEnd { get { return trainingSamples; } } protected override int TestPartitionStart { get { return trainingSamples; } } protected override int TestPartitionEnd { get { return trainingSamples + testSamples; } } protected override List> GenerateValues() { var rand = new MersenneTwister((uint) Seed); var data = new List>(); var m = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList(); var q = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList(); var h = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList(); var n = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList(); var epsilon = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList(); var E_n = new List(); data.Add(m); data.Add(q); data.Add(h); data.Add(n); data.Add(epsilon); data.Add(E_n); for (var i = 0; i < m.Count; i++) { var res = -m[i] * Math.Pow(q[i], 4) / (2 * Math.Pow(4 * Math.PI * epsilon[i], 2) * Math.Pow(h[i], 2) * (1.0 / Math.Pow(n[i], 2))); E_n.Add(res); } var targetNoise = ValueGenerator.GenerateNoise(E_n, rand, noiseRatio); if (targetNoise != null) data.Add(targetNoise); return data; } } }