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