#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.Data; using HeuristicLab.Encodings.DecisionList; using HeuristicLab.Encodings.DecisionList.Interfaces; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Operators.LCS; using HeuristicLab.Optimization.Operators.LCS.DefaultRule; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.DataAnalysis; using HeuristicLab.Problems.Instances; namespace HeuristicLab.Problems.DecisionListClassification { [Item("DecisionListClassificationProblem", "")] [StorableClass] [Creatable("Problems")] public class DecisionListClassificationProblem : HeuristicOptimizationProblem, IDecisionListClassificationProblem, IGAssistProblem, IProblemInstanceConsumer { #region parameter properties public IFixedValueParameter MaximizationParameter { get { return (IFixedValueParameter)Parameters["Maximization"]; } } IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter { get { return MaximizationParameter; } } public IFixedValueParameter BestKnownQualityParameter { get { return (IFixedValueParameter)Parameters["BestKnownQuality"]; } } IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter { get { return BestKnownQualityParameter; } } public IValueParameter ProblemDataParameter { get { return (IValueParameter)Parameters["ProblemData"]; } } public IFixedValueParameter SizePenaltyMinRulesParameter { get { return (IFixedValueParameter)Parameters["SizePenaltyMinRules"]; } } public IFixedValueParameter ActivationIterationParameter { get { return (IFixedValueParameter)Parameters["ActivationIteration"]; } } public IFixedValueParameter InitialTheoryLengthRatioParameter { get { return (IFixedValueParameter)Parameters["InitialTheoryLengthRatio"]; } } public IFixedValueParameter WeightRelaxFactorParameter { get { return (IFixedValueParameter)Parameters["WeightRelaxFactor"]; } } public IFixedValueParameter ActionMutationProbabilityParameter { get { return (IFixedValueParameter)Parameters["ActionMutationProbability"]; } } public IDecisionListClassificationProblemData ProblemData { get { return ProblemDataParameter.Value; } protected set { ProblemDataParameter.Value = value; } } IParameter IDecisionListClassificationProblem.ProblemDataParameter { get { return ProblemDataParameter; } } IDecisionListClassificationProblemData IDecisionListClassificationProblem.ProblemData { get { return ProblemData; } } IDecisionListEvaluator IDecisionListClassificationProblem.Evaluator { get { return Evaluator; } } ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator { get { return Evaluator; } } #endregion [StorableConstructor] protected DecisionListClassificationProblem(bool deserializing) : base(deserializing) { } protected DecisionListClassificationProblem(DecisionListClassificationProblem original, Cloner cloner) : base(original, cloner) { } public DecisionListClassificationProblem() : this(new DecisionListClassificationProblemData(new Dataset(DecisionListClassificationProblemData.defaultVariableNames, DecisionListClassificationProblemData.defaultData), DecisionListClassificationProblemData.defaultVariableNames.Take(DecisionListClassificationProblemData.defaultVariableNames.Length - 1), DecisionListClassificationProblemData.defaultVariableNames.Last()), new MDLEvaluator(), new UniformRandomDecisionListCreator()) { } public DecisionListClassificationProblem(IDecisionListClassificationProblemData problemData, IDecisionListEvaluator decisionlistEvaluator, IDecisionListCreator decisionListCreator) : base(decisionlistEvaluator, decisionListCreator) { Parameters.Add(new ValueParameter("ProblemData", "", problemData)); Parameters.Add(new FixedValueParameter("Maximization", "", new BoolValue(false))); Parameters.Add(new FixedValueParameter("BestKnownQuality", "", new DoubleValue(0.5))); Parameters.Add(new FixedValueParameter("SizePenaltyMinRules", "", new IntValue(4))); Parameters.Add(new FixedValueParameter("ActivationIteration", "", new IntValue(25))); Parameters.Add(new FixedValueParameter("InitialTheoryLengthRatio", "", new DoubleValue(0.075))); Parameters.Add(new FixedValueParameter("WeightRelaxFactor", "", new DoubleValue(0.9))); Parameters.Add(new FixedValueParameter("ActionMutationProbability", "", new PercentValue(0.1))); Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules"; // do differently ((MDLEvaluator)Evaluator).MDLCalculatorParameter.Value = new MDLCalculator(ActivationIterationParameter.Value.Value, InitialTheoryLengthRatioParameter.Value.Value, WeightRelaxFactorParameter.Value.Value); InitializeOperators(); } private void InitializeOperators() { foreach (var op in ApplicationManager.Manager.GetInstances()) Operators.Add(op); foreach (var op in ApplicationManager.Manager.GetInstances()) Operators.Add(op); foreach (var op in ApplicationManager.Manager.GetInstances()) Operators.Add(op); ParameterizeOperators(); BestTrainingDecisionListAnalyzer analyzer = new BestTrainingDecisionListAnalyzer(); analyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name; analyzer.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName; analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; analyzer.ResultsParameter.ActualName = "Results"; analyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; Operators.Add(analyzer); } private void ParameterizeOperators() { var autoDefaultRule = Operators.Where(x => x is AutoDefaultRule).Select(x => x as AutoDefaultRule).First(); autoDefaultRule.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; autoDefaultRule.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name; autoDefaultRule.NicheComparerParameter.Value = new DecisionListNicheComparer(); foreach (IDefaultRuleOperator op in Operators.OfType()) { op.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName; op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; op.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name; op.GAssistNichesProblemDataParameter.Hidden = true; op.NichingParameter.ActualName = "Niching"; } foreach (IDecisionListCrossover op in Operators.OfType()) { op.ParentsParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName; op.ParentsParameter.Hidden = true; op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName; op.ChildParameter.Hidden = true; } foreach (IDecisionListManipulator op in Operators.OfType()) { op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName; op.ChildParameter.Hidden = true; op.ActionMutationProbabilityParameter.ActualName = ActionMutationProbabilityParameter.Name; op.ActionMutationProbabilityParameter.Hidden = true; } } public override IDeepCloneable Clone(Cloner cloner) { return new DecisionListClassificationProblem(this, cloner); } IParameter IGAssistProblem.ProblemDataParameter { get { return ProblemDataParameter; } } public string NichingParameterName { get { return "Niching"; } } public void Load(DecisionListClassificationProblemData data) { Name = data.Name; Description = data.Description; ProblemData = data; } } }