Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/FeatureSelection/FeatureSelectionInstanceProvider.cs @ 16462

Last change on this file since 16462 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Linq;
25using HeuristicLab.Data;
26using HeuristicLab.Problems.DataAnalysis;
27using HeuristicLab.Random;
28
29namespace HeuristicLab.Problems.Instances.DataAnalysis {
30  public class FeatureSelectionInstanceProvider : ArtificialRegressionInstanceProvider {
31    public override string Name {
32      get { return "Feature Selection Problems"; }
33    }
34    public override string Description {
35      get { return "A set of artificial feature selection benchmark problems"; }
36    }
37    public override Uri WebLink {
38      get { return new Uri("http://dev.heuristiclab.com"); }
39    }
40    public override string ReferencePublication {
41      get { return ""; }
42    }
43    public int Seed { get; private set; }
44
45    public FeatureSelectionInstanceProvider() : base() {
46      Seed = (int)DateTime.Now.Ticks;
47    }
48
49    public FeatureSelectionInstanceProvider(int seed) : base() {
50      Seed = seed;
51    }
52
53
54    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
55      var sizes = new int[] { 50, 100, 200 };
56      var pp = new double[] { 0.1, 0.25, 0.5 };
57      var noiseRatios = new double[] { 0.01, 0.05, 0.1, 0.2 };
58      var rand = new MersenneTwister((uint)Seed); // use fixed seed for deterministic problem generation
59
60      return (from size in sizes
61              from p in pp
62              from noiseRatio in noiseRatios
63              let instanceSeed = rand.Next()
64              let mt = new MersenneTwister((uint)instanceSeed)
65              let xGenerator = new NormalDistributedRandom(mt, 0, 1)
66              let weightGenerator = new UniformDistributedRandom(mt, 0, 10)
67              select new FeatureSelection(size, p, noiseRatio, xGenerator, weightGenerator))
68              .Cast<IDataDescriptor>()
69              .ToList();
70    }
71
72    public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
73      var featureSelectionDescriptor = descriptor as FeatureSelection;
74      if (featureSelectionDescriptor == null) throw new ArgumentException("FeatureSelectionInstanceProvider expects an FeatureSelection data descriptor.");
75      // base call generates a regression problem data
76      var regProblemData = base.LoadData(featureSelectionDescriptor);
77      var problemData =
78        new FeatureSelectionRegressionProblemData(
79          regProblemData.Dataset, regProblemData.AllowedInputVariables, regProblemData.TargetVariable,
80          featureSelectionDescriptor.SelectedFeatures, featureSelectionDescriptor.Weights,
81          featureSelectionDescriptor.OptimalRSquared);
82
83      // copy values from regProblemData to feature selection problem data
84      problemData.Name = regProblemData.Name;
85      problemData.Description = regProblemData.Description;
86      problemData.TrainingPartition.Start = regProblemData.TrainingPartition.Start;
87      problemData.TrainingPartition.End = regProblemData.TrainingPartition.End;
88      problemData.TestPartition.Start = regProblemData.TestPartition.Start;
89      problemData.TestPartition.End = regProblemData.TestPartition.End;
90
91      return problemData;
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.