Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/24/12 16:37:40 (13 years ago)
Author:
sforsten
Message:

#1784:

  • deleted ClassificationData and RegressionData. RegressionProblemData and ClassificationProblemData are used instead
  • deleted not needed Transformer
  • ValueGenerator is now a static class and yield return is used return IEnumerable
Location:
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionDataDescriptor.cs

    r7682 r7759  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Problems.DataAnalysis;
     24
    2325namespace HeuristicLab.Problems.Instances.Regression {
    2426  public abstract class ArtificialRegressionDataDescriptor : IDataDescriptor {
     
    3436    protected abstract int TestPartitionEnd { get; }
    3537
    36     public RegressionData GenerateRegressionData() {
    37       RegressionData regData = new RegressionData();
     38    public RegressionProblemData GenerateRegressionData() {
     39      Dataset dataset = new Dataset(InputVariables, this.GenerateValues());
     40
     41      RegressionProblemData regData = new RegressionProblemData(dataset, AllowedInputVariables, TargetVariable);
    3842      regData.Name = this.Name;
    3943      regData.Description = this.Description;
    40       regData.InputVariables = this.InputVariables;
    41       regData.AllowedInputVariables = this.AllowedInputVariables;
    42       regData.TargetVariable = this.TargetVariable;
    43       regData.Values = Transformer.Transformation(this.GenerateValues());
    44       regData.TrainingPartitionStart = this.TrainingPartitionStart;
    45       regData.TrainingPartitionEnd = this.TrainingPartitionEnd;
    46       regData.TestPartitionStart = this.TestPartitionStart;
    47       regData.TestPartitionEnd = this.TestPartitionEnd;
     44      regData.TrainingPartition.Start = this.TrainingPartitionStart;
     45      regData.TrainingPartition.End = this.TrainingPartitionEnd;
     46      regData.TestPartition.Start = this.TestPartitionStart;
     47      regData.TestPartition.End = this.TestPartitionEnd;
    4848      return regData;
    4949    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionInstanceProvider.cs

    r7664 r7759  
    2020#endregion
    2121
     22using HeuristicLab.Problems.DataAnalysis;
    2223
    2324namespace HeuristicLab.Problems.Instances.Regression {
    2425  public abstract class ArtificialRegressionInstanceProvider : RegressionInstanceProvider {
    25     public override RegressionData LoadData(IDataDescriptor descriptor) {
     26    public override RegressionProblemData LoadData(IDataDescriptor descriptor) {
    2627      return ((ArtificialRegressionDataDescriptor)descriptor).GenerateRegressionData();
    2728    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/HeuristicLab.Problems.Instances.Regression-3.4.csproj

    r7687 r7759  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <Private>False</Private>
     42    </Reference>
    4043    <Reference Include="HeuristicLab.Common-3.3">
    4144      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     
    4447    <Reference Include="HeuristicLab.Core-3.3">
    4548      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     49      <Private>False</Private>
     50    </Reference>
     51    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4652      <Private>False</Private>
    4753    </Reference>
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RealWorld/RealWorldInstanceProvider.cs

    r7758 r7759  
    3939    }
    4040
    41     protected override string FileName { get { return "RealWorld"; } }
     41    protected override string FileExtension { get { return "RealWorld"; } }
    4242  }
    4343}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs

    r7682 r7759  
    2626using System.Linq;
    2727using System.Text;
     28using HeuristicLab.Problems.DataAnalysis;
    2829
    2930namespace HeuristicLab.Problems.Instances.Regression {
    30   public abstract class RegressionInstanceProvider : IProblemInstanceProvider<RegressionData> {
    31     public RegressionData LoadData(string path) {
     31  public abstract class RegressionInstanceProvider : IProblemInstanceProvider<RegressionProblemData> {
     32    public RegressionProblemData LoadData(string path) {
    3233      TableFileParser csvFileParser = new TableFileParser();
    3334      csvFileParser.Parse(path);
    3435
    35       RegressionData regData = new RegressionData();
     36      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     37      string targetVar = csvFileParser.VariableNames.Last();
     38      IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     39
     40      RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
    3641      int pos = path.LastIndexOf('\\');
    3742      if (pos < 0)
     
    4146        regData.Name = path.Substring(pos, path.Length - pos);
    4247      }
    43       regData.InputVariables = new List<string>(csvFileParser.VariableNames).ToArray();
    44       regData.TargetVariable = csvFileParser.VariableNames.Last();
    45       regData.AllowedInputVariables = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).ToArray();
    46       //convert to multidimensional array
    47       List<IList> values = csvFileParser.Values;
    48       regData.Values = new double[values.First().Count, values.Count];
    49       for (int i = 0; i < values.Count; i++) {
    50         for (int j = 0; j < values.First().Count; j++) {
    51           regData.Values[j, i] = (double)values[i][j];
    52         }
    53       }
    5448
    5549      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    56       regData.TrainingPartitionStart = 0;
    57       regData.TrainingPartitionEnd = trainingPartEnd;
    58       regData.TestPartitionStart = trainingPartEnd;
    59       regData.TestPartitionEnd = csvFileParser.Rows;
     50      regData.TrainingPartition.Start = 0;
     51      regData.TrainingPartition.End = trainingPartEnd;
     52      regData.TestPartition.Start = trainingPartEnd;
     53      regData.TestPartition.End = csvFileParser.Rows;
    6054      return regData;
    6155    }
    6256
    63     public void SaveData(RegressionData instance, string path) {
     57    public void SaveData(RegressionProblemData instance, string path) {
    6458      StringBuilder strBuilder = new StringBuilder();
    6559
     
    7064      strBuilder.AppendLine();
    7165
    72       double[,] values = instance.Values;
     66      Dataset dataset = instance.Dataset;
    7367
    74       for (int i = 0; i < values.GetLength(0); i++) {
    75         for (int j = 0; j < values.GetLength(1); j++) {
    76           strBuilder.Append(values[i, j] + ";");
     68      for (int i = 0; i < dataset.Rows; i++) {
     69        for (int j = 0; j < dataset.Columns; j++) {
     70          strBuilder.Append(dataset.GetValue(i, j) + ";");
    7771        }
    7872        strBuilder.Remove(strBuilder.Length - 1, 1);
     
    8680
    8781    public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    88     public abstract RegressionData LoadData(IDataDescriptor descriptor);
     82    public abstract RegressionProblemData LoadData(IDataDescriptor descriptor);
    8983
    9084    public abstract string Name { get; }
     
    9286    public abstract Uri WebLink { get; }
    9387    public abstract string ReferencePublication { get; }
    94 
    95     public IProblemInstanceConsumer<RegressionData> Consumer { get; set; }
    9688  }
    9789}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs

    r7758 r7759  
    2626using System.Reflection;
    2727using System.Text.RegularExpressions;
     28using HeuristicLab.Problems.DataAnalysis;
    2829using ICSharpCode.SharpZipLib.Zip;
    2930
     
    3132  public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider {
    3233
    33     protected abstract string FileName { get; }
     34    protected abstract string FileExtension { get; }
    3435
    3536    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    36       var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
     37      var solutionsArchiveName = GetResourceName(FileExtension + @"\.zip");
    3738      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    3839        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
     
    4344    }
    4445
    45     public override RegressionData LoadData(IDataDescriptor id) {
     46    public override RegressionProblemData LoadData(IDataDescriptor id) {
    4647      var descriptor = (ResourceRegressionDataDescriptor)id;
    4748
    48       RegressionData regData = LoadData(GetTempFileForResource(descriptor.ResourceName));
     49      RegressionProblemData regData = LoadData(GetTempFileForResource(descriptor.ResourceName));
    4950      regData.Name = descriptor.Name;
    5051      regData.Description = descriptor.Description;
     
    6667
    6768    private string GetTempFileForResource(string resourceName) {
    68       var instanceArchiveName = GetResourceName(FileName + @"\.zip");
     69      var instanceArchiveName = GetResourceName(FileExtension + @"\.zip");
    6970      using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    7071        var entry = instancesZipFile.GetEntry(resourceName);
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/TrentMcConaghy/TrentMcConaghyInstanceProvider.cs

    r7758 r7759  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
     25using HeuristicLab.Problems.DataAnalysis;
    2426
    2527namespace HeuristicLab.Problems.Instances.Regression {
     
    4345    }
    4446
    45     protected override string FileName { get { return "TrentMcConaghy"; } }
     47    protected override string FileExtension { get { return "TrentMcConaghy"; } }
    4648
    47     public override RegressionData LoadData(IDataDescriptor id) {
    48       RegressionData regData = base.LoadData(id);
    49 
    50       regData.TargetVariable = regData.InputVariables.First();
    51       regData.AllowedInputVariables = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).ToArray();
     49    public override RegressionProblemData LoadData(IDataDescriptor id) {
     50      RegressionProblemData regData = base.LoadData(id);
     51      string targetVar = regData.InputVariables.First().Value;
     52      IEnumerable<string> allowedInputVars = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).Select(x => x.Value);
     53      RegressionProblemData newRegData = new RegressionProblemData(regData.Dataset, allowedInputVars, targetVar);
    5254
    5355      return regData;
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ValueGenerator.cs

    r7698 r7759  
    2626using HeuristicLab.Random;
    2727namespace HeuristicLab.Problems.Instances.Regression {
    28   public class ValueGenerator {
    29     protected static FastRandom rand = new FastRandom();
     28  public static class ValueGenerator {
     29    private static FastRandom rand = new FastRandom();
    3030
    3131    public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth) {
    32       return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1))
    33                                       .Select(i => (start + i * stepWidth));
     32      int steps = (int)Math.Round(((end - start) / stepWidth) + 1);
     33      for (int i = 0; i < steps; i++)
     34        yield return start + i * stepWidth;
    3435    }
    3536
    3637    public static IEnumerable<double> GenerateUniformDistributedValues(int amount, double start, double end) {
    37       List<double> values = new List<double>();
    38       for (int i = 0; i < amount; i++) {
    39         values.Add(rand.NextDouble() * (end - start) + start);
    40       }
    41       return values;
     38      for (int i = 0; i < amount; i++)
     39        yield return rand.NextDouble() * (end - start) + start;
    4240    }
    4341
    4442    public static IEnumerable<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
    45       List<double> values = new List<double>();
    46       for (int i = 0; i < amount; i++) {
    47         values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
    48       }
    49       return values;
     43      for (int i = 0; i < amount; i++)
     44        yield return NormalDistributedRandom.NextDouble(rand, mu, sigma);
    5045    }
    5146
Note: See TracChangeset for help on using the changeset viewer.