Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/22/14 16:53:31 (11 years ago)
Author:
pfleck
Message:
  • Added ProblemDataCreator for instancing a new DataAnalysisProblemData with changed Dataset etc.
  • Added export functionality to PreprocessingContext. (cloned Algorithm or Problem)
  • Commented out code in StatisticsLogic which breaks the build. :(
File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs

    r10382 r10383  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
    26 using HeuristicLab.Optimization;
    2727using HeuristicLab.Problems.DataAnalysis;
    2828
    2929namespace HeuristicLab.DataPreprocessing {
    30   internal class PreprocessingCloner {
     30  internal class ProblemDataCreator {
    3131
    3232    private readonly IPreprocessingContext context;
    3333
    34     public PreprocessingCloner(IPreprocessingContext context) {
     34    public ProblemDataCreator(IPreprocessingContext context) {
    3535      this.context = context;
    3636    }
    3737
    38     public IItem GenerateAlteredClone(IItem obj) {
    39       IPreprocessingData data = context.Data;
     38    public IDataAnalysisProblemData CreateProblemData() {
    4039
    41       Dataset dataset = data.ExportToDataset();
    42       var variables = new CheckedItemList<StringValue>(data.VariableNames.Select(s => new StringValue(s))).AsReadOnly();
     40      IDataAnalysisProblemData problemData = CloneProblemDataWithDataset();
    4341
     42      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      }
     51
     52      return problemData;
     53    }
     54
     55    private IDataAnalysisProblemData CloneProblemDataWithDataset() {
    4456      var cloner = new Cloner();
    4557
    46       cloner.RegisterClonedObject(context.DataAnalysisProblemData.Dataset, dataset);
    47       cloner.RegisterClonedObject(context.DataAnalysisProblemData.TrainingPartition, data.TrainingPartition);
    48       cloner.RegisterClonedObject(context.DataAnalysisProblemData.TestPartition, data.TestPartition);
    49       cloner.RegisterClonedObject(context.DataAnalysisProblemData.InputVariables, variables);
    50       if (context.Algorithm != null) {
    51         cloner.RegisterClonedObject(context.Algorithm.Runs, new RunCollection { OptimizerName = context.Algorithm.Name });
     58      var problemData = context.Problem.ProblemData;
     59
     60      Dataset dataset = context.Data.ExportToDataset();
     61
     62      cloner.RegisterClonedObject(problemData.Dataset, dataset);
     63
     64      return cloner.Clone(problemData);
     65    }
     66
     67    private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) {
     68      var ppData = context.Data;
     69
     70      problemData.TrainingPartition.Start = ppData.TrainingPartition.Start;
     71      problemData.TrainingPartition.End = ppData.TrainingPartition.End;
     72      problemData.TestPartition.Start = ppData.TestPartition.Start;
     73      problemData.TestPartition.End = ppData.TestPartition.End;
     74    }
     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));
    52104      }
    53105
    54       return cloner.Clone(obj);
     106      targetVariableParameter.ActualValue = validValues.FirstOrDefault(v => v.Value == oldTarget);
    55107    }
    56108  }
Note: See TracChangeset for help on using the changeset viewer.