- Timestamp:
- 11/14/11 17:08:32 (13 years ago)
- Location:
- branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/Generator/RegressionBenchmark.cs
r6968 r6991 20 20 #endregion 21 21 22 using System;23 22 using System.Collections; 24 23 using System.Collections.Generic; … … 26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Data; 27 using HeuristicLab.Random; 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { 30 30 public abstract class RegressionBenchmark : Benchmark, IRegressionBenchmarkProblemDataGenerator { 31 32 #region properties 33 public abstract List<string> InputVariable { get; } 34 public abstract string TargetVariable { get; } 35 public abstract IntRange TrainingPartition { get; } 36 public abstract IntRange TestPartition { get; } 37 #endregion 31 38 32 39 protected RegressionBenchmark() { } … … 35 42 } 36 43 37 #region properties 38 public string TargetVariable { get; protected set; } 39 public Dictionary<string, IntRange> Inputvariables { get; protected set; } 40 public int AmountOfPoints { get; protected set; } 41 public IntRange TrainingPartition { get; protected set; } 42 public IntRange TestPartition { get; protected set; } 43 #endregion 44 protected abstract List<double> CalculateFunction(Dictionary<string, IList<double>> data); 44 45 45 protected abstract double CalculateFunction(Dictionary<string, IList<double>> data, List<string> vars);46 protected abstract Dictionary<string, IList<double>> GenerateInput(Dictionary<string, IList<double>> data); 46 47 47 48 public IDataAnalysisProblemData GenerateProblemData() { 48 //prepare dictionary49 49 Dictionary<string, IList<double>> data = new Dictionary<string, IList<double>>(); 50 data.Add( TargetVariable, new List<double>());51 foreach (var variable in Inputvariables.Keys) {50 data.Add(this.TargetVariable, new List<double>()); 51 foreach (var variable in this.InputVariable) { 52 52 data.Add(variable, new List<double>()); 53 53 } 54 54 55 data = CalculateValues(data);55 data = GenerateInput(data); 56 56 57 57 List<IList> values = new List<IList>(); … … 65 65 RegressionProblemData problemData = new RegressionProblemData(dataset, dataset.DoubleVariables.Skip(1), dataset.DoubleVariables.First()); 66 66 67 #region set ProblemData specific parameters68 67 problemData.Name = "Data generated for benchmark problem \"" + this.Name + "\""; 69 68 70 problemData.TargetVariableParameter.Value =71 problemData.TargetVariableParameter.ValidValues.First(v => v.Value == TargetVariable);72 problemData.InputVariables.SetItemCheckedState(73 problemData.InputVariables.Single(x => x.Value == TargetVariable), false);74 75 foreach (var variable in this.Inputvariables) {76 problemData.InputVariables.SetItemCheckedState(77 problemData.InputVariables.Single(x => x.Value == variable.Key), true);78 }79 69 80 70 problemData.TestPartition.Start = this.TestPartition.Start; 81 71 problemData.TestPartition.End = this.TestPartition.End; 72 82 73 problemData.TrainingPartition.Start = this.TrainingPartition.Start; 83 74 problemData.TrainingPartition.End = this.TrainingPartition.End; 84 #endregion85 75 86 76 return problemData; 87 77 } 88 78 89 private Dictionary<string, IList<double>> CalculateValues(Dictionary<string, IList<double>> data) { 90 Random rand = new Random(); 91 List<string> vars = new List<string>(Inputvariables.Keys); 92 for (int i = 0; i < AmountOfPoints; i++) { 93 foreach (var variable in vars) { 94 data[variable].Add(rand.NextDouble() * 95 (Inputvariables[variable].End - Inputvariables[variable].Start) + 96 Inputvariables[variable].Start); 97 } 79 //private Dictionary<string, IList<double>> CalculateValues(Dictionary<string, IList<double>> data, DatasetDefinition dataDef) { 80 // Random rand = new Random(); 81 // var combinationDataSet = AllCombinationsOf(dataDef.RangeVariables.Values.Select(range => range.Values).ToList()); 82 // int index = 0; 83 // var help = dataDef.RangeVariables.Keys; 84 // foreach (var dataSet in combinationDataSet) { 85 // data[help.ElementAt(index)] = dataSet; 86 // index++; 87 // } 88 // List<string> vars = new List<string>(dataDef.RandomVariables.Keys); 89 // for (int i = 0; i < dataDef.AmountOfPoints; i++) { 90 // foreach (var variable in vars) { 91 // data[variable].Add(dataDef.RandomVariables[variable].Next()); 92 // } 93 // // data[TargetVariable].Add(CalculateFunction(data, vars)); 94 // } 95 // int bla = 0; 96 // var test = data.Values.Select((ind) => (ind.ElementAt(bla))); 98 97 99 data[TargetVariable].Add(CalculateFunction(data, vars)); 98 // return data; 99 //} 100 101 public static List<double> generateSteps(DoubleRange range, double stepWidth) { 102 return Enumerable.Range(0, (int)((range.End - range.Start) / stepWidth) + 1) 103 .Select(i => (range.Start + i * stepWidth)) 104 .ToList<double>(); 105 } 106 107 public static List<double> generateUniformDistributedValues(int amount, DoubleRange range) { 108 List<double> values = new List<double>(); 109 System.Random rand = new System.Random(); 110 for (int i = 0; i < amount; i++) { 111 values.Add(rand.NextDouble() * (range.End - range.Start) + range.Start); 100 112 } 101 return data; 113 return values; 114 } 115 116 public static List<double> generateNormalDistributedValues(int amount, double mu, double sigma) { 117 List<double> values = new List<double>(); 118 FastRandom rand = new FastRandom(); 119 for (int i = 0; i < amount; i++) { 120 values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma)); 121 } 122 return values; 123 } 124 125 public static List<List<double>> AllCombinationsOf(List<List<double>> sets) { 126 127 var combinations = new List<List<double>>(); 128 129 foreach (var value in sets[0]) 130 combinations.Add(new List<double> { value }); 131 132 foreach (var set in sets.Skip(1)) 133 combinations = AddExtraSet(combinations, set); 134 135 return combinations; 136 } 137 138 private static List<List<double>> AddExtraSet 139 (List<List<double>> combinations, List<double> set) { 140 var newCombinations = from value in set 141 from combination in combinations 142 select new List<double>(combination) { value }; 143 144 return newCombinations.ToList(); 102 145 } 103 146 } -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/HeuristicLab.Problems.DataAnalysis.Benchmarks-3.4.csproj
r6973 r6991 49 49 <ItemGroup> 50 50 <Compile Include="Benchmark.cs" /> 51 <Compile Include="DistributionGenerator\Distribution.cs" />52 <Compile Include="DistributionGenerator\DistributionGenerator.cs" />53 <Compile Include="DistributionGenerator\NormalDistribution.cs" />54 <Compile Include="DistributionGenerator\RandomDistribution.cs" />55 <Compile Include="DistributionGenerator\StepsDistribution.cs" />56 <Compile Include="DistributionGenerator\UniformalDistribution.cs" />57 51 <Compile Include="Plugin.cs" /> 58 52 <Compile Include="Properties\AssemblyInfo.cs" /> 59 <Compile Include="RegressionBenchmarks\RationalPolynomial.cs" />60 <Compile Include="RegressionBenchmarks\RationalPolynomialTwo.cs" />61 <Compile Include="RegressionBenchmarks\RippleFunction.cs" />62 <Compile Include="RegressionBenchmarks\SalustowiczFunctionTwoDimensional.cs" />63 53 <Compile Include="RegressionBenchmarks\KotanchekFunction.cs" /> 64 54 <Compile Include="Generator\RegressionBenchmark.cs" /> 65 <Compile Include="RegressionBenchmarks\SalustowiczFunctionOneDimensional.cs" />66 <Compile Include="RegressionBenchmarks\SineCosineFunction.cs" />67 <Compile Include="RegressionBenchmarks\UnwrappedBallFunction.cs" />68 55 </ItemGroup> 69 56 <ItemGroup> … … 96 83 <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name> 97 84 </ProjectReference> 85 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 86 <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project> 87 <Name>HeuristicLab.Random-3.3</Name> 88 </ProjectReference> 98 89 </ItemGroup> 99 90 <ItemGroup> -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/KotanchekFunction.cs
r6968 r6991 31 31 public class KotanchekFunction : RegressionBenchmark { 32 32 33 private const string targetVariable = "Y"; 34 private static readonly List<string> inputVariables = new List<string>() { "X1", "X2" }; 35 private static readonly IntRange trainingPartition = new IntRange(0, 1000); 36 private static readonly IntRange testPartition = new IntRange(1001, 2000); 37 38 public override List<string> InputVariable { 39 get { return inputVariables; } 40 } 41 42 public override string TargetVariable { 43 get { return targetVariable; } 44 } 45 46 public override IntRange TrainingPartition { 47 get { return trainingPartition; } 48 } 49 50 public override IntRange TestPartition { 51 get { return testPartition; } 52 } 53 33 54 public KotanchekFunction() { 34 55 Name = "Kotanchek function (2d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(0, 4)},38 {"x2", new IntRange(0, 4)}39 };40 AmountOfPoints = 4000;41 TrainingPartition = new IntRange(0, 2667);42 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);43 56 } 44 57 … … 53 66 #endregion 54 67 55 protected override double CalculateFunction(Dictionary<string, IList<double>> data, List<string> vars) { 56 double x1 = data[vars.ElementAt(0)].Last(); 57 double x2 = data[vars.ElementAt(1)].Last(); 58 return Math.Exp(-Math.Pow(x1 - 1, 2)) / (Math.Pow(x2 - 2.5, 2) + 3.2); 68 protected override List<double> CalculateFunction(Dictionary<string, IList<double>> data) { 69 double x1, x2; 70 List<double> results = new List<double>(); 71 for (int i = 0; i < TestPartition.End; i++) { 72 x1 = data[InputVariable.ElementAt(0)].ElementAt(i); 73 x2 = data[InputVariable.ElementAt(1)].ElementAt(i); 74 results.Add(Math.Exp(-Math.Pow(x1 - 1, 2)) / (Math.Pow(x2 - 2.5, 2) + 3.2)); 75 } 76 return results; 77 } 78 79 protected override Dictionary<string, IList<double>> GenerateInput(Dictionary<string, IList<double>> data) { 80 foreach (var variable in InputVariable) { 81 data[variable] = RegressionBenchmark.generateUniformDistributedValues(TestPartition.End, new DoubleRange(0, 4)); 82 } 83 data[TargetVariable] = CalculateFunction(data); 84 return data; 59 85 } 60 86 } -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RationalPolynomial.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 32 31 33 32 public RationalPolynomial() { 34 Name = "Rational polynomial (3d)"; 35 TargetVariable = "y"; 36 Inputvariables = new Dictionary<string, IntRange>() { 37 {"x1", new IntRange(0, 2)}, 38 {"x2", new IntRange(1, 2)}, 39 {"x3", new IntRange(1, 2)} 40 }; 41 AmountOfPoints = 4000; 42 TrainingPartition = new IntRange(0, 2667); 43 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 33 //Name = "Rational polynomial (3d)"; 34 //TargetVariable = "y"; 35 36 //var inputVariables = new Dictionary<string, RandomDistribution>() { 37 // {"x1", new UniformalDistribution(0, 2)}, 38 // {"x2", new UniformalDistribution(1, 2)}, 39 // {"x3", new UniformalDistribution(1, 2)} 40 //}; 41 42 //TestData = new DatasetDefinition(2667, inputVariables); 43 //TrainingData = new DatasetDefinition(1333, inputVariables); 44 44 } 45 45 … … 54 54 #endregion 55 55 56 protected override double CalculateFunction(Dictionary<string, IList<double>> data , List<string> vars) {56 protected override double CalculateFunction(Dictionary<string, IList<double>> data) { 57 57 double x1 = data[vars.ElementAt(0)].Last(); 58 58 double x2 = data[vars.ElementAt(1)].Last(); … … 60 60 return (30 * (x1 - 1) * (x3 - 1)) / ((x1 - 10) * Math.Pow(x2, 2)); 61 61 } 62 63 public override List<string> InputVariable { 64 get { throw new NotImplementedException(); } 65 } 66 67 public override string TargetVariable { 68 get { throw new NotImplementedException(); } 69 } 70 71 public override Data.IntRange TrainingPartition { 72 get { throw new NotImplementedException(); } 73 } 74 75 public override Data.IntRange TestPartition { 76 get { throw new NotImplementedException(); } 77 } 78 79 protected override Dictionary<string, IList<double>> GenerateInput(Dictionary<string, IList<double>> data) { 80 throw new NotImplementedException(); 81 } 62 82 } 63 83 } -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RationalPolynomialTwo.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public RationalPolynomialTwo() { 34 33 Name = "RationalPolynomial2 (2d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(0, 6)},38 {"x2", new IntRange(0, 6)}39 };40 AmountOfPoints = 4000;41 TrainingPartition = new IntRange(0, 2667);42 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x1", new IntRange(0, 6)}, 37 // {"x2", new IntRange(0, 6)} 38 //}; 39 //AmountOfPoints = 4000; 40 //TrainingPartition = new IntRange(0, 2667); 41 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 43 42 } 44 43 -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RippleFunction.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public RippleFunction() { 34 33 Name = "Ripple function (2d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(0, 6)},38 {"x2", new IntRange(0, 6)}39 };40 AmountOfPoints = 4000;41 TrainingPartition = new IntRange(0, 2667);42 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x1", new IntRange(0, 6)}, 37 // {"x2", new IntRange(0, 6)} 38 //}; 39 //AmountOfPoints = 4000; 40 //TrainingPartition = new IntRange(0, 2667); 41 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 43 42 } 44 43 -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SalustowiczFunctionOneDimensional.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public SalustowiczFunctionOneDimensional() { 34 33 Name = "Salustowicz function (1d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x", new IntRange(0, 10)}38 };39 AmountOfPoints = 4000;40 TrainingPartition = new IntRange(0, 2667);41 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x", new IntRange(0, 10)} 37 //}; 38 //AmountOfPoints = 4000; 39 //TrainingPartition = new IntRange(0, 2667); 40 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 42 41 } 43 42 -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SalustowiczFunctionTwoDimensional.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public SalustowiczFunctionTwoDimensional() { 34 33 Name = "Salustowicz function (2d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(0, 10)},38 {"x2", new IntRange(0, 10)}39 };40 AmountOfPoints = 4000;41 TrainingPartition = new IntRange(0, 2667);42 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x1", new IntRange(0, 10)}, 37 // {"x2", new IntRange(0, 10)} 38 //}; 39 //AmountOfPoints = 4000; 40 //TrainingPartition = new IntRange(0, 2667); 41 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 43 42 } 44 43 -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SineCosineFunction.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public SineCosineFunction() { 34 33 Name = "SineCosine function (2d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(0, 6)},38 {"x2", new IntRange(0, 6)}39 };40 AmountOfPoints = 4000;41 TrainingPartition = new IntRange(0, 2667);42 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x1", new IntRange(0, 6)}, 37 // {"x2", new IntRange(0, 6)} 38 //}; 39 //AmountOfPoints = 4000; 40 //TrainingPartition = new IntRange(0, 2667); 41 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 43 42 } 44 43 -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/UnwrappedBallFunction.cs
r6968 r6991 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Benchmarks { … … 33 32 public UnwrappedBallFunction() { 34 33 Name = "UnwrappedBall function (1d)"; 35 TargetVariable = "y";36 Inputvariables = new Dictionary<string, IntRange>() {37 {"x1", new IntRange(-2, 8)}38 };39 AmountOfPoints = 4000;40 TrainingPartition = new IntRange(0, 2667);41 TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints);34 //TargetVariable = "y"; 35 //Inputvariables = new Dictionary<string, IntRange>() { 36 // {"x1", new IntRange(-2, 8)} 37 //}; 38 //AmountOfPoints = 4000; 39 //TrainingPartition = new IntRange(0, 2667); 40 //TestPartition = new IntRange(TrainingPartition.End, AmountOfPoints); 42 41 } 43 42
Note: See TracChangeset
for help on using the changeset viewer.