Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/PennML/PennMLRegressionInstanceProvider.cs @ 17414

Last change on this file since 17414 was 17414, checked in by pfleck, 4 years ago

#3040 Started adding UCI time series regression benchmarks.
Adapted parser (extracted format options & added parsing for double vectors).

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.IO;
25using System.IO.Compression;
26using System.Linq;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Problems.Instances.DataAnalysis {
30  public class PennMLRegressionInstanceProvider : ResourceRegressionInstanceProvider {
31    public override string Name {
32      get { return "PennML Regression Problems"; }
33    }
34
35    public override string Description {
36      get { return "A set of datasets used for benchmarking symbolic regression algorithms."; }
37    }
38
39    public override Uri WebLink {
40      get { return new Uri("https://github.com/EpistasisLab/penn-ml-benchmarks"); }
41    }
42
43    public override string ReferencePublication {
44      get { return "Patryk Orzechowski, William La Cava, Jason H. Moore - Where are we now? A large benchmark study of recent symbolic regression methods"; }
45    }
46
47    protected override string FileName {
48      get { return "PennML"; }
49    }
50
51    // the reference publication uses 75% of the samples in each of the datasets for training and the remaining 25% for testing
52    private const double trainTestSplit = 0.75;
53
54    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
55      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
56      using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
57        foreach (var entry in instancesZipFile.Entries) {
58          var formatOptions = GetFormatOptions(entry);
59
60          using (var stream = entry.Open()) {
61            using (var reader = new StreamReader(stream)) {
62              var header = reader.ReadLine(); // read the first line
63
64              // by convention each dataset from the PennML collection reserves the last column for the target
65              var variableNames = header.Split(formatOptions.ColumnSeparator);
66              var allowedInputVariables = variableNames.Take(variableNames.Length - 1);
67              var target = variableNames.Last();
68
69              // count lines
70              int lines = 0; while (reader.ReadLine() != null) lines++;
71
72              var trainEnd = (int)Math.Round(lines * trainTestSplit);
73              var trainRange = new IntRange(0, trainEnd);
74              var testRange = new IntRange(trainEnd, lines);
75
76              var descriptor = new PennMLRegressionDataDescriptor(entry.Name, variableNames, allowedInputVariables, target, trainRange, testRange);
77              yield return descriptor;
78            }
79          }
80        }
81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.