Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10536 for branches


Ignore:
Timestamp:
03/05/14 13:46:33 (11 years ago)
Author:
pfleck
Message:
  • Removed cloning of ProblemData. Instead the new ProblemData is instanciated based on the old type.
Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs

    r10383 r10536  
    7979
    8080    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
    81       algorithm.Name = "Cloned " + algorithm.Name;
     81      algorithm.Name = algorithm.Name + "(Preprocessed)";
    8282      algorithm.Runs.Clear();
    8383
     
    8585    }
    8686
    87     private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup) where T : IItem {
     87    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
     88        where T : IItem {
    8889      var creator = new ProblemDataCreator(this);
    8990      var data = creator.CreateProblemData();
     
    9394      var problem = setup(clone);
    9495      problem.ProblemDataParameter.ActualValue = data;
    95       problem.Name = "Cloned " + problem.Name;
     96      problem.Name = "Preprocessed " + problem.Name;
    9697
    9798      return clone;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs

    r10383 r10536  
    2121
    2222using System;
    23 using System.Linq;
    24 using HeuristicLab.Common;
    25 using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     23using System.Collections.Generic;
    2724using HeuristicLab.Problems.DataAnalysis;
    2825
     
    3734
    3835    public IDataAnalysisProblemData CreateProblemData() {
     36      var oldProblemData = context.Problem.ProblemData;
    3937
    40       IDataAnalysisProblemData problemData = CloneProblemDataWithDataset();
     38      IDataAnalysisProblemData problemData = null;
     39
     40      var dataSet = context.Data.ExportToDataset();
     41      var inputVariables = context.Data.VariableNames;
     42
     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.");
     51      }
    4152
    4253      SetTrainingAndTestPartition(problemData);
    43 
    44       if (problemData is RegressionProblemData) {
    45         //SetRegressionData((RegressionProblemData)problemData);
    46       } else if (problemData is ClassificationProblemData) {
    47         //SetClassificationData((ClassificationProblemData)problemData);
    48       } else if (problemData is ClusteringProblemData) {
    49         throw new NotImplementedException();
    50       }
    5154
    5255      return problemData;
    5356    }
    5457
    55     private IDataAnalysisProblemData CloneProblemDataWithDataset() {
    56       var cloner = new Cloner();
     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    }
    5763
    58       var problemData = context.Problem.ProblemData;
     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    }
    5969
    60       Dataset dataset = context.Data.ExportToDataset();
    61 
    62       cloner.RegisterClonedObject(problemData.Dataset, dataset);
    63 
    64       return cloner.Clone(problemData);
     70    private IDataAnalysisProblemData CreateClusteringData(ClusteringProblemData oldProblemData, Dataset dataSet, IEnumerable<string> inputVariables) {
     71      return new ClusteringProblemData(dataSet, inputVariables);
    6572    }
    6673
     
    7380      problemData.TestPartition.End = ppData.TestPartition.End;
    7481    }
    75 
    76     private void SetRegressionData(RegressionProblemData regressionProblemData) {
    77       SetInputVariables(regressionProblemData, regressionProblemData.TargetVariable);
    78       SetTargetVariable(regressionProblemData.TargetVariableParameter);
    79     }
    80 
    81     private void SetClassificationData(ClassificationProblemData classificationProblemData) {
    82       SetInputVariables(classificationProblemData, classificationProblemData.TargetVariable);
    83       SetTargetVariable(classificationProblemData.TargetVariableParameter);
    84     }
    85 
    86     private void SetInputVariables(DataAnalysisProblemData problemData, string targetVariable) {
    87       //TODO: InputVariables Set is Readonly
    88 
    89       problemData.InputVariables.Clear();
    90 
    91       foreach (string variable in context.Data.VariableNames) {
    92         problemData.InputVariables.Add(new StringValue(variable), variable != targetVariable);
    93       }
    94     }
    95 
    96     private void SetTargetVariable(IConstrainedValueParameter<StringValue> targetVariableParameter) {
    97       string oldTarget = targetVariableParameter.Value.Value;
    98 
    99       var validValues = targetVariableParameter.ValidValues;
    100       validValues.Clear();
    101 
    102       foreach (string variable in context.Data.VariableNames.Where(x => context.Data.IsType<double>(x))) {
    103         validValues.Add(new StringValue(variable));
    104       }
    105 
    106       targetVariableParameter.ActualValue = validValues.FirstOrDefault(v => v.Value == oldTarget);
    107     }
    10882  }
    10983}
Note: See TracChangeset for help on using the changeset viewer.