Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1980:

  • added necessary interface ICondition, IAction, IInput
  • removed not used class MatchSelector and interface IMatchSelector
  • added constructors to ItemDictionary
  • added new encoding
File size: 5.9 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 abstract 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    public ILookupParameter<IClassifierComparer> ClassifierComparerParameter {
69      get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; }
70    }
71
72    public ResultCollection Results { get { return ResultsParameter.ActualValue; } }
73
74    [StorableConstructor]
75    protected XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { }
76    protected XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
77    public XCSSolutionAnalyzer()
78      : base() {
79      Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifier", ""));
80      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Prediction", ""));
81      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Error", ""));
82      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Fitness", ""));
83      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Experience", ""));
84      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Timestamp", ""));
85      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("AverageActionSetSize", ""));
86      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Numerosity", ""));
87      Parameters.Add(new LookupParameter<IConditionActionProblemData>("ProblemData", ""));
88      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the solution should be stored."));
89      Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer"));
90    }
91
92    public override IOperation Apply() {
93      ItemArray<IClassifier> classifiers = ClassifierParameter.ActualValue;
94      ItemArray<DoubleValue> predictions = PredictionParameter.ActualValue;
95      ItemArray<DoubleValue> errors = ErrorParameter.ActualValue;
96      ItemArray<DoubleValue> fitnesses = FitnessParameter.ActualValue;
97      ItemArray<IntValue> experiences = ExperienceParameter.ActualValue;
98      ItemArray<IntValue> timestamps = TimestampParameter.ActualValue;
99      ItemArray<DoubleValue> averageActionSetSizes = AverageActionSetSizeParameter.ActualValue;
100      ItemArray<IntValue> numerosities = NumerosityParameter.ActualValue;
101      IConditionActionProblemData problemData = ProblemDataParameter.ActualValue;
102
103      ItemCollection<XCSClassifier> xcsClassifiers = new ItemCollection<XCSClassifier>();
104
105      for (int i = 0; i < classifiers.Length; i++) {
106        xcsClassifiers.Add(new XCSClassifier(classifiers[i], predictions[i], errors[i],
107          fitnesses[i], experiences[i], timestamps[i], averageActionSetSizes[i], numerosities[i]));
108      }
109
110      XCSModel xcsModel = new XCSModel(xcsClassifiers);
111      xcsModel.ClassifierComparer = ClassifierComparerParameter.ActualValue;
112      UseCurrentXCSSolution(xcsModel.CreateConditionActionSolution(problemData));
113      return base.Apply();
114    }
115
116    protected abstract void UseCurrentXCSSolution(IXCSSolution xcsSolution);
117  }
118}
Note: See TracBrowser for help on using the repository browser.