Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Templates/RegressionProblemInstances/RegressionProblemInstance/RegressionProblemInstanceProvider.cs @ 18040

Last change on this file since 18040 was 14365, checked in by gkronber, 8 years ago

added template for regression problem instance providers

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Problems.DataAnalysis;
4using HeuristicLab.Problems.Instances;
5using HeuristicLab.Random;
6
7namespace RegressionProblemInstances {
8  public class RegressionProblemInstanceProvider : ProblemInstanceProvider<IRegressionProblemData> {
9    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
10      // if data is generated randomly then it is recommended to use a fixed random seed for reproducability
11      // Here we even use a random number generator to produce the seeds for the instance specific random number generators
12      var seedRandom = new MersenneTwister(1234);
13      return new[]
14      {
15        new RegressionProblemInstanceDescriptor(
16          name: "Poly-10", desc: "The Poly-10 problem.",
17          rand: new NormalDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), 0, 10), // x ~ N(0,10)
18          dim: 10, numRows: 500,
19          func: (double[] x) => x[0]*x[1] + x[2]*x[3] + x[4]*x[5] + x[0]*x[6]*x[8] + x[2]*x[5]*x[9]
20          ),
21        new RegressionProblemInstanceDescriptor(
22          name: "sqrt(x+1)-sqrt(x)", desc: "Example from Herbie website http://herbie.uwplse.org/",
23          rand: new UniformDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), 0, 1E6),  // x ~ U(0, 1e6)
24          dim: 1, numRows: 5000,
25          func: (double[] x) => Math.Sqrt(x[0]+1) - Math.Sqrt(x[0])
26          ),
27        new RegressionProblemInstanceDescriptor(
28          name: "Quadratic formula (-b/2a - sqrt(b^2 - 4ac)/2a", desc: "Example from Herbie paper http://herbie.uwplse.org/pldi15-paper.pdf",
29          rand: new UniformDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), -1E6, 1E6),  // x ~ U(-1e6, 1e6)
30          dim: 3, numRows: 5000,
31          func: (double[] x) => (-x[1] - Math.Sqrt(-x[1]*x[1]  - 4.0*x[0]*x[2])) / (2*x[0])
32          )
33      };
34    }
35
36    public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
37      var desc = descriptor as IRegressionProblemInstanceDescriptor;
38      if (desc == null) {
39        throw new ArgumentException();
40      } else {
41        return desc.GenerateData();
42      }
43    }
44
45    public override bool CanExportData { get { return false; } }
46    public override bool CanImportData { get { return false; } }
47
48    public override string Name { get { return "My problem instances"; } }
49    public override string Description { get { return "A set of regression problem instance "; } }
50    public override Uri WebLink { get { return new Uri("https://dev.heuristiclab.com"); } } // if there is a web uri with more information on the problem instances
51    public override string ReferencePublication { get { return string.Empty; } } // if there is an academic publication for these problem instances
52  }
53}
Note: See TracBrowser for help on using the repository browser.