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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
28 | using System.Collections.Generic;
|
---|
29 | using System.Linq;
|
---|
30 |
|
---|
31 | namespace 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 : NamedItem {
|
---|
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 | Name = ItemName;
|
---|
82 | Description = ItemDescription;
|
---|
83 | }
|
---|
84 | protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
|
---|
85 | protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
|
---|
86 | : this() {
|
---|
87 | this.problemData = problemData;
|
---|
88 | this.lowerEstimationLimit = lowerEstimationLimit;
|
---|
89 | this.upperEstimationLimit = upperEstimationLimit;
|
---|
90 | Initialize();
|
---|
91 | }
|
---|
92 |
|
---|
93 | [StorableConstructor]
|
---|
94 | private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
|
---|
95 |
|
---|
96 | [StorableHook(HookType.AfterDeserialization)]
|
---|
97 | private void Initialize() {
|
---|
98 | if (problemData != null) RegisterProblemDataEvents();
|
---|
99 | }
|
---|
100 |
|
---|
101 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
102 | DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
|
---|
103 | // don't clone the problem data!
|
---|
104 | clone.problemData = problemData;
|
---|
105 | clone.lowerEstimationLimit = lowerEstimationLimit;
|
---|
106 | clone.upperEstimationLimit = upperEstimationLimit;
|
---|
107 | clone.Initialize();
|
---|
108 | return clone;
|
---|
109 | }
|
---|
110 |
|
---|
111 | #region Events
|
---|
112 | protected virtual void RegisterProblemDataEvents() {
|
---|
113 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
114 | }
|
---|
115 | protected virtual void DeregisterProblemDataEvents() {
|
---|
116 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
117 | }
|
---|
118 |
|
---|
119 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
120 | OnProblemDataChanged(EventArgs.Empty);
|
---|
121 | }
|
---|
122 |
|
---|
123 | public event EventHandler ProblemDataChanged;
|
---|
124 | protected virtual void OnProblemDataChanged(EventArgs e) {
|
---|
125 | var listeners = ProblemDataChanged;
|
---|
126 | if (listeners != null)
|
---|
127 | listeners(this, e);
|
---|
128 | }
|
---|
129 |
|
---|
130 | public event EventHandler EstimatedValuesChanged;
|
---|
131 | protected virtual void OnEstimatedValuesChanged(EventArgs e) {
|
---|
132 | var listeners = EstimatedValuesChanged;
|
---|
133 | if (listeners != null)
|
---|
134 | listeners(this, e);
|
---|
135 | }
|
---|
136 | #endregion
|
---|
137 | }
|
---|
138 | }
|
---|