[10310] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 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 |
|
---|
[10383] | 22 | using System;
|
---|
[10536] | 23 | using System.Collections.Generic;
|
---|
[10310] | 24 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10383] | 27 | internal class ProblemDataCreator {
|
---|
[10310] | 28 |
|
---|
| 29 | private readonly IPreprocessingContext context;
|
---|
| 30 |
|
---|
[10383] | 31 | public ProblemDataCreator(IPreprocessingContext context) {
|
---|
[10310] | 32 | this.context = context;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[10383] | 35 | public IDataAnalysisProblemData CreateProblemData() {
|
---|
[10536] | 36 | var oldProblemData = context.Problem.ProblemData;
|
---|
[10310] | 37 |
|
---|
[10536] | 38 | IDataAnalysisProblemData problemData = null;
|
---|
[10310] | 39 |
|
---|
[10536] | 40 | var dataSet = context.Data.ExportToDataset();
|
---|
| 41 | var inputVariables = context.Data.VariableNames;
|
---|
[10383] | 42 |
|
---|
[10536] | 43 | if (oldProblemData is RegressionProblemData) {
|
---|
| 44 | problemData = CreateRegressionData((RegressionProblemData)oldProblemData, dataSet, inputVariables);
|
---|
| 45 | } else if (oldProblemData is ClassificationProblemData) {
|
---|
| 46 | problemData = CreateClassificationData((ClassificationProblemData)oldProblemData, dataSet, inputVariables);
|
---|
| 47 | } else if (oldProblemData is ClusteringProblemData) {
|
---|
| 48 | problemData = CreateClusteringData((ClusteringProblemData)oldProblemData, dataSet, inputVariables);
|
---|
| 49 | } else {
|
---|
| 50 | throw new NotImplementedException("The type of the DataAnalysisProblemData is not supported.");
|
---|
[10383] | 51 | }
|
---|
| 52 |
|
---|
[10536] | 53 | SetTrainingAndTestPartition(problemData);
|
---|
| 54 |
|
---|
[10383] | 55 | return problemData;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[10536] | 58 | private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) {
|
---|
| 59 | var targetVariable = oldProblemData.TargetVariable;
|
---|
| 60 | // target variable must be double and must exist in the new dataset
|
---|
| 61 | return new RegressionProblemData(dataSet, inputVariables, targetVariable);
|
---|
| 62 | }
|
---|
[10310] | 63 |
|
---|
[10536] | 64 | private IDataAnalysisProblemData CreateClassificationData(ClassificationProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) {
|
---|
| 65 | var targetVariable = oldProblemData.TargetVariable;
|
---|
| 66 | // target variable must be double and must exist in the new dataset
|
---|
| 67 | return new ClassificationProblemData(dataSet, inputVariables, targetVariable);
|
---|
| 68 | }
|
---|
[10383] | 69 |
|
---|
[10536] | 70 | private IDataAnalysisProblemData CreateClusteringData(ClusteringProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) {
|
---|
| 71 | return new ClusteringProblemData(dataSet, inputVariables);
|
---|
[10383] | 72 | }
|
---|
| 73 |
|
---|
| 74 | private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) {
|
---|
| 75 | var ppData = context.Data;
|
---|
| 76 |
|
---|
| 77 | problemData.TrainingPartition.Start = ppData.TrainingPartition.Start;
|
---|
| 78 | problemData.TrainingPartition.End = ppData.TrainingPartition.End;
|
---|
| 79 | problemData.TestPartition.Start = ppData.TestPartition.Start;
|
---|
| 80 | problemData.TestPartition.End = ppData.TestPartition.End;
|
---|
| 81 | }
|
---|
[10310] | 82 | }
|
---|
| 83 | }
|
---|