Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/GA/XCSAfterCrossoverOperator.cs @ 9105

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

#1980:

  • included an adapted version of GA correctly
  • added action set subsumption
  • added deletion after GA and before covering
File size: 5.6 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.Encodings.ConditionActionEncoding {
31  [Item("XCSAfterCrossoverOperator", "Description missing")]
32  [StorableClass]
33  public class XCSAfterCrossoverOperator : SingleSuccessorOperator {
34
35    #region Parameter Properties
36    public IValueLookupParameter<IntValue> NumerosityParameter {
37      get { return (IValueLookupParameter<IntValue>)Parameters["Numerosity"]; }
38    }
39    public IValueLookupParameter<IntValue> ExperienceParameter {
40      get { return (IValueLookupParameter<IntValue>)Parameters["Experience"]; }
41    }
42    public IValueLookupParameter<IntValue> TimestampParameter {
43      get { return (IValueLookupParameter<IntValue>)Parameters["Timestamp"]; }
44    }
45    public IValueLookupParameter<DoubleValue> PredictionParameter {
46      get { return (IValueLookupParameter<DoubleValue>)Parameters["Prediction"]; }
47    }
48    public IValueLookupParameter<DoubleValue> AverageActionSetSizeParameter {
49      get { return (IValueLookupParameter<DoubleValue>)Parameters["AverageActionSetSize"]; }
50    }
51    public IValueLookupParameter<DoubleValue> ErrorParameter {
52      get { return (IValueLookupParameter<DoubleValue>)Parameters["Error"]; }
53    }
54    public IValueLookupParameter<DoubleValue> FitnessParameter {
55      get { return (IValueLookupParameter<DoubleValue>)Parameters["Fitness"]; }
56    }
57    public ILookupParameter<IntValue> CurrentIterationParameter {
58      get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; }
59    }
60    public ILookupParameter<ItemArray<DoubleValue>> ParentAverageActionSetSizeParameter {
61      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentAverageActionSetSize"]; }
62    }
63    public ILookupParameter<ItemArray<DoubleValue>> ParentPredictionParameter {
64      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentPrediction"]; }
65    }
66    public ILookupParameter<ItemArray<DoubleValue>> ParentErrorParameter {
67      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentError"]; }
68    }
69    public ILookupParameter<ItemArray<DoubleValue>> ParentFitnessParameter {
70      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentFitness"]; }
71    }
72    #endregion
73
74    [StorableConstructor]
75    protected XCSAfterCrossoverOperator(bool deserializing) : base(deserializing) { }
76    protected XCSAfterCrossoverOperator(XCSAfterCrossoverOperator original, Cloner cloner)
77      : base(original, cloner) {
78    }
79    public XCSAfterCrossoverOperator()
80      : base() {
81      Parameters.Add(new ValueLookupParameter<IntValue>("Numerosity"));
82      Parameters.Add(new ValueLookupParameter<IntValue>("Experience"));
83      Parameters.Add(new ValueLookupParameter<IntValue>("Timestamp"));
84      Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageActionSetSize"));
85      Parameters.Add(new ValueLookupParameter<DoubleValue>("Prediction"));
86      Parameters.Add(new ValueLookupParameter<DoubleValue>("Error"));
87      Parameters.Add(new ValueLookupParameter<DoubleValue>("Fitness"));
88      Parameters.Add(new LookupParameter<IntValue>("CurrentIteration"));
89      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentAverageActionSetSize"));
90      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentPrediction"));
91      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentError"));
92      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentFitness"));
93    }
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new XCSAfterCrossoverOperator(this, cloner);
96    }
97
98    public override IOperation Apply() {
99      NumerosityParameter.ActualValue = new IntValue(1);
100      ExperienceParameter.ActualValue = new IntValue(0);
101      TimestampParameter.ActualValue = new IntValue(CurrentIterationParameter.ActualValue.Value);
102      var parentAverageActionSetSize = ParentAverageActionSetSizeParameter.ActualValue;
103      var parentPrecision = ParentPredictionParameter.ActualValue;
104      var parentPrecisionError = ParentErrorParameter.ActualValue;
105      var parentFitness = ParentFitnessParameter.ActualValue;
106      AverageActionSetSizeParameter.ActualValue = new DoubleValue(parentAverageActionSetSize.Select(x => x.Value).Average());
107      PredictionParameter.ActualValue = new DoubleValue(parentPrecision.Select(x => x.Value).Average());
108      ErrorParameter.ActualValue = new DoubleValue(0.25 * parentPrecisionError.Select(x => x.Value).Average());
109      FitnessParameter.ActualValue = new DoubleValue(0.1 * parentFitness.Select(x => x.Value).Average());
110      return base.Apply();
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.