Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Covering/VariableVectorCoveringCreator.cs @ 13825

Last change on this file since 13825 was 9242, checked in by sforsten, 12 years ago

#1980:

  • fixed several bugs (crossover, subsumption, serialization etc.)
  • added ModuloOperator
  • CombinedIntegerVectorClassificationProblem\Data and VariableVectorClassificationProblem\Data inherit from ConditionActionClassificationProblem\Data
  • it can now be set how often the analyzers have to be executed
  • VariableVectorAction, VariableVectorCondition and VariableVectorInput now inherit from Item
File size: 3.6 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 System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.ConditionActionEncoding;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.VariableVector {
32  [Item("VariableVectorCoveringCreator", "Description missing")]
33  [StorableClass]
34  public class VariableVectorCoveringCreator : CoveringSolutionCreator, IVariableVectorCoveringCreator {
35
36    public IValueLookupParameter<IVariableVectorClassificationProblemData> ProblemDataParameter {
37      get { return (IValueLookupParameter<IVariableVectorClassificationProblemData>)Parameters["ProblemData"]; }
38    }
39
40    private IVariableVectorClassificationProblemData ProblemData {
41      get { return ProblemDataParameter.ActualValue; }
42    }
43
44    [StorableConstructor]
45    protected VariableVectorCoveringCreator(bool deserializing) : base(deserializing) { }
46    protected VariableVectorCoveringCreator(VariableVectorCoveringCreator original, Cloner cloner)
47      : base(original, cloner) {
48    }
49    public VariableVectorCoveringCreator()
50      : base() {
51      Parameters.Add(new ValueLookupParameter<IVariableVectorClassificationProblemData>("ProblemData"));
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new VariableVectorCoveringCreator(this, cloner);
55    }
56
57    protected override IClassifier CreateCoveredClassifier(IInput input, IAction action, IRandom random, double changeSymbolProbability) {
58      var inputCast = input as VariableVectorInput;
59      var actionCast = action as VariableVectorAction;
60
61      VariableVectorCondition sampleVariableVectorCondition = ProblemData.SampleVariableVectorParameter.Value.Condition;
62      IEnumerable<IVariable> newCondition = CoverInput(inputCast, sampleVariableVectorCondition, random, changeSymbolProbability);
63
64      return new VariableVector(newCondition, actionCast.VariableDictionary.Values);
65    }
66
67    private IEnumerable<IVariable> CoverInput(VariableVectorInput input, VariableVectorCondition sample, IRandom random, double changeSymbolProbability) {
68      List<IVariable> conditionVariables = new List<IVariable>();
69      if (!sample.VariableDictionary.Keys.All(x => input.InputDictionary.ContainsKey(x))) {
70        throw new ArgumentException("Input does not contain all variable names from sample");
71      }
72      foreach (var keyValuePair in sample.VariableDictionary) {
73        IVariable variable = keyValuePair.Value.GetEmptyCopy();
74        variable.Cover(random, input.InputDictionary[keyValuePair.Key], changeSymbolProbability);
75        conditionVariables.Add(variable);
76      }
77      return conditionVariables;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.