[9154] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Encodings.ConditionActionEncoding {
|
---|
| 31 | [Item("ConditionActionSolutionAnalyzer", "")]
|
---|
| 32 | [StorableClass]
|
---|
[9175] | 33 | public abstract class XCSSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
[9154] | 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 | }
|
---|
[9194] | 68 | public ILookupParameter<IClassifierComparer> ClassifierComparerParameter {
|
---|
| 69 | get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; }
|
---|
| 70 | }
|
---|
[9154] | 71 |
|
---|
[9175] | 72 | public ResultCollection Results { get { return ResultsParameter.ActualValue; } }
|
---|
| 73 |
|
---|
[9154] | 74 | [StorableConstructor]
|
---|
[9175] | 75 | protected XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 76 | protected XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
[9154] | 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."));
|
---|
[9194] | 89 | Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer"));
|
---|
[9154] | 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);
|
---|
[9194] | 111 | xcsModel.ClassifierComparer = ClassifierComparerParameter.ActualValue;
|
---|
[9175] | 112 | UseCurrentXCSSolution(xcsModel.CreateConditionActionSolution(problemData));
|
---|
[9154] | 113 | return base.Apply();
|
---|
| 114 | }
|
---|
[9175] | 115 |
|
---|
| 116 | protected abstract void UseCurrentXCSSolution(IXCSSolution xcsSolution);
|
---|
[9154] | 117 | }
|
---|
| 118 | }
|
---|