Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3075_aifeynman_instances/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Feynman/Feynman30.cs @ 17642

Last change on this file since 17642 was 17642, checked in by chaider, 4 years ago

#3075 Added field and constructor to define sample size in instances

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Random;
5
6namespace HeuristicLab.Problems.Instances.DataAnalysis {
7  public class Feynman30 : FeynmanDescriptor {
8    private readonly int testSamples;
9    private readonly int trainingSamples;
10
11    public Feynman30() : this((int) DateTime.Now.Ticks, 10000, 10000) { }
12
13    public Feynman30(int seed) {
14      Seed            = seed;
15      trainingSamples = 10000;
16      testSamples     = 10000;
17    }
18
19    public Feynman30(int seed, int trainingSamples, int testSamples) {
20      Seed                 = seed;
21      this.trainingSamples = trainingSamples;
22      this.testSamples     = testSamples;
23    }
24
25    public override string Name {
26      get {
27        return string.Format("Feynman I.30.3 Int_0*sin(n*theta/2)**2/sin(theta/2)**2 | {0} samples", trainingSamples);
28      }
29    }
30
31    protected override string TargetVariable { get { return "Int"; } }
32    protected override string[] VariableNames { get { return new[] {"Int_0", "theta", "n", "Int"}; } }
33    protected override string[] AllowedInputVariables { get { return new[] {"Int_0", "theta", "n"}; } }
34
35    public int Seed { get; private set; }
36
37    protected override int TrainingPartitionStart { get { return 0; } }
38    protected override int TrainingPartitionEnd { get { return trainingSamples; } }
39    protected override int TestPartitionStart { get { return trainingSamples; } }
40    protected override int TestPartitionEnd { get { return trainingSamples + testSamples; } }
41
42    protected override List<List<double>> GenerateValues() {
43      var rand = new MersenneTwister((uint) Seed);
44
45      var data  = new List<List<double>>();
46      var Int_0 = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList();
47      var theta = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList();
48      var n     = ValueGenerator.GenerateUniformDistributedValues(rand.Next(), TestPartitionEnd, 1, 5).ToList();
49
50      var Int = new List<double>();
51
52      data.Add(Int_0);
53      data.Add(theta);
54      data.Add(n);
55      data.Add(Int);
56
57      for (var i = 0; i < Int_0.Count; i++) {
58        var res = Int_0[i] * Math.Pow(Math.Sin(n[i] * theta[i] / 2), 2) / Math.Pow(Math.Sin(theta[i] / 2), 2);
59        Int.Add(res);
60      }
61
62      return data;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.