Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs @ 3538

Last change on this file since 3538 was 3513, checked in by gkronber, 15 years ago

Added upper and lower estimation limits. #938 (Data types and operators for regression problems)

File size: 4.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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using System.Collections.Generic;
29using System.Linq;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  /// <summary>
33  /// Represents a solution for a data analysis problem which can be visualized in the GUI.
34  /// </summary>
35  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
36  [StorableClass]
37  public abstract class DataAnalysisSolution : Item {
38    [Storable]
39    private DataAnalysisProblemData problemData;
40    public DataAnalysisProblemData ProblemData {
41      get { return problemData; }
42      set {
43        if (problemData != value) {
44          if (value == null) throw new ArgumentNullException();
45          if (problemData != null) DeregisterProblemDataEvents();
46          problemData = value;
47          RegisterProblemDataEvents();
48          OnProblemDataChanged(EventArgs.Empty);
49        }
50      }
51    }
52    [Storable]
53    private double lowerEstimationLimit;
54    public double LowerEstimationLimit {
55      get { return lowerEstimationLimit; }
56      set {
57        if (lowerEstimationLimit != value) {
58          lowerEstimationLimit = value;
59          OnEstimatedValuesChanged(EventArgs.Empty);
60        }
61      }
62    }
63
64    [Storable]
65    private double upperEstimationLimit;
66    public double UpperEstimationLimit {
67      get { return upperEstimationLimit; }
68      set {
69        if (upperEstimationLimit != value) {
70          upperEstimationLimit = value;
71          OnEstimatedValuesChanged(EventArgs.Empty);
72        }
73      }
74    }
75
76    public abstract IEnumerable<double> EstimatedValues { get; }
77    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
78    public abstract IEnumerable<double> EstimatedTestValues { get; }
79
80    protected DataAnalysisSolution() : base() { }
81    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
82    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
83      : this() {
84      this.problemData = problemData;
85      this.lowerEstimationLimit = lowerEstimationLimit;
86      this.upperEstimationLimit = upperEstimationLimit;
87      Initialize();
88    }
89
90    [StorableConstructor]
91    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
92
93    [StorableHook(HookType.AfterDeserialization)]
94    private void Initialize() {
95      if (problemData != null) RegisterProblemDataEvents();
96    }
97
98    public override IDeepCloneable Clone(Cloner cloner) {
99      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
100      // don't clone the problem data!
101      clone.problemData = problemData;
102      clone.lowerEstimationLimit = lowerEstimationLimit;
103      clone.upperEstimationLimit = upperEstimationLimit;
104      clone.Initialize();
105      return clone;
106    }
107
108    #region Events
109    protected virtual void RegisterProblemDataEvents() {
110      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
111    }
112    protected virtual void DeregisterProblemDataEvents() {
113      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
114    }
115
116    private void ProblemData_Changed(object sender, EventArgs e) {
117      OnProblemDataChanged(EventArgs.Empty);
118    }
119
120    public event EventHandler ProblemDataChanged;
121    protected virtual void OnProblemDataChanged(EventArgs e) {
122      var listeners = ProblemDataChanged;
123      if (listeners != null)
124        listeners(this, e);
125    }
126
127    public event EventHandler EstimatedValuesChanged;
128    protected virtual void OnEstimatedValuesChanged(EventArgs e) {
129      var listeners = EstimatedValuesChanged;
130      if (listeners != null)
131        listeners(this, e);
132    }
133    #endregion
134  }
135}
Note: See TracBrowser for help on using the repository browser.