Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6991


Ignore:
Timestamp:
11/14/11 17:08:32 (12 years ago)
Author:
sforsten
Message:

#1669: First version with a simpler design as discussed with Michael Kommenda has been implemented and will be tested soon. Currently only the KotanchekFunction.cs is changed accordingly. Other benchmarks are going to follow soon.

The classes for the different distributions are not needed any longer. Static methods in RegressionBenchmark replace them.

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  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections;
    2423using System.Collections.Generic;
     
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Data;
     27using HeuristicLab.Random;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
    3030  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
    3138
    3239    protected RegressionBenchmark() { }
     
    3542    }
    3643
    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);
    4445
    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);
    4647
    4748    public IDataAnalysisProblemData GenerateProblemData() {
    48       //prepare dictionary
    4949      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) {
    5252        data.Add(variable, new List<double>());
    5353      }
    5454
    55       data = CalculateValues(data);
     55      data = GenerateInput(data);
    5656
    5757      List<IList> values = new List<IList>();
     
    6565      RegressionProblemData problemData = new RegressionProblemData(dataset, dataset.DoubleVariables.Skip(1), dataset.DoubleVariables.First());
    6666
    67       #region set ProblemData specific parameters
    6867      problemData.Name = "Data generated for benchmark problem \"" + this.Name + "\"";
    6968
    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       }
    7969
    8070      problemData.TestPartition.Start = this.TestPartition.Start;
    8171      problemData.TestPartition.End = this.TestPartition.End;
     72
    8273      problemData.TrainingPartition.Start = this.TrainingPartition.Start;
    8374      problemData.TrainingPartition.End = this.TrainingPartition.End;
    84       #endregion
    8575
    8676      return problemData;
    8777    }
    8878
    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)));
    9897
    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);
    100112      }
    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();
    102145    }
    103146  }
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/HeuristicLab.Problems.DataAnalysis.Benchmarks-3.4.csproj

    r6973 r6991  
    4949  <ItemGroup>
    5050    <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" />
    5751    <Compile Include="Plugin.cs" />
    5852    <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" />
    6353    <Compile Include="RegressionBenchmarks\KotanchekFunction.cs" />
    6454    <Compile Include="Generator\RegressionBenchmark.cs" />
    65     <Compile Include="RegressionBenchmarks\SalustowiczFunctionOneDimensional.cs" />
    66     <Compile Include="RegressionBenchmarks\SineCosineFunction.cs" />
    67     <Compile Include="RegressionBenchmarks\UnwrappedBallFunction.cs" />
    6855  </ItemGroup>
    6956  <ItemGroup>
     
    9683      <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
    9784    </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>
    9889  </ItemGroup>
    9990  <ItemGroup>
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/KotanchekFunction.cs

    r6968 r6991  
    3131  public class KotanchekFunction : RegressionBenchmark {
    3232
     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
    3354    public KotanchekFunction() {
    3455      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);
    4356    }
    4457
     
    5366    #endregion
    5467
    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;
    5985    }
    6086  }
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RationalPolynomial.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3231
    3332    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);
    4444    }
    4545
     
    5454    #endregion
    5555
    56     protected override double CalculateFunction(Dictionary<string, IList<double>> data, List<string> vars) {
     56    protected override double CalculateFunction(Dictionary<string, IList<double>> data) {
    5757      double x1 = data[vars.ElementAt(0)].Last();
    5858      double x2 = data[vars.ElementAt(1)].Last();
     
    6060      return (30 * (x1 - 1) * (x3 - 1)) / ((x1 - 10) * Math.Pow(x2, 2));
    6161    }
     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    }
    6282  }
    6383}
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RationalPolynomialTwo.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public RationalPolynomialTwo() {
    3433      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);
    4342    }
    4443
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/RippleFunction.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public RippleFunction() {
    3433      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);
    4342    }
    4443
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SalustowiczFunctionOneDimensional.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public SalustowiczFunctionOneDimensional() {
    3433      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);
    4241    }
    4342
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SalustowiczFunctionTwoDimensional.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public SalustowiczFunctionTwoDimensional() {
    3433      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);
    4342    }
    4443
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/SineCosineFunction.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public SineCosineFunction() {
    3433      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);
    4342    }
    4443
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/UnwrappedBallFunction.cs

    r6968 r6991  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
     
    3332    public UnwrappedBallFunction() {
    3433      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);
    4241    }
    4342
Note: See TracChangeset for help on using the changeset viewer.