Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13791 was 9167, checked in by sforsten, 12 years ago

#1980:

  • change standard parameter settings in ConditionActionClassificationProblem
  • fixed bug: if a parent is copied instead of a crossover, the new individual is inserted in the population correctly
  • added missing attributes to ConditionActionClassificationProblemData
File size: 5.1 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.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.ConditionActionEncoding {
30  [Item("XCSAfterCrossoverOperator", "Description missing")]
31  [StorableClass]
32  public class XCSAfterCrossoverOperator : XCSAfterCopyingParentOperator {
33
34    #region Parameter Properties
35    public IValueLookupParameter<IntValue> TimestampParameter {
36      get { return (IValueLookupParameter<IntValue>)Parameters["Timestamp"]; }
37    }
38    public IValueLookupParameter<DoubleValue> PredictionParameter {
39      get { return (IValueLookupParameter<DoubleValue>)Parameters["Prediction"]; }
40    }
41    public IValueLookupParameter<DoubleValue> AverageActionSetSizeParameter {
42      get { return (IValueLookupParameter<DoubleValue>)Parameters["AverageActionSetSize"]; }
43    }
44    public IValueLookupParameter<DoubleValue> ErrorParameter {
45      get { return (IValueLookupParameter<DoubleValue>)Parameters["Error"]; }
46    }
47    public IValueLookupParameter<DoubleValue> FitnessParameter {
48      get { return (IValueLookupParameter<DoubleValue>)Parameters["Fitness"]; }
49    }
50    public ILookupParameter<IntValue> CurrentIterationParameter {
51      get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; }
52    }
53    public ILookupParameter<ItemArray<DoubleValue>> ParentAverageActionSetSizeParameter {
54      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentAverageActionSetSize"]; }
55    }
56    public ILookupParameter<ItemArray<DoubleValue>> ParentPredictionParameter {
57      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentPrediction"]; }
58    }
59    public ILookupParameter<ItemArray<DoubleValue>> ParentErrorParameter {
60      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentError"]; }
61    }
62    public ILookupParameter<ItemArray<DoubleValue>> ParentFitnessParameter {
63      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ParentFitness"]; }
64    }
65    #endregion
66
67    [StorableConstructor]
68    protected XCSAfterCrossoverOperator(bool deserializing) : base(deserializing) { }
69    protected XCSAfterCrossoverOperator(XCSAfterCrossoverOperator original, Cloner cloner)
70      : base(original, cloner) {
71    }
72    public XCSAfterCrossoverOperator()
73      : base() {
74      Parameters.Add(new ValueLookupParameter<IntValue>("Timestamp"));
75      Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageActionSetSize"));
76      Parameters.Add(new ValueLookupParameter<DoubleValue>("Prediction"));
77      Parameters.Add(new ValueLookupParameter<DoubleValue>("Error"));
78      Parameters.Add(new ValueLookupParameter<DoubleValue>("Fitness"));
79      Parameters.Add(new LookupParameter<IntValue>("CurrentIteration"));
80      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentAverageActionSetSize"));
81      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentPrediction"));
82      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentError"));
83      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentFitness"));
84    }
85    public override IDeepCloneable Clone(Cloner cloner) {
86      return new XCSAfterCrossoverOperator(this, cloner);
87    }
88
89    public override IOperation Apply() {
90      TimestampParameter.ActualValue = new IntValue(CurrentIterationParameter.ActualValue.Value);
91      var parentAverageActionSetSize = ParentAverageActionSetSizeParameter.ActualValue;
92      var parentPrecision = ParentPredictionParameter.ActualValue;
93      var parentPrecisionError = ParentErrorParameter.ActualValue;
94      var parentFitness = ParentFitnessParameter.ActualValue;
95      AverageActionSetSizeParameter.ActualValue = new DoubleValue(parentAverageActionSetSize.Select(x => x.Value).Average());
96      PredictionParameter.ActualValue = new DoubleValue(parentPrecision.Select(x => x.Value).Average());
97      ErrorParameter.ActualValue = new DoubleValue(0.25 * parentPrecisionError.Select(x => x.Value).Average());
98      FitnessParameter.ActualValue = new DoubleValue(0.1 * parentFitness.Select(x => x.Value).Average());
99      return base.Apply();
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.