Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Analyzer/XCSSolutionAnalyzer.cs @ 9154

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

#1980:

  • added XCSSolution, XCSModel, XCSClassifier to represent the xcs classifier
  • XCSSolution also shows the current accuracy (training and test partition has to be added)
  • added XCSSolutionAnalyzer to create a XCSSolution during the run of the algorithm
  • added XCSModelView to show the xcs model
  • fixed a bug in XCSDeletionOperator (sometimes it deleted less classifiers than it should)
  • moved some parameter from ConditionActionClassificationProblem to ConditionActionClassificationProblemData
File size: 5.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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Encodings.ConditionActionEncoding {
31  [Item("ConditionActionSolutionAnalyzer", "")]
32  [StorableClass]
33  public sealed class XCSSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
34    public bool EnabledByDefault {
35      get { return true; }
36    }
37
38    public ScopeTreeLookupParameter<IClassifier> ClassifierParameter {
39      get { return (ScopeTreeLookupParameter<IClassifier>)Parameters["Classifier"]; }
40    }
41    public ScopeTreeLookupParameter<DoubleValue> PredictionParameter {
42      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Prediction"]; }
43    }
44    public ScopeTreeLookupParameter<DoubleValue> ErrorParameter {
45      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Error"]; }
46    }
47    public ScopeTreeLookupParameter<DoubleValue> FitnessParameter {
48      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Fitness"]; }
49    }
50    public ScopeTreeLookupParameter<IntValue> ExperienceParameter {
51      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["Experience"]; }
52    }
53    public ScopeTreeLookupParameter<IntValue> TimestampParameter {
54      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["Timestamp"]; }
55    }
56    public ScopeTreeLookupParameter<DoubleValue> AverageActionSetSizeParameter {
57      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["AverageActionSetSize"]; }
58    }
59    public ScopeTreeLookupParameter<IntValue> NumerosityParameter {
60      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["Numerosity"]; }
61    }
62    public LookupParameter<IConditionActionProblemData> ProblemDataParameter {
63      get { return (LookupParameter<IConditionActionProblemData>)Parameters["ProblemData"]; }
64    }
65    public ValueLookupParameter<ResultCollection> ResultsParameter {
66      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
67    }
68
69    [StorableConstructor]
70    private XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { }
71    private XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new XCSSolutionAnalyzer(this, cloner);
74    }
75    public XCSSolutionAnalyzer()
76      : base() {
77      Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifier", ""));
78      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Prediction", ""));
79      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Error", ""));
80      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Fitness", ""));
81      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Experience", ""));
82      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Timestamp", ""));
83      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("AverageActionSetSize", ""));
84      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Numerosity", ""));
85      Parameters.Add(new LookupParameter<IConditionActionProblemData>("ProblemData", ""));
86      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the solution should be stored."));
87    }
88
89    public override IOperation Apply() {
90      ItemArray<IClassifier> classifiers = ClassifierParameter.ActualValue;
91      ItemArray<DoubleValue> predictions = PredictionParameter.ActualValue;
92      ItemArray<DoubleValue> errors = ErrorParameter.ActualValue;
93      ItemArray<DoubleValue> fitnesses = FitnessParameter.ActualValue;
94      ItemArray<IntValue> experiences = ExperienceParameter.ActualValue;
95      ItemArray<IntValue> timestamps = TimestampParameter.ActualValue;
96      ItemArray<DoubleValue> averageActionSetSizes = AverageActionSetSizeParameter.ActualValue;
97      ItemArray<IntValue> numerosities = NumerosityParameter.ActualValue;
98      ResultCollection results = ResultsParameter.ActualValue;
99      IConditionActionProblemData problemData = ProblemDataParameter.ActualValue;
100
101      ItemCollection<XCSClassifier> xcsClassifiers = new ItemCollection<XCSClassifier>();
102
103      for (int i = 0; i < classifiers.Length; i++) {
104        xcsClassifiers.Add(new XCSClassifier(classifiers[i], predictions[i], errors[i],
105          fitnesses[i], experiences[i], timestamps[i], averageActionSetSizes[i], numerosities[i]));
106      }
107
108      XCSModel xcsModel = new XCSModel(xcsClassifiers);
109
110      if (results.ContainsKey("XCSSolution")) {
111        results.Remove("XCSSolution");
112      }
113      results.Add(new Result("XCSSolution", xcsModel.CreateConditionActionSolution(problemData)));
114
115      return base.Apply();
116    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.