Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/27/12 19:14:51 (12 years ago)
Author:
sforsten
Message:

#1980:

  • added ConditionActionClassificationProblem
  • added ConditionActionEncoding
  • added Manipulators, Crossovers and an LCSAdaptedGeneticAlgorithm
  • changed LearningClassifierSystemMainLoop
Location:
branches/LearningClassifierSystems
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems

    • Property svn:ignore set to
      *.suo
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3

    • Property svn:ignore set to
      *.user
      Plugin.cs
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs

    r8941 r9089  
    2020#endregion
    2121
    22 using HeuristicLab.Algorithms.GeneticAlgorithm;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
    26 using HeuristicLab.Encodings.CombinedIntegerVectorEncoding;
     25using HeuristicLab.Encodings.ConditionActionEncoding;
    2726using HeuristicLab.Encodings.IntegerVectorEncoding;
    2827using HeuristicLab.Operators;
     
    3130using HeuristicLab.Parameters;
    3231using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    33 using HeuristicLab.Random;
    3432using HeuristicLab.Selection;
    3533
     
    4038  [Item("LearningClassifierSystemMainLoop", "An operator which represents the main loop of a learning classifier system.")]
    4139  [StorableClass]
    42   public class LearningClassifierSystemMainLoop : AlgorithmOperator {
     40  public sealed class LearningClassifierSystemMainLoop : AlgorithmOperator {
    4341
    4442    #region Parameter Properties
     
    5452    #endregion
    5553
    56     #region Properties
    57     public ISelector Selector {
    58       get { return SelectorParameter.Value; }
    59       set { SelectorParameter.Value = value; }
    60     }
    61     public ICrossover Crossover {
    62       get { return CrossoverParameter.Value; }
    63       set { CrossoverParameter.Value = value; }
    64     }
    65     public IManipulator Mutator {
    66       get { return MutatorParameter.Value; }
    67       set { MutatorParameter.Value = value; }
    68     }
     54    #region private properties
     55    private SolutionsCreator initialSolutionsCreator;
     56    private SolutionsCreator coveringMechanism;
     57    private MatchConditionOperator matchConditionOperator;
     58    private PredictionArrayCalculator predictionArrayCalculator;
     59    private ActionSelector actionSelector;
     60
     61    private Placeholder evaluator;
     62    private Placeholder actionExecuter;
     63    private Placeholder classifierFetcher;
    6964    #endregion
    7065
    7166    [StorableConstructor]
    7267    private LearningClassifierSystemMainLoop(bool deserializing) : base(deserializing) { }
    73     protected LearningClassifierSystemMainLoop(LearningClassifierSystemMainLoop original, Cloner cloner)
     68    private LearningClassifierSystemMainLoop(LearningClassifierSystemMainLoop original, Cloner cloner)
    7469      : base(original, cloner) {
    7570    }
     
    8580      #region Create parameters
    8681      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.", new ItemSet<ISelector>() { new ProportionalSelector() }, new ProportionalSelector()));
    87       Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.", new ItemSet<ICrossover>() { new SinglePointCrossover() }, new SinglePointCrossover()));
    88       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.", new ItemSet<IManipulator>() { new UniformOnePositionManipulator() }, new UniformOnePositionManipulator()));
    89       //for test purposes
    90       int[] numbers = new int[3] { 1, 1, 1 };
    91       int[,] elements = new int[,] { { 0, 3 }, { 0, 3 }, { 0, 2 } };
    92       Parameters.Add(new ValueLookupParameter<CombinedIntegerVector>("TestTarget", "Target for test", new CombinedIntegerVector(numbers, 1, elements)));
    93 
     82      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.", new ItemSet<ICrossover>() { new HeuristicLab.Encodings.CombinedIntegerVectorEncoding.SinglePointCrossover() }, new HeuristicLab.Encodings.CombinedIntegerVectorEncoding.SinglePointCrossover()));
     83      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     84      UniformOnePositionManipulator test = new UniformOnePositionManipulator();
     85      test.IntegerVectorParameter.ActualName = "CombinedIntegerVector";
     86      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.", new ItemSet<IManipulator>() { new UniformOnePositionManipulator() }, test));
    9487      #endregion
    9588
    9689      #region Create operators
    9790      VariableCreator variableCreator = new VariableCreator();
    98       MatchSelector conditionMatchSelector = new MatchSelector();
    99       MatchSelector actionMatchSelector = new MatchSelector();
     91      ConditionalBranch initialPopulationConditionalBranch = new ConditionalBranch();
     92      initialSolutionsCreator = new SolutionsCreator();
     93      IntCounter iterationCounter = new IntCounter();
     94      UniformSubScopesProcessor matchCondtionSubScopesProcessor = new UniformSubScopesProcessor();
     95      matchConditionOperator = new MatchConditionOperator();
     96      predictionArrayCalculator = new PredictionArrayCalculator();
     97      actionSelector = new ActionSelector();
     98      UniformSubScopesProcessor matchActionSubScopesProcessor = new UniformSubScopesProcessor();
     99      MatchActionOperator matchActionOperator = new MatchActionOperator();
     100      ConditionalSelector conditionMatchSelector = new ConditionalSelector();
     101      ConditionalSelector actionMatchSelector = new ConditionalSelector();
    100102      SubScopesProcessor coveringSubScopesProcessor = new SubScopesProcessor();
    101       SubScopesRemover subScopesRemover = new SubScopesRemover();
     103      SubScopesCounter matchsetCounter = new SubScopesCounter();
    102104      Comparator comparator = new Comparator();
    103       ConditionalBranch conditionalBranch = new ConditionalBranch();
     105      ConditionalBranch coveringConditionalBranch = new ConditionalBranch();
    104106      MergingReducer mergingReducer = new MergingReducer();
    105       SolutionsCreator coveringMechanism = new SolutionsCreator();
    106       SubScopesProcessor actionSelectionSubScopesProcessor = new SubScopesProcessor();
    107       MaxValueActionSelector maxValueActionSelection = new MaxValueActionSelector();
    108       GeneticAlgorithmMainLoop geneticAlgorithmMainLoop = new GeneticAlgorithmMainLoop();
    109 
    110       UniformSubScopesProcessor uniformSubScopeProcessor = new UniformSubScopesProcessor();
    111       UniformRandomizer uniformRandomizer = new UniformRandomizer();
     107      MergingReducer mergingReducerWithSuccessor = new MergingReducer();
     108      coveringMechanism = new SolutionsCreator();
     109      evaluator = new Placeholder();
     110      SubScopesProcessor actionSetSubScopesProcessor = new SubScopesProcessor();
     111      DataReducer actionSetSizeDataReducer = new DataReducer();
     112      UniformSubScopesProcessor accuracySubScopesProcessor = new UniformSubScopesProcessor();
     113      CalculateAccuracy calculateAccuracy = new CalculateAccuracy();
     114      SumAccuracy sumAccuracy = new SumAccuracy();
     115      UniformSubScopesProcessor updateParametersSubScopesProcessor = new UniformSubScopesProcessor();
     116      LCSAdaptedGeneticAlgorithm adaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm();
     117
     118      classifierFetcher = new Placeholder();
     119      actionExecuter = new Placeholder();
    112120
    113121      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("ZeroIntValue", new IntValue(0)));
    114122      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OneIntValue", new IntValue(1)));
     123      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iteration", new IntValue(0)));
     124
     125      initialPopulationConditionalBranch.ConditionParameter.ActualName = "CreateInitialPopulation";
     126
     127      initialSolutionsCreator.NumberOfSolutionsParameter.ActualName = "N";
     128
     129      iterationCounter.ValueParameter.ActualName = "Iteration";
     130      iterationCounter.IncrementParameter.ActualName = "OneIntValue";
     131
     132      matchCondtionSubScopesProcessor.Operator = matchConditionOperator;
     133
     134      matchConditionOperator.MatchParameter.ActualName = "CombinedIntegerVector";
    115135
    116136      conditionMatchSelector.CopySelected = new BoolValue(false);
    117       conditionMatchSelector.MatchCondition = new BoolValue(true);
    118       //this has to be set differently
    119       conditionMatchSelector.MatchParameter.ActualName = "CombinedIntegerVector";
    120       conditionMatchSelector.TargetMatchParameter.ActualName = "TestTarget";
     137      conditionMatchSelector.ConditionParameter.ActualName = "MatchCondition";
     138
     139      matchsetCounter.Name = "Count number of rules in match set";
     140      matchsetCounter.AccumulateParameter.Value = new BoolValue(false);
     141      matchsetCounter.ValueParameter.ActualName = "MatchSetCount";
    121142
    122143      comparator.Comparison = new Comparison(ComparisonType.LessOrEqual);
    123       comparator.LeftSideParameter.ActualName = conditionMatchSelector.NumberOfSelectedSubScopesParameter.ActualName;
     144      comparator.LeftSideParameter.ActualName = matchsetCounter.ValueParameter.ActualName;
    124145      comparator.ResultParameter.ActualName = "Covering";
    125146      //more than zero solutions have to be selected
    126147      comparator.RightSideParameter.ActualName = "ZeroIntValue";
    127148
    128       conditionalBranch.ConditionParameter.ActualName = "Covering";
    129 
    130       subScopesRemover.SubScopeIndexParameter.ActualName = "OneIntValue";
    131       subScopesRemover.RemoveAllSubScopes = false;
     149      coveringConditionalBranch.Name = "Covering Branch";
     150      coveringConditionalBranch.ConditionParameter.ActualName = "Covering";
     151
     152      matchActionSubScopesProcessor.Operator = matchActionOperator;
     153
     154      matchActionOperator.MatchParameter.ActualName = "CombinedIntegerVector";
     155      matchActionOperator.TargetMatchParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
    132156
    133157      coveringMechanism.NumberOfSolutionsParameter.ActualName = "OneIntValue";
    134       coveringMechanism.SolutionCreatorParameter.ActualName = "SolutionCreator";
    135 
    136       maxValueActionSelection.ValueParameter.ActualName = "Fitness";
    137       maxValueActionSelection.MatchParameter.ActualName = "CombinedIntegerVector";
     158
     159      predictionArrayCalculator.MatchParameter.ActualName = "CombinedIntegerVector";
     160
     161      actionSelector.PredictionArrayParameter.ActualName = predictionArrayCalculator.PredictionArrayParameter.Name;
     162      actionSelector.RandomParameter.ActualName = "Random";
     163      actionSelector.ExplorationProbabilityParameter.ActualName = "ExplorationProbability";
    138164
    139165      actionMatchSelector.CopySelected = new BoolValue(false);
    140       actionMatchSelector.MatchCondition = new BoolValue(false);
    141       //this has to be set differently
    142       actionMatchSelector.MatchParameter.ActualName = "CombinedIntegerVector";
    143       actionMatchSelector.TargetMatchParameter.ActualName = maxValueActionSelection.SelectedActionParameter.ActualName;
     166      actionMatchSelector.ConditionParameter.ActualName = "MatchAction";
    144167
    145168      SelectorParameter.Value.CopySelected = new BoolValue(true);
    146169      SelectorParameter.Value.NumberOfSelectedSubScopesParameter.Value = new IntValue(200);
    147170
    148       geneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    149       geneticAlgorithmMainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
    150       geneticAlgorithmMainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
    151       geneticAlgorithmMainLoop.RandomParameter.ActualName = "Random";
    152       geneticAlgorithmMainLoop.ElitesParameter.ActualName = "OneIntValue";
    153       geneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue";
    154       geneticAlgorithmMainLoop.QualityParameter.ActualName = "Fitness";
     171      evaluator.Name = "Evaluator";
     172
     173      classifierFetcher.Name = "ClassifierFetcher";
     174
     175      actionExecuter.Name = "ActionExecuter";
     176
     177      actionSetSizeDataReducer.TargetParameter.ActualName = "CurrentActionSetSize";
     178      actionSetSizeDataReducer.ParameterToReduce.ActualName = "Numerosity";
     179      actionSetSizeDataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     180      actionSetSizeDataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
     181
     182      calculateAccuracy.AlphaParameter.ActualName = "Alpha";
     183      calculateAccuracy.ErrorParameter.ActualName = "Error";
     184      calculateAccuracy.ErrorZeroParameter.ActualName = "ErrorZero";
     185      calculateAccuracy.PowerParameter.ActualName = "v";
     186
     187      sumAccuracy.AccuracyParameter.ActualName = calculateAccuracy.AccuracyParameter.ActualName;
     188      sumAccuracy.NumerosityParameter.ActualName = "Numerosity";
     189
     190      adaptedGeneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
     191      adaptedGeneticAlgorithmMainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
     192      adaptedGeneticAlgorithmMainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
     193      adaptedGeneticAlgorithmMainLoop.RandomParameter.ActualName = "Random";
     194      adaptedGeneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue";
     195      adaptedGeneticAlgorithmMainLoop.QualityParameter.ActualName = "Fitness";
    155196      //needed?
    156       geneticAlgorithmMainLoop.MutationProbabilityParameter.Value = new PercentValue(10);
    157       geneticAlgorithmMainLoop.MaximizationParameter.Value = new BoolValue(true);
    158 
    159       uniformSubScopeProcessor.Parallel = new BoolValue(true);
    160 
    161       uniformRandomizer.RandomParameter.ActualName = "Random";
    162       uniformRandomizer.MinParameter.Value = new DoubleValue(0);
    163       uniformRandomizer.MaxParameter.Value = new DoubleValue(100);
    164       uniformRandomizer.ValueParameter.ActualName = "Fitness";
    165 
    166       //ParameterizeSelectors();
     197      adaptedGeneticAlgorithmMainLoop.MutationProbabilityParameter.Value = new PercentValue(10);
     198      adaptedGeneticAlgorithmMainLoop.MaximizationParameter.Value = new BoolValue(true);
    167199      #endregion
    168200
    169201      #region Create operator graph
    170202      OperatorGraph.InitialOperator = variableCreator;
    171       variableCreator.Successor = conditionMatchSelector;
    172       //variableCreator.Successor = geneticAlgorithmMainLoop;
    173       //geneticAlgorithmMainLoop.Successor = conditionMatchSelector;
    174       conditionMatchSelector.Successor = comparator;
    175       comparator.Successor = conditionalBranch;
    176       conditionalBranch.TrueBranch = coveringSubScopesProcessor;
    177       conditionalBranch.FalseBranch = actionSelectionSubScopesProcessor;
    178       conditionalBranch.Successor = subScopesRemover;
    179       coveringMechanism.Successor = uniformSubScopeProcessor;
    180       uniformSubScopeProcessor.Operator = uniformRandomizer;
     203
     204      variableCreator.Successor = initialPopulationConditionalBranch;
     205      initialPopulationConditionalBranch.TrueBranch = initialSolutionsCreator;
     206      initialPopulationConditionalBranch.FalseBranch = new EmptyOperator();
     207      initialPopulationConditionalBranch.Successor = classifierFetcher;
     208      classifierFetcher.Successor = matchCondtionSubScopesProcessor;
     209      matchCondtionSubScopesProcessor.Successor = conditionMatchSelector;
     210      //variableCreator.Successor = adaptedGeneticAlgorithmMainLoop;
     211      //adaptedGeneticAlgorithmMainLoop.Successor = conditionMatchSelector;
     212
     213      conditionMatchSelector.Successor = coveringSubScopesProcessor;
    181214      coveringSubScopesProcessor.Operators.Add(new EmptyOperator());
    182       coveringSubScopesProcessor.Operators.Add(coveringMechanism);
    183       coveringSubScopesProcessor.Successor = actionSelectionSubScopesProcessor;
    184       actionSelectionSubScopesProcessor.Operators.Add(new EmptyOperator());
    185       actionSelectionSubScopesProcessor.Operators.Add(maxValueActionSelection);
    186       maxValueActionSelection.Successor = actionMatchSelector;
    187       subScopesRemover.Successor = mergingReducer;
    188       mergingReducer.Successor = conditionMatchSelector;
    189       //mergingReducer.Successor = geneticAlgorithmMainLoop;
     215      coveringSubScopesProcessor.Operators.Add(matchsetCounter);
     216      coveringSubScopesProcessor.Successor = mergingReducerWithSuccessor;
     217      matchsetCounter.Successor = comparator;
     218      comparator.Successor = coveringConditionalBranch;
     219      coveringConditionalBranch.TrueBranch = coveringMechanism;
     220      coveringConditionalBranch.FalseBranch = new EmptyOperator();
     221      coveringConditionalBranch.Successor = predictionArrayCalculator;
     222      predictionArrayCalculator.Successor = actionSelector;
     223      actionSelector.Successor = matchActionSubScopesProcessor;
     224      matchActionSubScopesProcessor.Successor = actionMatchSelector;
     225      actionMatchSelector.Successor = actionExecuter;
     226      actionExecuter.Successor = actionSetSubScopesProcessor;
     227      actionSetSubScopesProcessor.Operators.Add(new EmptyOperator());
     228      actionSetSubScopesProcessor.Operators.Add(actionSetSizeDataReducer);
     229      actionSetSizeDataReducer.Successor = accuracySubScopesProcessor;
     230      accuracySubScopesProcessor.Operator = calculateAccuracy;
     231      accuracySubScopesProcessor.Successor = sumAccuracy;
     232      sumAccuracy.Successor = updateParametersSubScopesProcessor;
     233      updateParametersSubScopesProcessor.Operator = evaluator;
     234
     235      actionSetSubScopesProcessor.Successor = mergingReducer;
     236
     237      mergingReducerWithSuccessor.Successor = iterationCounter;
     238      iterationCounter.Successor = classifierFetcher;
     239      //mergingReducer.Successor = adaptedGeneticAlgorithmMainLoop;
    190240      #endregion
    191241    }
     
    197247        stochasticOp.RandomParameter.Hidden = true;
    198248      }
     249    }
     250
     251    internal void SetCurrentProblem(IConditionActionProblem problem) {
     252      initialSolutionsCreator.SolutionCreatorParameter.ActualName = problem.SolutionCreatorParameter.Name;
     253      initialSolutionsCreator.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
     254
     255      coveringMechanism.SolutionCreatorParameter.ActualName = problem.SolutionCreatorParameter.Name;
     256      coveringMechanism.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
     257
     258      problem.ActionExecuter.SelectedActionParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
     259
     260      problem.ClassifierFetcher.IterationParameter.ActualName = "Iteration";
     261
     262      evaluator.OperatorParameter.ActualName = problem.EvaluatorParameter.Name;
     263
     264      classifierFetcher.OperatorParameter.ActualName = problem.ClassifierFetcherParameter.Name;
     265
     266      actionExecuter.OperatorParameter.ActualName = problem.ActionExecuterParameter.Name;
     267
     268      matchConditionOperator.TargetMatchParameter.ActualName = problem.ClassifierFetcher.CurrentClassifierToMatchParameter.Name;
     269
     270      predictionArrayCalculator.PredictionParameter.ActualName = problem.Evaluator.PredictionParameter.ActualName;
     271      predictionArrayCalculator.FitnessParameter.ActualName = problem.Evaluator.FitnessParameter.ActualName;
    199272    }
    200273    //private void ParameterizeSelectors() {
Note: See TracChangeset for help on using the changeset viewer.