Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs @ 4237

Last change on this file since 4237 was 4193, checked in by gkronber, 14 years ago

Created a feature/exploration branch for new data analysis features #1142

File size: 5.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis {
30  /// <summary>
31  /// Represents a solution for a data analysis problem which can be visualized in the GUI.
32  /// </summary>
33  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
34  [StorableClass]
35  public abstract class DataAnalysisSolution : NamedItem {
36    protected DataAnalysisSolution()
37      : base() { }
38    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
39    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
40      : this() {
41      this.problemData = problemData;
42      this.lowerEstimationLimit = lowerEstimationLimit;
43      this.upperEstimationLimit = upperEstimationLimit;
44      Initialize();
45    }
46
47    [StorableConstructor]
48    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
49    [StorableHook(HookType.AfterDeserialization)]
50    private void Initialize() {
51      if (problemData != null)
52        RegisterProblemDataEvents();
53    }
54
55    [Storable]
56    private DataAnalysisProblemData problemData;
57    public DataAnalysisProblemData ProblemData {
58      get { return problemData; }
59      set {
60        if (problemData != value) {
61          if (value == null) throw new ArgumentNullException();
62          if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
63            value.InputVariables.Select(c => c.Value)))
64            throw new ArgumentException("Could not set new problem data with different structure");
65
66          if (problemData != null) DeregisterProblemDataEvents();
67          problemData = value;
68          RegisterProblemDataEvents();
69          OnProblemDataChanged();
70          RecalculateEstimatedValues();
71        }
72      }
73    }
74
75    [Storable]
76    private IDataAnalysisModel model;
77    public IDataAnalysisModel Model {
78      get { return model; }
79      set {
80        if (model != value) {
81          if (value == null) throw new ArgumentNullException();
82          model = value;
83          OnModelChanged();
84          RecalculateEstimatedValues();
85        }
86      }
87    }
88
89    [Storable]
90    private double lowerEstimationLimit;
91    public double LowerEstimationLimit {
92      get { return lowerEstimationLimit; }
93      set {
94        if (lowerEstimationLimit != value) {
95          lowerEstimationLimit = value;
96          RecalculateEstimatedValues();
97        }
98      }
99    }
100
101    [Storable]
102    private double upperEstimationLimit;
103    public double UpperEstimationLimit {
104      get { return upperEstimationLimit; }
105      set {
106        if (upperEstimationLimit != value) {
107          upperEstimationLimit = value;
108          RecalculateEstimatedValues();
109        }
110      }
111    }
112
113    public abstract IEnumerable<double> EstimatedValues { get; }
114    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
115    public abstract IEnumerable<double> EstimatedTestValues { get; }
116    protected abstract void RecalculateEstimatedValues();
117
118    #region Events
119    protected virtual void RegisterProblemDataEvents() {
120      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
121    }
122    protected virtual void DeregisterProblemDataEvents() {
123      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
124    }
125    private void ProblemData_Changed(object sender, EventArgs e) {
126      OnProblemDataChanged();
127    }
128
129    public event EventHandler ProblemDataChanged;
130    protected virtual void OnProblemDataChanged() {
131      RecalculateEstimatedValues();
132      var listeners = ProblemDataChanged;
133      if (listeners != null)
134        listeners(this, EventArgs.Empty);
135    }
136
137    public event EventHandler ModelChanged;
138    protected virtual void OnModelChanged() {
139      EventHandler handler = ModelChanged;
140      if (handler != null)
141        handler(this, EventArgs.Empty);
142    }
143
144    public event EventHandler EstimatedValuesChanged;
145    protected virtual void OnEstimatedValuesChanged() {
146      var listeners = EstimatedValuesChanged;
147      if (listeners != null)
148        listeners(this, EventArgs.Empty);
149    }
150    #endregion
151
152    public override IDeepCloneable Clone(Cloner cloner) {
153      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
154      clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
155      clone.model = (IDataAnalysisModel)cloner.Clone(model);
156      clone.lowerEstimationLimit = lowerEstimationLimit;
157      clone.upperEstimationLimit = upperEstimationLimit;
158      clone.Initialize();
159
160      return clone;
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.