#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Optimization.Operators.LCS {
[Item("InitializeDiscretizersOperator", "Description missing")]
[StorableClass]
public class InitializeDiscretizersOperator : SingleSuccessorOperator {
#region Parameter Properties
public ILookupParameter ProblemDataParameter {
get { return (ILookupParameter)Parameters["ProblemData"]; }
}
public ILookupParameter> DiscretizersParameter {
get { return (ILookupParameter>)Parameters["Discretizers"]; }
}
#endregion
[StorableConstructor]
protected InitializeDiscretizersOperator(bool deserializing) : base(deserializing) { }
protected InitializeDiscretizersOperator(InitializeDiscretizersOperator original, Cloner cloner)
: base(original, cloner) {
}
public InitializeDiscretizersOperator()
: base() {
Parameters.Add(new LookupParameter("ProblemData", ""));
Parameters.Add(new LookupParameter>("Discretizers", ""));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new InitializeDiscretizersOperator(this, cloner);
}
public override IOperation Apply() {
var dataset = ProblemDataParameter.ActualValue.Dataset;
var trainingIndizes = ProblemDataParameter.ActualValue.TrainingIndices;
var conditionVariables = ProblemDataParameter.ActualValue.ConditionVariables.CheckedItems.Select(x => x.Value.Value);
foreach (var variable in dataset.DoubleVariables.Where(x => conditionVariables.Contains(x))) {
var values = dataset.GetDoubleValues(variable, trainingIndizes);
foreach (var discretizer in DiscretizersParameter.ActualValue) {
discretizer.DiscretizeValues(variable, values);
}
}
return base.Apply();
}
}
}