Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17401


Ignore:
Timestamp:
01/16/20 12:34:45 (4 years ago)
Author:
pfleck
Message:

#3040 Added parser for new benchmark data but did not commit the data yet (too large)

Location:
branches/3040_VectorBasedGP
Files:
1 added
5 edited
4 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r17369 r17401  
    123123      var vectorDiv = new VectorDivision();
    124124      var vectorSum = new VectorSum();
    125       var vectorAvg = new VectorAverage();
     125      var vectorAvg = new VectorMean();
    126126      #endregion
    127127
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17369 r17401  
    219219    <Compile Include="SymbolicDataAnalysisProblem.cs" />
    220220    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
    221     <Compile Include="Symbols\VectorAverage.cs" />
     221    <Compile Include="Symbols\VectorMean.cs" />
    222222    <Compile Include="Symbols\VectorSum.cs" />
    223223    <Compile Include="Symbols\VectorSubtraction.cs" />
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r17367 r17401  
    147147    public const byte VectorDiv = (byte)OpCode.VectorDiv;
    148148    public const byte VectorSum = (byte)OpCode.VectorSum;
    149     public const byte VectorAvg = (byte)OpCode.VectorAvg;
     149    public const byte VectorMean = (byte)OpCode.VectorAvg;
    150150
    151151
     
    210210      { typeof(VectorDivision), OpCodes.VectorDiv },
    211211      { typeof(VectorSum), OpCodes.VectorSum },
    212       { typeof(VectorAverage), OpCodes.VectorAvg }
     212      { typeof(VectorMean), OpCodes.VectorMean }
    213213    };
    214214
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r17400 r17401  
    536536            return v.Sum();
    537537          }
    538         case OpCodes.VectorAvg: {
     538        case OpCodes.VectorMean: {
    539539            DoubleVector v = VectorEvaluate(dataset, ref row, state);
    540540            return v.Mean();
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorMean.cs

    r17400 r17401  
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2727  [StorableType("85FF9A2E-207C-4008-BB8B-0C0363885443")]
    28   [Item("VectorAverage", "Symbol that represents the average function.")]
    29   public sealed class VectorAverage : Symbol {
     28  [Item("VectorMean", "Symbol that represents the mean function.")]
     29  public sealed class VectorMean : Symbol {
    3030    private const int minimumArity = 1;
    3131    private const int maximumArity = 1;
     
    3939
    4040    [StorableConstructor]
    41     private VectorAverage(StorableConstructorFlag _) : base(_) { }
    42     private VectorAverage(VectorAverage original, Cloner cloner) : base(original, cloner) { }
     41    private VectorMean(StorableConstructorFlag _) : base(_) { }
     42    private VectorMean(VectorMean original, Cloner cloner) : base(original, cloner) { }
    4343    public override IDeepCloneable Clone(Cloner cloner) {
    44       return new VectorAverage(this, cloner);
     44      return new VectorMean(this, cloner);
    4545    }
    46     public VectorAverage() : base("VectorAverage", "Symbol that represents the average function.") { }
     46    public VectorMean() : base("VectorMean", "Symbol that represents the mean function.") { }
    4747  }
    4848}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/TimeSeries/TimeSeriesDataDescriptor.cs

    r17393 r17401  
    2020#endregion
    2121
    22 using System;
     22namespace HeuristicLab.Problems.Instances.DataAnalysis {
     23  public class TimeSeriesDataDescriptor : IDataDescriptor {
     24    public string Name { get; }
     25    public string Description { get { return string.Empty; } }
    2326
    24 namespace HeuristicLab.Problems.Instances.DataAnalysis {
    25   public abstract class UCIDataDescriptor : ResourceClassificationDataDescriptor {
    26     public override string Name { get { return String.Format("{0}, {1}, {2}", Filename, Donor, Year); } }
    27     public abstract string Filename { get; }
    28     public abstract string Donor { get; }
    29     public abstract int Year { get; }
     27    internal string TrainingEntryName { get; }
     28    internal string TestEntryName { get; }
     29
     30    public TimeSeriesDataDescriptor(string name, string trainingEntryName, string testEntryName) {
     31      Name = name;
     32      TrainingEntryName = trainingEntryName;
     33      TestEntryName = testEntryName;
     34    }
    3035  }
    3136}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/TimeSeries/TimeSeriesInstanceProvider.cs

    r17393 r17401  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
     25using System.Collections.ObjectModel;
     26using System.Diagnostics;
     27using System.Globalization;
    2428using System.IO;
    2529using System.IO.Compression;
    2630using System.Linq;
     31using HeuristicLab.Problems.DataAnalysis;
    2732
    2833namespace HeuristicLab.Problems.Instances.DataAnalysis {
    29   public class UCIInstanceProvider : ResourceClassificationInstanceProvider {
    30     public override string Name {
    31       get { return "UCI Problems"; }
    32     }
     34  public abstract class TimeSeriesInstanceProvider : ResourceClassificationInstanceProvider {
     35    //public override string Name {
     36    //  get { return "TimeSeries (Univariate) Problems"; }
     37    //}
    3338    public override string Description {
    34       get {
    35         return "";
    36       }
     39      get { return "UEA & UCR TimeSeries Problems"; }
    3740    }
    3841    public override Uri WebLink {
    39       get { return new Uri("http://archive.ics.uci.edu/ml/datasets.html"); }
     42      get { return new Uri("http://www.timeseriesclassification.com/"); }
    4043    }
    4144    public override string ReferencePublication {
    42       get { return ""; }
     45      get { return "Anthony Bagnall, Jason Lines, William Vickers and Eamonn Keogh, The UEA & UCR Time Series Classification Repository, www.timeseriesclassification.com"; }
    4346    }
    4447
    45     protected override string FileName { get { return "UCI"; } }
     48    public override IClassificationProblemData LoadData(IDataDescriptor id) {
     49      var descriptor = (TimeSeriesDataDescriptor)id;
     50      using (var instancesZipFile = OpenZipArchive()) {
     51        var trainingEntry = instancesZipFile.GetEntry(descriptor.TrainingEntryName);
     52        var testEntry = instancesZipFile.GetEntry(descriptor.TestEntryName);
    4653
    47     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    48       List<UCIDataDescriptor> descriptorList = new List<UCIDataDescriptor>();
    49       descriptorList.Add(new Iris());
    50       descriptorList.Add(new Mammography());
    51       descriptorList.Add(new Parkinsons());
    52       descriptorList.Add(new Thyroid());
    53       descriptorList.Add(new Vertebral_3C());
    54       descriptorList.Add(new Wine());
    55       descriptorList.Add(new WisconsinDiagnosticBreastCancer());
    56       var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
    57       if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    58         using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName), ZipArchiveMode.Read)) {
    59           IList<string> entries = new List<string>();
    60           foreach (var curEntry in solutionsZipFile.Entries) {
    61             entries.Add(curEntry.Name);
    62           }
    63           foreach (var entry in entries.OrderBy(x => x)) {
    64             string filename = Path.GetFileNameWithoutExtension(entry);
    65             UCIDataDescriptor desc = descriptorList.Where(x => x.Filename.Equals(filename)).FirstOrDefault();
    66             if (desc != null) {
    67               desc.ResourceName = entry;
    68               yield return desc;
    69             } else
    70               throw new ArgumentNullException("No Descriptor could be found for this entry.");
    71           }
     54        if (trainingEntry == null || testEntry == null) {
     55          throw new InvalidOperationException("The training or test entry could not be found in the archive.");
     56        }
     57
     58        using (var trainingReader = new StreamReader(trainingEntry.Open()))
     59        using (var testReader = new StreamReader(testEntry.Open())) {
     60          ParseMetadata(trainingReader, out var inputVariables, out string targetVariable);
     61          ParseMetadata(testReader, out _, out _); // ignore outputs
     62
     63          // Read data
     64          var inputsData = new List<DoubleVector>[inputVariables.Count];
     65          for (int i = 0; i < inputsData.Length; i++) inputsData[i] = new List<DoubleVector>();
     66          var targetData = new List<double>();
     67          ReadData(trainingReader, inputsData, targetData, out int numTrainingRows);
     68          ReadData(testReader, inputsData, targetData, out int numTestRows);
     69
     70          // Build dataset
     71          var dataset = new Dataset(
     72            inputVariables.Concat(new[] { targetVariable }),
     73            inputsData.Cast<IList>().Concat(new[] { targetData })
     74          );
     75          Debug.Assert(dataset.Rows == numTrainingRows + numTestRows);
     76          Debug.Assert(dataset.Columns == inputVariables.Count + 1);
     77
     78          // Build problem data
     79          var problemData = new ClassificationProblemData(dataset, inputVariables, targetVariable) {
     80            Name = descriptor.Name
     81          };
     82          problemData.TrainingPartition.Start = 0;
     83          problemData.TrainingPartition.End = numTrainingRows;
     84          problemData.TestPartition.Start = numTrainingRows;
     85          problemData.TestPartition.End = numTrainingRows + numTestRows;
     86
     87          return problemData;
    7288        }
    7389      }
    7490    }
     91
     92    private static void ParseMetadata(StreamReader reader, out List<string> inputVariables, out string targetVariable) {
     93      int nrOfInputs = 0;
     94      bool dataStart = false;
     95      while (!reader.EndOfStream && !dataStart) {
     96        var line = reader.ReadLine();
     97        if (line.StartsWith("#")) {
     98          // Comment
     99        } else if (line.StartsWith("@")) {
     100          var splits = line.Split(' ');
     101          var type = splits.First();
     102          var arguments = splits.Skip(1).ToList();
     103          switch (type.ToLowerInvariant()) {
     104            case "@univariate":
     105              bool univariate = bool.Parse(arguments[0]);
     106              if (univariate)
     107                nrOfInputs = 1;
     108              break;
     109            case "@dimensions":
     110              int dimensions = int.Parse(arguments[0]);
     111              nrOfInputs = dimensions;
     112              break;
     113            case "@data":
     114              dataStart = true;
     115              break;
     116          }
     117        } else {
     118          throw new InvalidOperationException("A data section already occurred within metadata section.");
     119        }
     120      }
     121
     122      int digits = Math.Max((int)Math.Log10(nrOfInputs - 1) + 1, 1);
     123      inputVariables = Enumerable.Range(0, nrOfInputs)
     124        .Select(i => "X" + i.ToString("D" + digits))
     125        .ToList();
     126
     127      targetVariable = "Y";
     128    }
     129
     130    private static void ReadData(StreamReader reader, List<DoubleVector>[] inputsData, List<double> targetData, out int count) {
     131      count = 0;
     132      while (!reader.EndOfStream) {
     133        var line = reader.ReadLine();
     134        var variables = line.Split(':');
     135
     136        // parse all except last, which is the non-vector target
     137        for (int i = 0; i < variables.Length - 1; i++) {
     138          var variable = variables[i];
     139          var numbers = variable
     140            .Split(',')
     141            .Select(d => double.Parse(d, CultureInfo.InvariantCulture))
     142            .ToList();
     143          inputsData[i].Add(new DoubleVector(numbers));
     144        }
     145
     146        var target = double.Parse(variables[variables.Length - 1], CultureInfo.InvariantCulture);
     147        targetData.Add(target);
     148
     149        count++;
     150      }
     151    }
     152
     153    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
     154      using (var instancesZipFile = OpenZipArchive()) {
     155        var instances = GroupEntriesByInstance(instancesZipFile.Entries);
     156        var descriptors = instances.Select(instance => CreateDescriptor(instance.Key, instance.Value));
     157
     158        return descriptors.ToList();
     159      }
     160    }
     161
     162    private ZipArchive OpenZipArchive() {
     163      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
     164      return new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read);
     165    }
     166
     167    private static IDictionary<string, List<ZipArchiveEntry>> GroupEntriesByInstance(ReadOnlyCollection<ZipArchiveEntry> entries) {
     168      var topLevelEntries = entries.Where(entry => string.IsNullOrEmpty(entry.Name)).ToList();
     169
     170      return topLevelEntries.ToDictionary(
     171        entry => Path.GetDirectoryName(entry.FullName),
     172        entry => entries.Except(topLevelEntries).Where(subEntry => subEntry.FullName.StartsWith(entry.FullName)).ToList());
     173    }
     174
     175    private static TimeSeriesDataDescriptor CreateDescriptor(string name, List<ZipArchiveEntry> subEntries) {
     176      var trainingEntry = subEntries.Single(entry => entry.Name.EndsWith("_TRAIN.ts"));
     177      var testEntry = subEntries.Single(entry => entry.Name.EndsWith("_TEST.ts"));
     178      return new TimeSeriesDataDescriptor(name, trainingEntry.FullName, testEntry.FullName);
     179    }
    75180  }
    76181}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/TimeSeries/TimeSeriesMultivariateInstanceProvider.cs

    r17393 r17401  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    2722
    2823namespace HeuristicLab.Problems.Instances.DataAnalysis {
    29   public class UCIInstanceProvider : ResourceClassificationInstanceProvider {
     24  public class TimeSeriesMultivariateInstanceProvider : TimeSeriesInstanceProvider {
    3025    public override string Name {
    31       get { return "UCI Problems"; }
    32     }
    33     public override string Description {
    34       get {
    35         return "";
    36       }
    37     }
    38     public override Uri WebLink {
    39       get { return new Uri("http://archive.ics.uci.edu/ml/datasets.html"); }
    40     }
    41     public override string ReferencePublication {
    42       get { return ""; }
     26      get { return "TimeSeries (Multivariate)"; }
    4327    }
    4428
    45     protected override string FileName { get { return "UCI"; } }
    46 
    47     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    48       List<UCIDataDescriptor> descriptorList = new List<UCIDataDescriptor>();
    49       descriptorList.Add(new Iris());
    50       descriptorList.Add(new Mammography());
    51       descriptorList.Add(new Parkinsons());
    52       descriptorList.Add(new Thyroid());
    53       descriptorList.Add(new Vertebral_3C());
    54       descriptorList.Add(new Wine());
    55       descriptorList.Add(new WisconsinDiagnosticBreastCancer());
    56       var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
    57       if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    58         using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName), ZipArchiveMode.Read)) {
    59           IList<string> entries = new List<string>();
    60           foreach (var curEntry in solutionsZipFile.Entries) {
    61             entries.Add(curEntry.Name);
    62           }
    63           foreach (var entry in entries.OrderBy(x => x)) {
    64             string filename = Path.GetFileNameWithoutExtension(entry);
    65             UCIDataDescriptor desc = descriptorList.Where(x => x.Filename.Equals(filename)).FirstOrDefault();
    66             if (desc != null) {
    67               desc.ResourceName = entry;
    68               yield return desc;
    69             } else
    70               throw new ArgumentNullException("No Descriptor could be found for this entry.");
    71           }
    72         }
    73       }
    74     }
     29    protected override string FileName { get { return "TimeSeriesMultivariate"; } }
    7530  }
    7631}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/TimeSeries/TimeSeriesUnivariateInstanceProvider.cs

    r17393 r17401  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    2722
    2823namespace HeuristicLab.Problems.Instances.DataAnalysis {
    29   public class UCIInstanceProvider : ResourceClassificationInstanceProvider {
     24  public class TimeSeriesUnivariateInstanceProvider : TimeSeriesInstanceProvider {
    3025    public override string Name {
    31       get { return "UCI Problems"; }
    32     }
    33     public override string Description {
    34       get {
    35         return "";
    36       }
    37     }
    38     public override Uri WebLink {
    39       get { return new Uri("http://archive.ics.uci.edu/ml/datasets.html"); }
    40     }
    41     public override string ReferencePublication {
    42       get { return ""; }
     26      get { return "TimeSeries (Univariate)"; }
    4327    }
    4428
    45     protected override string FileName { get { return "UCI"; } }
    46 
    47     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    48       List<UCIDataDescriptor> descriptorList = new List<UCIDataDescriptor>();
    49       descriptorList.Add(new Iris());
    50       descriptorList.Add(new Mammography());
    51       descriptorList.Add(new Parkinsons());
    52       descriptorList.Add(new Thyroid());
    53       descriptorList.Add(new Vertebral_3C());
    54       descriptorList.Add(new Wine());
    55       descriptorList.Add(new WisconsinDiagnosticBreastCancer());
    56       var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
    57       if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    58         using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName), ZipArchiveMode.Read)) {
    59           IList<string> entries = new List<string>();
    60           foreach (var curEntry in solutionsZipFile.Entries) {
    61             entries.Add(curEntry.Name);
    62           }
    63           foreach (var entry in entries.OrderBy(x => x)) {
    64             string filename = Path.GetFileNameWithoutExtension(entry);
    65             UCIDataDescriptor desc = descriptorList.Where(x => x.Filename.Equals(filename)).FirstOrDefault();
    66             if (desc != null) {
    67               desc.ResourceName = entry;
    68               yield return desc;
    69             } else
    70               throw new ArgumentNullException("No Descriptor could be found for this entry.");
    71           }
    72         }
    73       }
    74     }
     29    protected override string FileName { get { return "TimeSeriesUnivariate"; } }
    7530  }
    7631}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj

    r17364 r17401  
    2424    <WarningLevel>4</WarningLevel>
    2525    <Prefer32Bit>false</Prefer32Bit>
    26     <LangVersion>6</LangVersion>
     26    <LangVersion>7.0</LangVersion>
    2727  </PropertyGroup>
    2828  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    3434    <WarningLevel>4</WarningLevel>
    3535    <Prefer32Bit>false</Prefer32Bit>
    36     <LangVersion>6</LangVersion>
     36    <LangVersion>7.0</LangVersion>
    3737  </PropertyGroup>
    3838  <PropertyGroup>
     
    134134    <Compile Include="Classification\ResourceClassificationDataDescriptor.cs" />
    135135    <Compile Include="Classification\ResourceClassificationInstanceProvider.cs" />
     136    <Compile Include="Classification\TimeSeries\TimeSeriesMultivariateInstanceProvider.cs" />
     137    <Compile Include="Classification\TimeSeries\TimeSeriesUnivariateInstanceProvider.cs" />
     138    <Compile Include="Classification\TimeSeries\TimeSeriesInstanceProvider.cs" />
     139    <Compile Include="Classification\TimeSeries\TimeSeriesDataDescriptor.cs" />
    136140    <Compile Include="Classification\UCI\WisconsinDiagnosticBreastCancer.cs" />
    137141    <Compile Include="Classification\UCI\Vertebral_3C.cs" />
     
    243247    <Compile Include="Regression\Various\SpatialCoevolution.cs" />
    244248    <Compile Include="Regression\Various\VariousInstanceProvider.cs" />
     249    <Compile Include="Regression\VectorData\AzzaliKorns5.cs" />
     250    <Compile Include="Regression\VectorData\AzzaliBenchmark3.cs" />
     251    <Compile Include="Regression\VectorData\AzzaliBenchmark2.cs" />
     252    <Compile Include="Regression\VectorData\AzzaliBenchmark1.cs" />
     253    <Compile Include="Regression\VectorData\RandomExtensions.cs" />
    245254    <Compile Include="Regression\VectorData\VariousInstanceProvider.cs" />
    246255    <Compile Include="Regression\VectorData\VectorDataTestOne.cs" />
     
    261270  <ItemGroup>
    262271    <EmbeddedResource Include="Classification\Data\UCI.zip" />
     272    <EmbeddedResource Include="Classification\Data\TimeSeriesMultivariate.zip" />
     273    <EmbeddedResource Include="Classification\Data\TimeSeriesUnivariate.zip" />
    263274    <None Include="HeuristicLab.snk" />
    264275    <None Include="Plugin.cs.frame" />
Note: See TracChangeset for help on using the changeset viewer.