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. :(
Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
Files:
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj

    r10380 r10383  
    9595    <Compile Include="Interfaces\IManipulationLogic.cs" />
    9696    <Compile Include="Interfaces\ITransformationLogic.cs" />
    97     <Compile Include="PreprocessingCloner.cs" />
     97    <Compile Include="ProblemDataCreator.cs" />
    9898    <Compile Include="Views\FilterView.cs">
    9999      <SubType>UserControl</SubType>
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataPreprocessorStarter.cs

    r10307 r10383  
    3434    public void Start(IDataAnalysisProblemData problemData, View currentView) {
    3535      IAlgorithm algorithm;
    36       IProblem problem;
     36      IDataAnalysisProblem problem;
    3737      IItem parentItem = GetMostOuterContent(currentView, out algorithm, out problem);
    38       var context = new PreprocessingContext(problemData, parentItem, algorithm, problem);
     38      var context = new PreprocessingContext(problemData, algorithm, problem);
    3939      MainFormManager.MainForm.ShowContent(context);
    4040    }
    4141
    42     private IItem GetMostOuterContent(Control control, out IAlgorithm algorithm, out IProblem problem) {
     42    private IItem GetMostOuterContent(Control control, out IAlgorithm algorithm, out IDataAnalysisProblem problem) {
    4343      algorithm = null;
    4444      problem = null;
     
    5151            algorithm = (IAlgorithm)itemView.Content;
    5252          }
    53           if (itemView.Content is IProblem) {
    54             problem = (IProblem)itemView.Content;
     53          if (itemView.Content is IDataAnalysisProblem) {
     54            problem = (IDataAnalysisProblem)itemView.Content;
    5555          }
    5656        }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs

    r10307 r10383  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2728namespace HeuristicLab.DataPreprocessing {
    2829  [Item("PreprocessingContext", "PreprocessingContext")]
    29   public class PreprocessingContext : Item, IPreprocessingContext {
    30     public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IItem parentItem, IAlgorithm algorithm, IProblem problem) {
     30  public class PreprocessingContext
     31    : Item, IPreprocessingContext {
     32
     33    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
    3134      Data = new PreprocessingData(dataAnalysisProblemData);
    32       ParentItem = parentItem;
    3335      DataAnalysisProblemData = dataAnalysisProblemData;
    3436      Algorithm = algorithm;
     
    3941      : base(original, cloner) {
    4042      Data = cloner.Clone(original.Data);
    41       ParentItem = original.ParentItem;
    4243      DataAnalysisProblemData = original.DataAnalysisProblemData;
    4344      Algorithm = original.Algorithm;
     
    4748    public IPreprocessingData Data { get; private set; }
    4849
    49     /// <summary>
    50     /// Parent algorithm, if available, or problem.
    51     /// </summary>
    52     public IItem ParentItem { get; private set; }
    53 
    5450    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
    5551
    5652    public IAlgorithm Algorithm { get; private set; }
    5753
    58     public IProblem Problem { get; private set; }
     54    public IDataAnalysisProblem Problem { get; private set; }
    5955
    6056    public override IDeepCloneable Clone(Cloner cloner) {
    6157      return new PreprocessingContext(this, cloner);
    6258    }
     59
     60    public IItem ExportAlgorithmOrProblem() {
     61      if (Algorithm != null) {
     62        return ExportAlgorithm();
     63      } else {
     64        return ExportProblem();
     65      }
     66    }
     67
     68    public IProblem ExportProblem() {
     69      return Export(Problem, SetupProblem);
     70    }
     71
     72    private IDataAnalysisProblem SetupProblem(IProblem problem) {
     73      return (IDataAnalysisProblem)problem;
     74    }
     75
     76    public IAlgorithm ExportAlgorithm() {
     77      return Export(Algorithm, SetupAlgorithm);
     78    }
     79
     80    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
     81      algorithm.Name = "Cloned " + algorithm.Name;
     82      algorithm.Runs.Clear();
     83
     84      return (IDataAnalysisProblem)algorithm.Problem;
     85    }
     86
     87    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup) where T : IItem {
     88      var creator = new ProblemDataCreator(this);
     89      var data = creator.CreateProblemData();
     90
     91      var clone = (T)original.Clone(new Cloner());
     92
     93      var problem = setup(clone);
     94      problem.ProblemDataParameter.ActualValue = data;
     95      problem.Name = "Cloned " + problem.Name;
     96
     97      return clone;
     98    }
    6399  }
    64100}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/StatisticsLogic.cs

    r10381 r10383  
    11using System;
     2using System.Collections.Generic;
    23using System.Linq;
    34using HeuristicLab.Common;
    4 using System.Collections.Generic;
    55
    66namespace HeuristicLab.DataPreprocessing {
     
    7575    }
    7676
    77     public DateTime GetMedianDateTime(int columnIndex)
    78     {
     77    public DateTime GetMedianDateTime(int columnIndex) {
    7978      DateTime median = new DateTime();
    80       if (preprocessingData.IsType<DateTime>(columnIndex))
    81       {
    82           median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median());
     79      if (preprocessingData.IsType<DateTime>(columnIndex)) {
     80        median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median());
    8381      }
    8482      return median;
    8583    }
    8684
    87     public DateTime GetAverageDateTime(int columnIndex)
    88     {
     85    public DateTime GetAverageDateTime(int columnIndex) {
    8986      DateTime avg = new DateTime();
    90       if (preprocessingData.IsType<DateTime>(columnIndex))
    91       {
    92           avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average());   
     87      if (preprocessingData.IsType<DateTime>(columnIndex)) {
     88        avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average());
    9389      }
    9490      return avg;
     
    107103    public double GetStandardDeviation(int columnIndex) {
    108104      double stdDev = double.NaN;
     105      //TODO: fix me
     106      /*
    109107      if (preprocessingData.IsType<double>(columnIndex)) {
    110108        stdDev = preprocessingData.GetValues<double>(columnIndex).StandardDeviation();
     
    113111        stdDev = GetDateTimeAsSeconds(variableName).StandardDeviation();
    114112      }
     113      */
    115114      return stdDev;
    116115    }
    117116
    118117    public double GetVariance(int columnIndex) {
    119        double variance = double.NaN;
    120 
     118      double variance = double.NaN;
     119      //TODO: fix me
     120      /*
    121121      if (preprocessingData.IsType<double>(columnIndex)) {
    122122        variance = preprocessingData.GetValues<double>(columnIndex).Variance();
     
    125125        variance = GetDateTimeAsSeconds(variableName).Variance();
    126126      }
     127      */
    127128      return variance;
    128129    }
     
    161162    }
    162163
    163     private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex)
    164     {
    165         return preprocessingData.GetValues<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond);
     164    private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) {
     165      return preprocessingData.GetValues<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond);
    166166    }
    167167
    168     private DateTime GetSecondsAsDateTime(double seconds)
    169     {
    170         DateTime dateTime = new DateTime();
    171         return dateTime.Add(new TimeSpan(0, 0, (int)seconds));
     168    private DateTime GetSecondsAsDateTime(double seconds) {
     169      DateTime dateTime = new DateTime();
     170      return dateTime.Add(new TimeSpan(0, 0, (int)seconds));
    172171    }
    173172  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IPreprocessingContext.cs

    r10307 r10383  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Optimization;
     
    2526
    2627namespace HeuristicLab.DataPreprocessing {
    27   public interface IPreprocessingContext : IItem {
     28  public interface IPreprocessingContext
     29    : IItem {
     30
    2831    IPreprocessingData Data { get; }
    2932
    30     /// <summary>
    31     /// Parent algorithm, if available, or problem.
    32     /// </summary>
    33     IItem ParentItem { get; }
    34 
     33    [Obsolete]
    3534    IDataAnalysisProblemData DataAnalysisProblemData { get; }
    3635
    3736    IAlgorithm Algorithm { get; }
    3837
    39     IProblem Problem { get; }
     38    IDataAnalysisProblem Problem { get; }
     39
     40    IItem ExportAlgorithmOrProblem();
     41
     42    IAlgorithm ExportAlgorithm();
     43
     44    IProblem ExportProblem();
    4045  }
    4146}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Plugin.cs.frame

    r10250 r10383  
    2828  [Plugin("HeuristicLab.DataPreprocessing", "3.3.9.$WCREV$")]
    2929  [PluginFile("HeuristicLab.DataPreprocessing-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3031  [PluginDependency("HeuristicLab.Common", "3.3")]
    3132  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
  • 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  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs

    r10377 r10383  
    88namespace HeuristicLab.DataPreprocessing {
    99  [View("DataPreprocessing View")]
    10   [Content(typeof(PreprocessingContext), true)]
     10  [Content(typeof(IPreprocessingContext), true)]
    1111  public partial class DataPreprocessingView : ItemView {
    1212
     
    9797
    9898    private void exportProblemButton_Click(object sender, EventArgs e) {
    99       var cloner = new PreprocessingCloner(Content);
    100       var alteredClone = cloner.GenerateAlteredClone(Content.Problem);
     99      var problem = Content.ExportProblem();
    101100
    102101      var saveFileDialog = new SaveFileDialog {
     
    107106      };
    108107
    109       var content = alteredClone as IStorableContent;
     108      var content = problem as IStorableContent;
    110109      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    111110        bool compressed = saveFileDialog.FilterIndex != 1;
     
    115114
    116115    private void applyInNewTabButton_Click(object sender, EventArgs e) {
    117       var cloner = new PreprocessingCloner(Content);
    118       var item = cloner.GenerateAlteredClone(Content.ParentItem);
     116      var item = Content.ExportAlgorithmOrProblem();
    119117
    120118      MainFormManager.MainForm.ShowContent(item);
Note: See TracChangeset for help on using the changeset viewer.