[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;
|
---|
[4068] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[3408] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace 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]
|
---|
[4457] | 35 | public abstract class DataAnalysisSolution : NamedItem, IStorableContent {
|
---|
| 36 | #region IStorableContent Members
|
---|
| 37 | public string Filename { get; set; }
|
---|
| 38 | #endregion
|
---|
| 39 |
|
---|
| 40 |
|
---|
[3884] | 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]
|
---|
[4401] | 53 | protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
|
---|
[3884] | 54 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 55 | private void Initialize() {
|
---|
[3921] | 56 | if (problemData != null)
|
---|
| 57 | RegisterProblemDataEvents();
|
---|
[3884] | 58 | }
|
---|
| 59 |
|
---|
[3408] | 60 | [Storable]
|
---|
| 61 | private DataAnalysisProblemData problemData;
|
---|
| 62 | public DataAnalysisProblemData ProblemData {
|
---|
| 63 | get { return problemData; }
|
---|
| 64 | set {
|
---|
| 65 | if (problemData != value) {
|
---|
[3442] | 66 | if (value == null) throw new ArgumentNullException();
|
---|
[3884] | 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 |
|
---|
[3408] | 71 | if (problemData != null) DeregisterProblemDataEvents();
|
---|
| 72 | problemData = value;
|
---|
[3442] | 73 | RegisterProblemDataEvents();
|
---|
[3884] | 74 | OnProblemDataChanged();
|
---|
[3915] | 75 | RecalculateEstimatedValues();
|
---|
[3408] | 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
[3884] | 79 |
|
---|
[3513] | 80 | [Storable]
|
---|
[3884] | 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();
|
---|
[3915] | 89 | RecalculateEstimatedValues();
|
---|
[3884] | 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | [Storable]
|
---|
[3513] | 95 | private double lowerEstimationLimit;
|
---|
| 96 | public double LowerEstimationLimit {
|
---|
| 97 | get { return lowerEstimationLimit; }
|
---|
| 98 | set {
|
---|
| 99 | if (lowerEstimationLimit != value) {
|
---|
| 100 | lowerEstimationLimit = value;
|
---|
[3884] | 101 | RecalculateEstimatedValues();
|
---|
[3513] | 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[3442] | 105 |
|
---|
[3513] | 106 | [Storable]
|
---|
| 107 | private double upperEstimationLimit;
|
---|
| 108 | public double UpperEstimationLimit {
|
---|
| 109 | get { return upperEstimationLimit; }
|
---|
| 110 | set {
|
---|
| 111 | if (upperEstimationLimit != value) {
|
---|
| 112 | upperEstimationLimit = value;
|
---|
[3884] | 113 | RecalculateEstimatedValues();
|
---|
[3513] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[3462] | 118 | public abstract IEnumerable<double> EstimatedValues { get; }
|
---|
| 119 | public abstract IEnumerable<double> EstimatedTrainingValues { get; }
|
---|
| 120 | public abstract IEnumerable<double> EstimatedTestValues { get; }
|
---|
[3884] | 121 | protected abstract void RecalculateEstimatedValues();
|
---|
[3442] | 122 |
|
---|
[3408] | 123 | #region Events
|
---|
[3462] | 124 | protected virtual void RegisterProblemDataEvents() {
|
---|
[3442] | 125 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 126 | }
|
---|
[3462] | 127 | protected virtual void DeregisterProblemDataEvents() {
|
---|
[3442] | 128 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 129 | }
|
---|
[3442] | 130 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
[3884] | 131 | OnProblemDataChanged();
|
---|
[3408] | 132 | }
|
---|
[3462] | 133 |
|
---|
| 134 | public event EventHandler ProblemDataChanged;
|
---|
[3884] | 135 | protected virtual void OnProblemDataChanged() {
|
---|
[4193] | 136 | RecalculateEstimatedValues();
|
---|
[3462] | 137 | var listeners = ProblemDataChanged;
|
---|
| 138 | if (listeners != null)
|
---|
[3884] | 139 | listeners(this, EventArgs.Empty);
|
---|
[3462] | 140 | }
|
---|
| 141 |
|
---|
[3884] | 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 |
|
---|
[3462] | 149 | public event EventHandler EstimatedValuesChanged;
|
---|
[3884] | 150 | protected virtual void OnEstimatedValuesChanged() {
|
---|
[3462] | 151 | var listeners = EstimatedValuesChanged;
|
---|
| 152 | if (listeners != null)
|
---|
[3884] | 153 | listeners(this, EventArgs.Empty);
|
---|
[3462] | 154 | }
|
---|
[3408] | 155 | #endregion
|
---|
[3884] | 156 |
|
---|
| 157 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 158 | DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
|
---|
[3933] | 159 | clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
|
---|
[3921] | 160 | clone.model = (IDataAnalysisModel)cloner.Clone(model);
|
---|
[3884] | 161 | clone.lowerEstimationLimit = lowerEstimationLimit;
|
---|
| 162 | clone.upperEstimationLimit = upperEstimationLimit;
|
---|
| 163 | clone.Initialize();
|
---|
[3921] | 164 |
|
---|
[3884] | 165 | return clone;
|
---|
| 166 | }
|
---|
[3408] | 167 | }
|
---|
| 168 | }
|
---|