Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/GAssist/MDL/MDLIterationOperator.cs @ 9392

Last change on this file since 9392 was 9392, checked in by sforsten, 11 years ago

#1980:

  • several small bug fixes
  • added windowing technique ILAS to GAssist
  • GAssist and XCS work now with real-valued features
  • severely improved the performance of XCS
File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Optimization.Operators.LCS {
31  [Item("MDLIterationOperator", "Description missing")]
32  [StorableClass]
33  public class MDLIterationOperator : SingleSuccessorOperator {
34
35    #region Parameter Properties
36    public IValueLookupParameter<MDLCalculator> MDLCalculatorParameter {
37      get { return (IValueLookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; }
38    }
39    public ILookupParameter<IntValue> IterationsParameter {
40      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
41    }
42    public ILookupParameter<IntValue> MDLActivationIterationParameter {
43      get { return (ILookupParameter<IntValue>)Parameters["MDLActivationIteration"]; }
44    }
45    public ILookupParameter<DoubleValue> InitialTheoryLengthRatioParameter {
46      get { return (ILookupParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; }
47    }
48    public ILookupParameter<DoubleValue> WeightRelaxFactorParameter {
49      get { return (ILookupParameter<DoubleValue>)Parameters["WeightRelaxFactor"]; }
50    }
51    public ILookupParameter<IntValue> WeightAdaptionIterationsParameter {
52      get { return (ILookupParameter<IntValue>)Parameters["WeightAdaptionIterations"]; }
53    }
54
55    public ScopeTreeLookupParameter<IGAssistIndividual> IndividualParameter {
56      get { return (ScopeTreeLookupParameter<IGAssistIndividual>)Parameters["Individual"]; }
57    }
58    public LookupParameter<IGAssistNichesProblemData> ProblemDataParameter {
59      get { return (LookupParameter<IGAssistNichesProblemData>)Parameters["ProblemData"]; }
60    }
61    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
62      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
63    }
64    public ILookupParameter<BoolValue> MaximizationParameter {
65      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
66    }
67    #endregion
68
69    [StorableConstructor]
70    protected MDLIterationOperator(bool deserializing) : base(deserializing) { }
71    protected MDLIterationOperator(MDLIterationOperator original, Cloner cloner)
72      : base(original, cloner) {
73    }
74    public MDLIterationOperator()
75      : base() {
76      Parameters.Add(new LookupParameter<IntValue>("Iterations", ""));
77      Parameters.Add(new ValueLookupParameter<MDLCalculator>("MDLCalculator", ""));
78      Parameters.Add(new LookupParameter<IntValue>("MDLActivationIteration", ""));
79      Parameters.Add(new LookupParameter<DoubleValue>("InitialTheoryLengthRatio", ""));
80      Parameters.Add(new LookupParameter<DoubleValue>("WeightRelaxFactor", ""));
81      Parameters.Add(new LookupParameter<IntValue>("WeightAdaptionIterations", ""));
82
83      Parameters.Add(new ScopeTreeLookupParameter<IGAssistIndividual>("Individual", ""));
84      Parameters.Add(new LookupParameter<IGAssistNichesProblemData>("ProblemData", ""));
85      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the trees that should be analyzed."));
86      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "The direction of optimization."));
87    }
88    public override IDeepCloneable Clone(Cloner cloner) {
89      return new MDLIterationOperator(this, cloner);
90    }
91
92    public override IOperation Apply() {
93      if (MDLCalculatorParameter.ActualValue == null) {
94        MDLCalculatorParameter.ActualValue = new MDLCalculator(MDLActivationIterationParameter.ActualValue.Value,
95                                                               InitialTheoryLengthRatioParameter.ActualValue.Value,
96                                                               WeightRelaxFactorParameter.ActualValue.Value,
97                                                               WeightAdaptionIterationsParameter.ActualValue.Value);
98      } else {
99        var qualities = QualityParameter.ActualValue;
100        var bestQuality = MaximizationParameter.ActualValue.Value ? qualities.Max() : qualities.Min();
101        int index = qualities.IndexOf(bestQuality);
102        var dls = IndividualParameter.ActualValue[index].CreateGAssistSolution(ProblemDataParameter.ActualValue);
103
104        MDLCalculatorParameter.ActualValue.StartNewIteration(dls, IterationsParameter.ActualValue.Value);
105      }
106      return base.Apply();
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.