#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.DataAnalysis;
namespace HeuristicLab.DatastreamAnalysis {
[StorableClass]
[Item("Rated Ensemble Model", "Represents a rated collection of models")]
[Creatable(CreatableAttribute.Categories.DataAnalysis)]
public class RatedEnsembleModel : ParameterizedNamedItem, IRatedEnsembleModel {
protected const string ModelParameterName = "Model";
protected const string QualityThresholdParameterName = "QualityThreshold";
protected const string ConfidenceThresholdParameterName = "ConfidenceThreshold";
#region parameter properties
public IValueParameter ModelParameter {
get { return (IValueParameter) Parameters[ModelParameterName]; }
}
public IValueParameter QualityThresholdParameter {
get { return (IValueParameter) Parameters[QualityThresholdParameterName]; }
}
public IValueParameter ConfidenceThresholdParameter {
get { return (IValueParameter)Parameters[ConfidenceThresholdParameterName]; }
}
public RegressionEnsembleModel Model {
get { return ModelParameter.Value; }
set {
if(value == null) throw new ArgumentNullException("Model", "The provided value for model is null.");
ModelParameter.Value = value;
}
}
public DoubleRange QualityThreshold {
get { return QualityThresholdParameter.Value; }
set { QualityThresholdParameter.Value = value; }
}
public DoubleRange ConfidenceThreshold {
get { return ConfidenceThresholdParameter.Value; }
set { ConfidenceThresholdParameter.Value = value; }
}
#endregion
#region constructors, clone ...
[StorableConstructor]
protected RatedEnsembleModel(bool deserializing) : base(deserializing) { }
protected RatedEnsembleModel(RatedEnsembleModel original, Cloner cloner) : base(original, cloner) {
RegisterParameterEvents();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new RatedEnsembleModel(this, cloner);
}
public RatedEnsembleModel() : base() {
Parameters.Add(new ValueParameter(ModelParameterName, "Collection of models.", null));
Parameters.Add(new FixedValueParameter(QualityThresholdParameterName, "Quality threshold for the ensemble evaluation [0.0,1.0]", new DoubleRange(0.8,0.9)));
Parameters.Add(new FixedValueParameter(ConfidenceThresholdParameterName, "Confidence threshold for the ensemble evaluation [0.0,1.0]", new DoubleRange(0.8, 0.9)));
RegisterParameterEvents();
}
[StorableHook(HookType.AfterDeserialization)]
private void AfterDeserialization() {
RegisterParameterEvents();
}
#endregion
public event EventHandler Reset;
public event EventHandler ModelChanged;
public event EventHandler QualityThresholdChanged;
public event EventHandler ConfidenceThresholdChanged;
private void RegisterParameterEvents() {
ModelParameter.ValueChanged += new EventHandler(Model_ValueChanged);
QualityThresholdParameter.ValueChanged += new EventHandler(QualityTreshold_ValueChanged);
ConfidenceThresholdParameter.ValueChanged += new EventHandler(ConfidenceTreshold_ValueChanged);
}
private void Model_ValueChanged(object sender, EventArgs e) {
if (e == null) return;
DatastreamAnalysisUtil.RaiseEvent(this, ModelChanged);
}
private void QualityTreshold_ValueChanged(object sender, EventArgs e) {
if (e == null) return;
DatastreamAnalysisUtil.RaiseEvent(this, QualityThresholdChanged);
}
private void ConfidenceTreshold_ValueChanged(object sender, EventArgs e) {
if (e == null) return;
DatastreamAnalysisUtil.RaiseEvent(this, ConfidenceThresholdChanged);
}
// TODO
public IEnumerable ExecutionContextItems { get; }
}
}