Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9133


Ignore:
Timestamp:
01/09/13 14:56:57 (12 years ago)
Author:
sforsten
Message:

#2001:

  • removed IRealWorldRegressionDataDescriptor and RealWorldResourceRegressionDataDescriptor
  • simplified regression data descriptors as suggested by mkommend
Location:
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3
Files:
3 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj

    r9131 r9133  
    185185    <Compile Include="Regression\Nguyen\NguyenFunctionTwo.cs" />
    186186    <Compile Include="Regression\Nguyen\NguyenInstanceProvider.cs" />
    187     <Compile Include="Regression\RealWorld\IRealWorldRegressionDataDescriptor.cs" />
     187    <Compile Include="Regression\RealWorld\ChemicalOne.cs" />
     188    <Compile Include="Regression\RealWorld\Housing.cs" />
    188189    <Compile Include="Regression\RealWorld\RealWorldRegressionInstanceProvider.cs" />
    189     <Compile Include="Regression\RealWorld\RealWorldResourceRegressionDataDescriptor.cs" />
    190190    <Compile Include="Regression\RealWorld\Tower.cs" />
     191    <Compile Include="Regression\RegressionDataDescriptor.cs" />
    191192    <Compile Include="Regression\RegressionImportType.cs" />
    192193    <Compile Include="Regression\RegressionInstanceProvider.cs" />
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ArtificialRegressionDataDescriptor.cs

    r8825 r9133  
    2424
    2525namespace HeuristicLab.Problems.Instances.DataAnalysis {
    26   public abstract class ArtificialRegressionDataDescriptor : IDataDescriptor {
    27     public abstract string Name { get; }
    28     public abstract string Description { get; }
    29 
    30     protected abstract string TargetVariable { get; }
    31     protected abstract string[] VariableNames { get; }
    32     protected abstract string[] AllowedInputVariables { get; }
    33     protected abstract int TrainingPartitionStart { get; }
    34     protected abstract int TrainingPartitionEnd { get; }
    35     protected abstract int TestPartitionStart { get; }
    36     protected abstract int TestPartitionEnd { get; }
    37 
     26  public abstract class ArtificialRegressionDataDescriptor : RegressionDataDescriptor {
    3827    public IRegressionProblemData GenerateRegressionData() {
    3928      Dataset dataset = new Dataset(VariableNames, this.GenerateValues());
    40 
    41       RegressionProblemData regData = new RegressionProblemData(dataset, AllowedInputVariables, TargetVariable);
    42       regData.Name = this.Name;
    43       regData.Description = this.Description;
    44       regData.TrainingPartition.Start = this.TrainingPartitionStart;
    45       regData.TrainingPartition.End = this.TrainingPartitionEnd;
    46       regData.TestPartition.Start = this.TestPartitionStart;
    47       regData.TestPartition.End = this.TestPartitionEnd;
    48       return regData;
     29      return GenerateRegressionData(dataset);
    4930    }
    5031
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RealWorld/RealWorldRegressionInstanceProvider.cs

    r9131 r9133  
    2424using System.IO;
    2525using System.Linq;
    26 using HeuristicLab.Problems.DataAnalysis;
    2726using ICSharpCode.SharpZipLib.Zip;
    2827
     
    4746
    4847    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    49       List<IRealWorldRegressionDataDescriptor> descriptorList = new List<IRealWorldRegressionDataDescriptor>();
     48      List<ResourceRegressionDataDescriptor> descriptorList = new List<ResourceRegressionDataDescriptor>();
     49      descriptorList.Add(new ChemicalOne());
     50      descriptorList.Add(new Housing());
    5051      descriptorList.Add(new Tower());
    5152      var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
     
    5960          foreach (var entry in entries.OrderBy(x => x)) {
    6061            string prettyName = Path.GetFileNameWithoutExtension(entry);
    61             IRealWorldRegressionDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault();
     62            ResourceRegressionDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault();
    6263            if (desc != null) {
    63               yield return new RealWorldResourceRegressionDataDescriptor(prettyName, desc.Description, entry, desc.Training, desc.Test);
     64              desc.ResourceName = entry;
     65              yield return desc;
    6466            } else
    65               yield return new ResourceRegressionDataDescriptor(prettyName, Description, entry);
     67              throw new ArgumentNullException("No Descriptor could be found for this entry.");
    6668          }
    6769        }
    6870      }
    6971    }
    70 
    71     public override IRegressionProblemData LoadData(IDataDescriptor id) {
    72       var problem = base.LoadData(id);
    73 
    74       var descriptor = id as RealWorldResourceRegressionDataDescriptor;
    75 
    76       if (descriptor == null) {
    77         return problem;
    78       }
    79 
    80       problem.TrainingPartition.Start = descriptor.Training.Start;
    81       problem.TrainingPartition.End = descriptor.Training.End;
    82       problem.TestPartition.Start = descriptor.Test.Start;
    83       problem.TestPartition.End = descriptor.Test.End;
    84 
    85       return problem;
    86     }
    8772  }
    8873}
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RealWorld/Tower.cs

    r9131 r9133  
    2020#endregion
    2121
     22using System;
    2223
    23 using System;
    24 using HeuristicLab.Data;
    2524namespace HeuristicLab.Problems.Instances.DataAnalysis {
    26   public class Tower : IRealWorldRegressionDataDescriptor {
    27     public string Name { get { return "Tower"; } }
    28     public string Description {
     25  public class Tower : ResourceRegressionDataDescriptor {
     26    public override string Name { get { return "Tower"; } }
     27    public override string Description {
    2928      get {
    3029        return "Publication: Order of Nonlinearity as a Complexity Measure for Models " +
     
    3332      }
    3433    }
    35     public IntRange Training { get { return new IntRange(0, 3135); } }
    36     public IntRange Test { get { return new IntRange(3135, 4999); } }
     34    protected override string TargetVariable { get { return "towerResponse"; } }
     35    protected override string[] VariableNames {
     36      get { return new string[] { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "towerResponse" }; }
     37    }
     38    protected override string[] AllowedInputVariables {
     39      get { return new string[] { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25" }; }
     40    }
     41    protected override int TrainingPartitionStart { get { return 0; } }
     42    protected override int TrainingPartitionEnd { get { return 3135; } }
     43    protected override int TestPartitionStart { get { return 3135; } }
     44    protected override int TestPartitionEnd { get { return 4999; } }
    3745  }
    3846}
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ResourceRegressionDataDescriptor.cs

    r7849 r9133  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224
    2325namespace HeuristicLab.Problems.Instances.DataAnalysis {
    24   internal class ResourceRegressionDataDescriptor : IDataDescriptor {
    25     public string Name { get; internal set; }
    26     public string Description { get; internal set; }
     26  public abstract class ResourceRegressionDataDescriptor : RegressionDataDescriptor {
     27    internal string ResourceName { get; set; }
    2728
    28     internal string ResourceName { get; set; }
    29     internal ResourceRegressionDataDescriptor(string name, string description, string resourceName) {
    30       Name = name;
    31       Description = description;
    32       ResourceName = resourceName;
     29    public bool CheckVariableNames(IEnumerable<string> VariableNames) {
     30      return this.VariableNames.All(x => VariableNames.Contains(x));
    3331    }
    3432  }
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ResourceRegressionInstanceProvider.cs

    r7965 r9133  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Globalization;
    2524using System.IO;
     
    3534    protected abstract string FileName { get; }
    3635
    37     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    38       var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
    39       if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    40         using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    41           IList<string> entries = new List<string>();
    42           ZipEntry curEntry;
    43           while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {
    44             entries.Add(curEntry.Name);
    45           }
    46           foreach (var entry in entries.OrderBy(x => x)) {
    47             yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry);
    48           }
    49         }
    50       }
    51     }
     36    //public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
     37    //  var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
     38    //  if (!String.IsNullOrEmpty(solutionsArchiveName)) {
     39    //    using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
     40    //      IList<string> entries = new List<string>();
     41    //      ZipEntry curEntry;
     42    //      while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {
     43    //        entries.Add(curEntry.Name);
     44    //      }
     45    //      foreach (var entry in entries.OrderBy(x => x)) {
     46    //        yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry);
     47    //      }
     48    //    }
     49    //  }
     50    //}
    5251
    5352    public override IRegressionProblemData LoadData(IDataDescriptor id) {
     
    7069
    7170        Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    72         string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last();
    73         IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar));
     71        if (!descriptor.CheckVariableNames(csvFileParser.VariableNames)) {
     72          throw new ArgumentException("Parsed file contains variables which are not in the descriptor.");
     73        }
    7474
    75         IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
    76 
    77         int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    78         regData.TrainingPartition.Start = 0;
    79         regData.TrainingPartition.End = trainingPartEnd;
    80         regData.TestPartition.Start = trainingPartEnd;
    81         regData.TestPartition.End = csvFileParser.Rows;
    82 
    83         regData.Name = descriptor.Name;
    84         regData.Description = descriptor.Description;
    85         return regData;
     75        return descriptor.GenerateRegressionData(dataset);
    8676      }
    8777    }
Note: See TracChangeset for help on using the changeset viewer.