Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs @ 10698

Last change on this file since 10698 was 10695, checked in by pfleck, 11 years ago
  • Added Transformations to PreprocessingData
  • Added Transformations to DataAnalysisProblemData Parameters
  • Removed SymbolicExpressionTree as inverse transformation.
File size: 3.5 KB
RevLine 
[10219]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]22using System;
[10219]23using HeuristicLab.Common;
24using HeuristicLab.Core;
[10673]25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[10240]26using HeuristicLab.Optimization;
[10221]27using HeuristicLab.Problems.DataAnalysis;
[10673]28using HeuristicLab.Problems.DataAnalysis.Symbolic;
[10676]29using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
[10219]30
31namespace HeuristicLab.DataPreprocessing {
32  [Item("PreprocessingContext", "PreprocessingContext")]
[10383]33  public class PreprocessingContext
34    : Item, IPreprocessingContext {
35
[10614]36    public ITransactionalPreprocessingData Data { get; private set; }
37
38    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
39
40    public IAlgorithm Algorithm { get; private set; }
41
[10676]42    public IDataAnalysisProblem Problem { get; private set; }
[10614]43
[10676]44    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
[10586]45      Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
[10221]46      DataAnalysisProblemData = dataAnalysisProblemData;
[10240]47      Algorithm = algorithm;
[10307]48      Problem = problem;
[10219]49    }
50
51    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
52      : base(original, cloner) {
53      Data = cloner.Clone(original.Data);
[10221]54      DataAnalysisProblemData = original.DataAnalysisProblemData;
[10240]55      Algorithm = original.Algorithm;
[10307]56      Problem = original.Problem;
[10219]57    }
58
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new PreprocessingContext(this, cloner);
61    }
[10383]62
63    public IItem ExportAlgorithmOrProblem() {
64      if (Algorithm != null) {
65        return ExportAlgorithm();
66      }
[10676]67      return ExportProblem();
[10383]68    }
[10676]69
[10383]70    public IProblem ExportProblem() {
71      return Export(Problem, SetupProblem);
72    }
[10614]73    public IAlgorithm ExportAlgorithm() {
74      return Export(Algorithm, SetupAlgorithm);
75    }
[10383]76
[10676]77    private IDataAnalysisProblem SetupProblem(IProblem problem) {
78      return (IDataAnalysisProblem)problem;
[10383]79    }
[10676]80    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
[10536]81      algorithm.Name = algorithm.Name + "(Preprocessed)";
[10383]82      algorithm.Runs.Clear();
[10676]83      return (IDataAnalysisProblem)algorithm.Problem;
[10383]84    }
[10676]85    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
[10536]86        where T : IItem {
[10383]87      var creator = new ProblemDataCreator(this);
88      var data = creator.CreateProblemData();
89
90      var clone = (T)original.Clone(new Cloner());
91
92      var problem = setup(clone);
93      problem.ProblemDataParameter.ActualValue = data;
[10536]94      problem.Name = "Preprocessed " + problem.Name;
[10383]95      return clone;
96    }
[10219]97  }
98}
Note: See TracBrowser for help on using the repository browser.