Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/GA/XCSCheckIfGAShouldBeApplied.cs @ 10138

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

#1980:

  • included an adapted version of GA correctly
  • added action set subsumption
  • added deletion after GA and before covering
File size: 3.7 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;
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("CheckIfGAShouldBeApplied", "Description missing")]
32  [StorableClass]
33  public class XCSCheckIfGAShouldBeApplied : SingleSuccessorOperator {
34
35    #region Parameter Properties
36    public ILookupParameter<IntValue> ThetaGAParameter {
37      get { return (ILookupParameter<IntValue>)Parameters["ThetaGA"]; }
38    }
39    public ILookupParameter<IntValue> IterationParameter {
40      get { return (ILookupParameter<IntValue>)Parameters["Iteration"]; }
41    }
42    public ILookupParameter<ItemArray<IntValue>> TimeStampsParameter {
43      get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["TimeStamps"]; }
44    }
45    public ILookupParameter<ItemArray<IntValue>> NumerositiesParameter {
46      get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["Numerosities"]; }
47    }
48    public IValueLookupParameter<BoolValue> RunGAParameter {
49      get { return (IValueLookupParameter<BoolValue>)Parameters["RunGA"]; }
50    }
51    #endregion
52
53    [StorableConstructor]
54    protected XCSCheckIfGAShouldBeApplied(bool deserializing) : base(deserializing) { }
55    protected XCSCheckIfGAShouldBeApplied(XCSCheckIfGAShouldBeApplied original, Cloner cloner)
56      : base(original, cloner) {
57    }
58    public XCSCheckIfGAShouldBeApplied()
59      : base() {
60      Parameters.Add(new LookupParameter<IntValue>("ThetaGA"));
61      Parameters.Add(new LookupParameter<IntValue>("Iteration"));
62      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("TimeStamps"));
63      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Numerosities"));
64      Parameters.Add(new ValueLookupParameter<BoolValue>("RunGA"));
65    }
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new XCSCheckIfGAShouldBeApplied(this, cloner);
68    }
69
70    public override IOperation Apply() {
71      int numerositySum = 0;
72      int timestamNumerositySum = 0;
73
74      var timestamps = TimeStampsParameter.ActualValue;
75      var numerosities = NumerositiesParameter.ActualValue;
76      int actualtime = IterationParameter.ActualValue.Value;
77      int thetaGA = ThetaGAParameter.ActualValue.Value;
78
79      if (timestamps.Length != numerosities.Length) {
80        throw new ArgumentException("The number of timestamps and numerosities is not the same.");
81      }
82
83      for (int i = 0; i < numerosities.Length; i++) {
84        numerositySum += numerosities[i].Value;
85        timestamNumerositySum += timestamps[i].Value * numerosities[i].Value;
86      }
87
88      RunGAParameter.ActualValue = new BoolValue(actualtime - (timestamNumerositySum / numerositySum) > thetaGA);
89
90      return base.Apply();
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.