Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4501 was 4457, checked in by gkronber, 14 years ago

made DataAnalysisProblem and DataAnalysisProblemData and SymbolicTimeSeriesPrognosisSolution savable and added field for conditional evaluation to Symbolic/SymbolicTimeSeriesPrognosisSolution. #1142

File size: 5.9 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, IStorableContent {
36    #region IStorableContent Members
37    public string Filename { get; set; }
38    #endregion
39
40
41    protected DataAnalysisSolution()
42      : base() { }
43    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
44    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
45      : this() {
46      this.problemData = problemData;
47      this.lowerEstimationLimit = lowerEstimationLimit;
48      this.upperEstimationLimit = upperEstimationLimit;
49      Initialize();
50    }
51
52    [StorableConstructor]
53    protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
54    [StorableHook(HookType.AfterDeserialization)]
55    private void Initialize() {
56      if (problemData != null)
57        RegisterProblemDataEvents();
58    }
59
60    [Storable]
61    private DataAnalysisProblemData problemData;
62    public DataAnalysisProblemData ProblemData {
63      get { return problemData; }
64      set {
65        if (problemData != value) {
66          if (value == null) throw new ArgumentNullException();
67          if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
68            value.InputVariables.Select(c => c.Value)))
69            throw new ArgumentException("Could not set new problem data with different structure");
70
71          if (problemData != null) DeregisterProblemDataEvents();
72          problemData = value;
73          RegisterProblemDataEvents();
74          OnProblemDataChanged();
75          RecalculateEstimatedValues();
76        }
77      }
78    }
79
80    [Storable]
81    private IDataAnalysisModel model;
82    public IDataAnalysisModel Model {
83      get { return model; }
84      set {
85        if (model != value) {
86          if (value == null) throw new ArgumentNullException();
87          model = value;
88          OnModelChanged();
89          RecalculateEstimatedValues();
90        }
91      }
92    }
93
94    [Storable]
95    private double lowerEstimationLimit;
96    public double LowerEstimationLimit {
97      get { return lowerEstimationLimit; }
98      set {
99        if (lowerEstimationLimit != value) {
100          lowerEstimationLimit = value;
101          RecalculateEstimatedValues();
102        }
103      }
104    }
105
106    [Storable]
107    private double upperEstimationLimit;
108    public double UpperEstimationLimit {
109      get { return upperEstimationLimit; }
110      set {
111        if (upperEstimationLimit != value) {
112          upperEstimationLimit = value;
113          RecalculateEstimatedValues();
114        }
115      }
116    }
117
118    public abstract IEnumerable<double> EstimatedValues { get; }
119    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
120    public abstract IEnumerable<double> EstimatedTestValues { get; }
121    protected abstract void RecalculateEstimatedValues();
122
123    #region Events
124    protected virtual void RegisterProblemDataEvents() {
125      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
126    }
127    protected virtual void DeregisterProblemDataEvents() {
128      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
129    }
130    private void ProblemData_Changed(object sender, EventArgs e) {
131      OnProblemDataChanged();
132    }
133
134    public event EventHandler ProblemDataChanged;
135    protected virtual void OnProblemDataChanged() {
136      RecalculateEstimatedValues();
137      var listeners = ProblemDataChanged;
138      if (listeners != null)
139        listeners(this, EventArgs.Empty);
140    }
141
142    public event EventHandler ModelChanged;
143    protected virtual void OnModelChanged() {
144      EventHandler handler = ModelChanged;
145      if (handler != null)
146        handler(this, EventArgs.Empty);
147    }
148
149    public event EventHandler EstimatedValuesChanged;
150    protected virtual void OnEstimatedValuesChanged() {
151      var listeners = EstimatedValuesChanged;
152      if (listeners != null)
153        listeners(this, EventArgs.Empty);
154    }
155    #endregion
156
157    public override IDeepCloneable Clone(Cloner cloner) {
158      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
159      clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
160      clone.model = (IDataAnalysisModel)cloner.Clone(model);
161      clone.lowerEstimationLimit = lowerEstimationLimit;
162      clone.upperEstimationLimit = upperEstimationLimit;
163      clone.Initialize();
164
165      return clone;
166    }
167  }
168}
Note: See TracBrowser for help on using the repository browser.