Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/ProxyEnsembleModel.cs

Last change on this file was 17980, checked in by jzenisek, 3 years ago

#2719 merged head of HeuristicLab.Problems.DataAnalysis into branch; added several minor items

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HeuristicLab.Problems.DataAnalysis;
29using HEAL.Attic;
30
31namespace HeuristicLab.DatastreamAnalysis {
32  [Item("Proxy Ensemble Model", "Represents a named and rated collection of models which acts as a model yet again.")] 
33  [Creatable(CreatableAttribute.Categories.DataAnalysis)]
34  [StorableType("F3794605-3D02-4482-8919-2FC29EBDB6F4")]
35  public class ProxyEnsembleModel : ParameterizedNamedItem, IProxyEnsembleModel {
36    protected const string ModelParameterName = "Model";
37    protected const string QualityThresholdParameterName = "QualityThreshold";
38    protected const string ConfidenceThresholdParameterName = "ConfidenceThreshold";
39
40    #region parameter properties
41
42    public IValueParameter<RegressionEnsembleModel> ModelParameter {
43      get { return (IValueParameter<RegressionEnsembleModel>) Parameters[ModelParameterName]; }
44    }
45
46    public IValueParameter<DoubleRange> QualityThresholdParameter {
47      get { return (IValueParameter<DoubleRange>) Parameters[QualityThresholdParameterName]; }
48    }
49
50    public IValueParameter<DoubleRange> ConfidenceThresholdParameter {
51      get { return (IValueParameter<DoubleRange>)Parameters[ConfidenceThresholdParameterName]; }
52    }
53
54    public RegressionEnsembleModel Model {
55      get { return ModelParameter.Value; }
56      set {
57        if(value == null) throw new ArgumentNullException("Model", "The provided value for model is null.");
58        ModelParameter.Value = value;
59      }
60    }
61
62    public DoubleRange QualityThreshold {
63      get { return QualityThresholdParameter.Value; }
64      set { QualityThresholdParameter.Value = value; }
65    }
66
67    public DoubleRange ConfidenceThreshold {
68      get { return ConfidenceThresholdParameter.Value; }
69      set { ConfidenceThresholdParameter.Value = value; }
70    }
71
72    #endregion
73
74    #region constructors, clone ...
75    [StorableConstructor]
76    protected ProxyEnsembleModel(StorableConstructorFlag _) : base(_) { }
77    protected ProxyEnsembleModel(ProxyEnsembleModel original, Cloner cloner) : base(original, cloner) {
78      RegisterParameterEvents();
79    }
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new ProxyEnsembleModel(this, cloner);
82    }
83    public ProxyEnsembleModel() : base() {
84      Parameters.Add(new ValueParameter<RegressionEnsembleModel>(ModelParameterName, "Collection of models.", null));
85      Parameters.Add(new FixedValueParameter<DoubleRange>(QualityThresholdParameterName, "Quality threshold for the ensemble evaluation [0.0,1.0]", new DoubleRange(0.8,0.9)));
86      Parameters.Add(new FixedValueParameter<DoubleRange>(ConfidenceThresholdParameterName, "Confidence threshold for the ensemble evaluation [0.0,1.0]", new DoubleRange(0.8, 0.9)));
87      RegisterParameterEvents();
88    }
89    [StorableHook(HookType.AfterDeserialization)]
90    private void AfterDeserialization() {
91      RegisterParameterEvents();
92    }
93    #endregion
94
95    public event EventHandler Reset;
96    public event EventHandler ModelChanged;
97    public event EventHandler QualityThresholdChanged;
98    public event EventHandler ConfidenceThresholdChanged;
99
100    private void RegisterParameterEvents() {
101      ModelParameter.ValueChanged += new EventHandler(Model_ValueChanged);
102      QualityThresholdParameter.ValueChanged += new EventHandler(QualityTreshold_ValueChanged);
103      ConfidenceThresholdParameter.ValueChanged += new EventHandler(ConfidenceTreshold_ValueChanged);
104    }
105
106    private void Model_ValueChanged(object sender, EventArgs e) {
107      if (e == null) return;
108      DatastreamAnalysisUtil.RaiseEvent(this, ModelChanged);
109    }
110
111    private void QualityTreshold_ValueChanged(object sender, EventArgs e) {
112      if (e == null) return;
113      DatastreamAnalysisUtil.RaiseEvent(this, QualityThresholdChanged);
114    }
115
116    private void ConfidenceTreshold_ValueChanged(object sender, EventArgs e) {
117      if (e == null) return;
118      DatastreamAnalysisUtil.RaiseEvent(this, ConfidenceThresholdChanged);
119    }
120
121    // TODO
122    public IEnumerable<IParameterizedItem> ExecutionContextItems { get; }
123  }
124}
Note: See TracBrowser for help on using the repository browser.