Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/13 16:16:38 (12 years ago)
Author:
sforsten
Message:

#1980:

  • deleted not needed interface IMatching
  • finished VariableVector encoding
  • the algorithm LearningClassifierSystem is now independent of a specific encoding. It still needs the ConditionActionEncoding.
  • merged r9191:9203 HeuristicLab.Core from trunk to branch
Location:
branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystem.cs

    r9175 r9204  
    118118      get { return (ValueParameter<IntValue>)Parameters["MaxIterations"]; }
    119119    }
     120    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
     121      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
     122    }
     123    public IConstrainedValueParameter<IManipulator> MutatorParameter {
     124      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
     125    }
    120126    #endregion
    121127
     
    204210      get { return FinalAnalyzerParameter.Value; }
    205211      set { FinalAnalyzerParameter.Value = value; }
     212    }
     213    public ICrossover Crossover {
     214      get { return CrossoverParameter.Value; }
     215      set { CrossoverParameter.Value = value; }
     216    }
     217    public IManipulator Mutator {
     218      get { return MutatorParameter.Value; }
     219      set { MutatorParameter.Value = value; }
    206220    }
    207221    private RandomCreator RandomCreator {
     
    237251      Parameters.Add(new ValueParameter<MultiAnalyzer>("FinalAnalyzer", "The operator used to analyze the last generation.", new MultiAnalyzer()));
    238252      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "The maximum number of iterations.", new IntValue(1000)));
     253      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
     254      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    239255      #endregion
    240256
     
    256272      mainLoop.FinalAnalyzerParameter.ActualName = FinalAnalyzerParameter.Name;
    257273      mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name;
     274      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
     275      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
     276      mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
    258277      #endregion
    259278
     
    279298        ParameterizeEvaluator(Problem.Evaluator);
    280299        MainLoop.SetCurrentProblem(Problem);
     300        UpdateCrossovers();
     301        UpdateMutators();
    281302        UpdateAnalyzers();
     303        ParameterizeManipulator();
    282304      }
    283305      base.OnProblemChanged();
     306    }
     307
     308    private void ParameterizeManipulator() {
     309      foreach (var op in Problem.Operators.OfType<IProbabilityMutatorOperator>()) {
     310        op.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     311      }
    284312    }
    285313    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
     
    293321    }
    294322    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     323      UpdateCrossovers();
     324      UpdateMutators();
    295325      UpdateAnalyzers();
     326      ParameterizeManipulator();
    296327      base.Problem_OperatorsChanged(sender, e);
    297328    }
     
    305336    }
    306337
     338    private void UpdateCrossovers() {
     339      ICrossover oldCrossover = CrossoverParameter.Value;
     340      CrossoverParameter.ValidValues.Clear();
     341      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
     342
     343      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
     344        CrossoverParameter.ValidValues.Add(crossover);
     345
     346      if (oldCrossover != null) {
     347        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
     348        if (crossover != null) CrossoverParameter.Value = crossover;
     349        else oldCrossover = null;
     350      }
     351      if (oldCrossover == null && defaultCrossover != null)
     352        CrossoverParameter.Value = defaultCrossover;
     353    }
     354    private void UpdateMutators() {
     355      IManipulator oldMutator = MutatorParameter.Value;
     356      MutatorParameter.ValidValues.Clear();
     357      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     358
     359      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
     360        MutatorParameter.ValidValues.Add(mutator);
     361      if (oldMutator != null) {
     362        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
     363        if (mutator != null) MutatorParameter.Value = mutator;
     364        else oldMutator = null;
     365      }
     366      if (oldMutator == null && defaultMutator != null)
     367        MutatorParameter.Value = defaultMutator;
     368    }
    307369    private void UpdateAnalyzers() {
    308370      Analyzer.Operators.Clear();
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs

    r9194 r9204  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
    25 using HeuristicLab.Encodings.CombinedIntegerVectorEncoding;
    2625using HeuristicLab.Encodings.ConditionActionEncoding;
    2726using HeuristicLab.Operators;
     
    4645      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
    4746    }
    48     public IConstrainedValueParameter<ICrossover> CrossoverParameter {
    49       get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    50     }
    51     public IConstrainedValueParameter<IManipulator> MutatorParameter {
    52       get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
     47    public ValueLookupParameter<PercentValue> CrossoverProbabilityParameter {
     48      get { return adaptedGeneticAlgorithmMainLoop.CrossoverProbabilityParameter; }
     49    }
     50    public ValueLookupParameter<IOperator> CrossoverParameter {
     51      get { return adaptedGeneticAlgorithmMainLoop.CrossoverParameter; }
     52    }
     53    public ValueLookupParameter<IOperator> MutatorParameter {
     54      get { return adaptedGeneticAlgorithmMainLoop.MutatorParameter; }
    5355    }
    5456    public IConstrainedValueParameter<IOperator> AfterCopyingParentsParameter {
     
    7880    private CountNumberOfUniqueActions countNumberOfUniqueActions;
    7981
    80     private UniformSomePositionManipulator test;
     82    private LCSAdaptedGeneticAlgorithm adaptedGeneticAlgorithmMainLoop;
    8183
    8284    private Placeholder evaluator;
     
    102104      #region Create parameters
    103105      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.", new ItemSet<ISelector>() { new ProportionalSelector() }, new ProportionalSelector()));
    104       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()));
    105106      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."));
    106       test = new UniformSomePositionManipulator();
    107       test.ProbabilityParameter.ActualName = "MutationProbability";
    108       test.ChildParameter.ActualName = "CombinedIntegerVector";
    109       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.", new ItemSet<IManipulator>() { new UniformSomePositionManipulator() }, test));
    110107      XCSAfterCopyingParentOperator afterCopyingParents = new XCSAfterCopyingParentOperator();
    111108      Parameters.Add(new ConstrainedValueParameter<IOperator>("AfterCopyingParents", "", new ItemSet<IOperator>() { new XCSAfterCopyingParentOperator() }, afterCopyingParents));
     
    162159      UniformSubScopesProcessor timestampAssignerSubscopeProcessor = new UniformSubScopesProcessor();
    163160      Assigner timestampAssigner = new Assigner();
    164       LCSAdaptedGeneticAlgorithm adaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm();
     161      adaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm();
    165162      IntCounter currentPopulationSizeCounter = new IntCounter();
    166163      CalculateNumberOfDeletionsOperator calculateNumberOfDeletions = new CalculateNumberOfDeletionsOperator();
     
    313310
    314311      adaptedGeneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
    315       adaptedGeneticAlgorithmMainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
    316       adaptedGeneticAlgorithmMainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
    317312      adaptedGeneticAlgorithmMainLoop.RandomParameter.ActualName = "Random";
    318313      adaptedGeneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue";
     
    440435      classifierFetcher.OperatorParameter.ActualName = problem.ClassifierFetcherParameter.Name;
    441436
    442       test.FetchedConditionParameter.ActualName = problem.ClassifierFetcher.CurrentInputToMatchParameter.ActualName;
    443       test.PossibleActionsParameter.ActualName = problem.PossibleActionsConcreteClassParameter.Name;
    444 
    445437      actionExecuter.OperatorParameter.ActualName = problem.ActionExecuterParameter.Name;
    446438
Note: See TracChangeset for help on using the changeset viewer.