[9093] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9093] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[9217] | 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 27 | using HeuristicLab.Random;
|
---|
[9093] | 28 |
|
---|
| 29 | namespace 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 | }
|
---|
[14229] | 43 | public int Seed { get; private set; }
|
---|
[9093] | 44 |
|
---|
[14228] | 45 | public FeatureSelectionInstanceProvider() : base() {
|
---|
| 46 | Seed = (int)DateTime.Now.Ticks;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public FeatureSelectionInstanceProvider(int seed) : base() {
|
---|
| 50 | Seed = seed;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
[9093] | 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 };
|
---|
[14228] | 58 | var rand = new MersenneTwister((uint)Seed); // use fixed seed for deterministic problem generation
|
---|
| 59 |
|
---|
[9217] | 60 | return (from size in sizes
|
---|
| 61 | from p in pp
|
---|
| 62 | from noiseRatio in noiseRatios
|
---|
[14228] | 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)
|
---|
[9217] | 67 | select new FeatureSelection(size, p, noiseRatio, xGenerator, weightGenerator))
|
---|
| 68 | .Cast<IDataDescriptor>()
|
---|
| 69 | .ToList();
|
---|
[9093] | 70 | }
|
---|
[9217] | 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 | }
|
---|
[9093] | 93 | }
|
---|
| 94 | }
|
---|