using System; using System.Collections.Generic; using HeuristicLab.Problems.DataAnalysis; using HeuristicLab.Problems.Instances; using HeuristicLab.Random; namespace RegressionProblemInstances { public class RegressionProblemInstanceProvider : ProblemInstanceProvider { public override IEnumerable GetDataDescriptors() { // if data is generated randomly then it is recommended to use a fixed random seed for reproducability // Here we even use a random number generator to produce the seeds for the instance specific random number generators var seedRandom = new MersenneTwister(1234); return new[] { new RegressionProblemInstanceDescriptor( name: "Poly-10", desc: "The Poly-10 problem.", rand: new NormalDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), 0, 10), // x ~ N(0,10) dim: 10, numRows: 500, 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] ), new RegressionProblemInstanceDescriptor( name: "sqrt(x+1)-sqrt(x)", desc: "Example from Herbie website http://herbie.uwplse.org/", rand: new UniformDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), 0, 1E6), // x ~ U(0, 1e6) dim: 1, numRows: 5000, func: (double[] x) => Math.Sqrt(x[0]+1) - Math.Sqrt(x[0]) ), new RegressionProblemInstanceDescriptor( name: "Quadratic formula (-b/2a - sqrt(b^2 - 4ac)/2a", desc: "Example from Herbie paper http://herbie.uwplse.org/pldi15-paper.pdf", rand: new UniformDistributedRandom(new MersenneTwister((uint) seedRandom.Next()), -1E6, 1E6), // x ~ U(-1e6, 1e6) dim: 3, numRows: 5000, func: (double[] x) => (-x[1] - Math.Sqrt(-x[1]*x[1] - 4.0*x[0]*x[2])) / (2*x[0]) ) }; } public override IRegressionProblemData LoadData(IDataDescriptor descriptor) { var desc = descriptor as IRegressionProblemInstanceDescriptor; if (desc == null) { throw new ArgumentException(); } else { return desc.GenerateData(); } } public override bool CanExportData { get { return false; } } public override bool CanImportData { get { return false; } } public override string Name { get { return "My problem instances"; } } public override string Description { get { return "A set of regression problem instance "; } } 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 public override string ReferencePublication { get { return string.Empty; } } // if there is an academic publication for these problem instances } }