[3408] | 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;
|
---|
[3442] | 28 | using System.Collections.Generic;
|
---|
| 29 | using System.Linq;
|
---|
[3408] | 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]
|
---|
[3462] | 37 | public abstract class DataAnalysisSolution : Item {
|
---|
[3408] | 38 | [Storable]
|
---|
| 39 | private DataAnalysisProblemData problemData;
|
---|
| 40 | public DataAnalysisProblemData ProblemData {
|
---|
| 41 | get { return problemData; }
|
---|
| 42 | set {
|
---|
| 43 | if (problemData != value) {
|
---|
[3442] | 44 | if (value == null) throw new ArgumentNullException();
|
---|
[3408] | 45 | if (problemData != null) DeregisterProblemDataEvents();
|
---|
| 46 | problemData = value;
|
---|
[3442] | 47 | RegisterProblemDataEvents();
|
---|
[3462] | 48 | OnProblemDataChanged(EventArgs.Empty);
|
---|
[3408] | 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
[3513] | 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 | }
|
---|
[3442] | 63 |
|
---|
[3513] | 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 |
|
---|
[3462] | 76 | public abstract IEnumerable<double> EstimatedValues { get; }
|
---|
| 77 | public abstract IEnumerable<double> EstimatedTrainingValues { get; }
|
---|
| 78 | public abstract IEnumerable<double> EstimatedTestValues { get; }
|
---|
[3442] | 79 |
|
---|
[3462] | 80 | protected DataAnalysisSolution() : base() { }
|
---|
[3513] | 81 | protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
|
---|
| 82 | protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
|
---|
[3408] | 83 | : this() {
|
---|
| 84 | this.problemData = problemData;
|
---|
[3513] | 85 | this.lowerEstimationLimit = lowerEstimationLimit;
|
---|
| 86 | this.upperEstimationLimit = upperEstimationLimit;
|
---|
[3408] | 87 | Initialize();
|
---|
| 88 | }
|
---|
[3442] | 89 |
|
---|
[3408] | 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) {
|
---|
[3462] | 99 | DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
|
---|
| 100 | // don't clone the problem data!
|
---|
[3408] | 101 | clone.problemData = problemData;
|
---|
[3513] | 102 | clone.lowerEstimationLimit = lowerEstimationLimit;
|
---|
| 103 | clone.upperEstimationLimit = upperEstimationLimit;
|
---|
[3408] | 104 | clone.Initialize();
|
---|
| 105 | return clone;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | #region Events
|
---|
[3462] | 109 | protected virtual void RegisterProblemDataEvents() {
|
---|
[3442] | 110 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 111 | }
|
---|
[3462] | 112 | protected virtual void DeregisterProblemDataEvents() {
|
---|
[3442] | 113 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 114 | }
|
---|
| 115 |
|
---|
[3442] | 116 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
[3462] | 117 | OnProblemDataChanged(EventArgs.Empty);
|
---|
[3408] | 118 | }
|
---|
[3462] | 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 | }
|
---|
[3408] | 133 | #endregion
|
---|
| 134 | }
|
---|
| 135 | }
|
---|