Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9090


Ignore:
Timestamp:
12/29/12 20:15:48 (12 years ago)
Author:
sforsten
Message:

#1980: implemented covering and changed SinglePointCrossover for CombinedIntegerVectorEncoding

Location:
branches/LearningClassifierSystems
Files:
1 added
1 deleted
17 edited

Legend:

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

    • Property svn:ignore
      •  

        old new  
        11*.user
        22Plugin.cs
         3obj
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs

    r9089 r9090  
    5454    #region private properties
    5555    private SolutionsCreator initialSolutionsCreator;
    56     private SolutionsCreator coveringMechanism;
    5756    private MatchConditionOperator matchConditionOperator;
    5857    private PredictionArrayCalculator predictionArrayCalculator;
    5958    private ActionSelector actionSelector;
     59    private CoveringOperator covering;
    6060
    6161    private Placeholder evaluator;
     
    100100      ConditionalSelector conditionMatchSelector = new ConditionalSelector();
    101101      ConditionalSelector actionMatchSelector = new ConditionalSelector();
    102       SubScopesProcessor coveringSubScopesProcessor = new SubScopesProcessor();
    103       SubScopesCounter matchsetCounter = new SubScopesCounter();
    104       Comparator comparator = new Comparator();
    105       ConditionalBranch coveringConditionalBranch = new ConditionalBranch();
     102      SubScopesProcessor matchSetSubScopesProcessor = new SubScopesProcessor();
     103      CountNumberOfUniqueActions countNumberOfUniqueActions = new CountNumberOfUniqueActions();
     104      covering = new CoveringOperator();
    106105      MergingReducer mergingReducer = new MergingReducer();
    107106      MergingReducer mergingReducerWithSuccessor = new MergingReducer();
    108       coveringMechanism = new SolutionsCreator();
    109107      evaluator = new Placeholder();
    110108      SubScopesProcessor actionSetSubScopesProcessor = new SubScopesProcessor();
     
    137135      conditionMatchSelector.ConditionParameter.ActualName = "MatchCondition";
    138136
    139       matchsetCounter.Name = "Count number of rules in match set";
    140       matchsetCounter.AccumulateParameter.Value = new BoolValue(false);
    141       matchsetCounter.ValueParameter.ActualName = "MatchSetCount";
    142 
    143       comparator.Comparison = new Comparison(ComparisonType.LessOrEqual);
    144       comparator.LeftSideParameter.ActualName = matchsetCounter.ValueParameter.ActualName;
    145       comparator.ResultParameter.ActualName = "Covering";
    146       //more than zero solutions have to be selected
    147       comparator.RightSideParameter.ActualName = "ZeroIntValue";
    148 
    149       coveringConditionalBranch.Name = "Covering Branch";
    150       coveringConditionalBranch.ConditionParameter.ActualName = "Covering";
     137      countNumberOfUniqueActions.ClassifiersParameter.ActualName = "CombinedIntegerVector";
     138
     139      covering.ActionsInMatchSetParameter.ActualName = countNumberOfUniqueActions.UniqueActionsParameter.ActualName;
     140      covering.ParallelParameter.Value.Value = true;
     141      covering.RandomParameter.ActualName = "Random";
    151142
    152143      matchActionSubScopesProcessor.Operator = matchActionOperator;
     
    154145      matchActionOperator.MatchParameter.ActualName = "CombinedIntegerVector";
    155146      matchActionOperator.TargetMatchParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
    156 
    157       coveringMechanism.NumberOfSolutionsParameter.ActualName = "OneIntValue";
    158147
    159148      predictionArrayCalculator.MatchParameter.ActualName = "CombinedIntegerVector";
     
    211200      //adaptedGeneticAlgorithmMainLoop.Successor = conditionMatchSelector;
    212201
    213       conditionMatchSelector.Successor = coveringSubScopesProcessor;
    214       coveringSubScopesProcessor.Operators.Add(new EmptyOperator());
    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;
     202      conditionMatchSelector.Successor = matchSetSubScopesProcessor;
     203      matchSetSubScopesProcessor.Operators.Add(new EmptyOperator());
     204      matchSetSubScopesProcessor.Operators.Add(countNumberOfUniqueActions);
     205      matchSetSubScopesProcessor.Successor = mergingReducerWithSuccessor;
     206      countNumberOfUniqueActions.Successor = covering;
     207      covering.Successor = predictionArrayCalculator;
    222208      predictionArrayCalculator.Successor = actionSelector;
    223209      actionSelector.Successor = matchActionSubScopesProcessor;
     
    253239      initialSolutionsCreator.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
    254240
    255       coveringMechanism.SolutionCreatorParameter.ActualName = problem.SolutionCreatorParameter.Name;
    256       coveringMechanism.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
    257 
    258241      problem.ActionExecuter.SelectedActionParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
    259242
     
    266249      actionExecuter.OperatorParameter.ActualName = problem.ActionExecuterParameter.Name;
    267250
    268       matchConditionOperator.TargetMatchParameter.ActualName = problem.ClassifierFetcher.CurrentClassifierToMatchParameter.Name;
     251      matchConditionOperator.TargetMatchParameter.ActualName = problem.ClassifierFetcher.CurrentClassifierToMatchParameter.ActualName;
     252
     253      covering.SolutionCreatorParameter.ActualName = problem.CoveringSolutionCreatorParameter.Name;
     254      covering.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
     255      covering.MinimalNumberOfUniqueActionsParameter.ActualName = problem.ThetaMinimalNumberOfActionsParameter.Name;
     256      covering.PossibleActionsParameter.ActualName = problem.PossibleActionsParameter.Name;
    269257
    270258      predictionArrayCalculator.PredictionParameter.ActualName = problem.Evaluator.PredictionParameter.ActualName;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3

    • Property svn:ignore
      •  

        old new  
        11*.user
        22Plugin.cs
         3obj
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Covering/CombinedIntegerVectorCoveringCreator.cs

    r9089 r9090  
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    30 namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding.Covering {
     30namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding {
    3131  [Item("CombinedIntegerVectorCoveringCreator", "Description missing")]
    3232  [StorableClass]
     
    4343      get { return (IValueLookupParameter<IClassifier>)Parameters["CreatedClassifier"]; }
    4444    }
    45     public IValueLookupParameter<PercentValue> ChangeSymbolProbabilityParameter {
    46       get { return (IValueLookupParameter<PercentValue>)Parameters["ChangeSymbolProbability"]; }
     45    public ILookupParameter<PercentValue> ChangeSymbolProbabilityParameter {
     46      get { return (ILookupParameter<PercentValue>)Parameters["ChangeSymbolProbability"]; }
    4747    }
     48    public ILookupParameter<IRandom> RandomParameter {
     49      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     50    }
     51
    4852    #endregion
    4953
     
    6165      Parameters.Add(new LookupParameter<IClassifier>("Action"));
    6266      Parameters.Add(new ValueLookupParameter<IClassifier>("CreatedClassifier"));
    63       Parameters.Add(new ValueLookupParameter<PercentValue>("ChangeSymbolProbability"));
     67      Parameters.Add(new LookupParameter<PercentValue>("ChangeSymbolProbability"));
     68      Parameters.Add(new LookupParameter<IRandom>("Random"));
    6469    }
    6570
    6671    public override IOperation Apply() {
     72      CombinedIntegerVector newCondition = (CombinedIntegerVector)CoverClassifierParameter.ActualValue.Condition.Clone();
     73
    6774      CombinedIntegerVector condition = (CombinedIntegerVector)CoverClassifierParameter.ActualValue.Condition;
    6875      CombinedIntegerVector action = (CombinedIntegerVector)ActionParameter.ActualValue.Action;
    6976
    70       //TODO: manipulation
     77      newCondition = UniformSomePositionInConditionManipulator.ManipulateCondition(RandomParameter.ActualValue, condition, newCondition, ChangeSymbolProbabilityParameter.ActualValue.Value);
    7178
    72       CreatedClassifierParameter.ActualValue = new CombinedIntegerVector(condition, condition.Bounds, action, action.Bounds);
     79      CreatedClassifierParameter.ActualValue = new CombinedIntegerVector(newCondition, newCondition.Bounds, action, action.Bounds);
    7380      return base.Apply();
    7481    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r9089 r9090  
    3838    }
    3939
     40    public static CombinedIntegerVector Apply(IRandom random, CombinedIntegerVector parent1, CombinedIntegerVector parent2) {
     41      if (parent1.Length != parent2.Length && parent1.ActionLength != parent2.ActionLength && parent1.Bounds.Equals(parent2.Bounds))
     42        throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
     43
     44      int length = parent1.Length;
     45      int actionLength = parent1.ActionLength;
     46      int conditionLength = length - actionLength;
     47      int[] result = new int[length];
     48      int breakPoint = random.Next(1, conditionLength);
     49
     50      for (int i = 0; i < breakPoint; i++) {
     51        result[i] = parent1[i];
     52      }
     53      for (int i = breakPoint; i < conditionLength; i++) {
     54        result[i] = parent2[i];
     55      }
     56
     57      CombinedIntegerVector actionParent = random.Next(2) == 1 ? parent1 : parent2;
     58      for (int i = conditionLength; i < length; i++) {
     59        result[i] = actionParent[i];
     60      }
     61
     62      return new CombinedIntegerVector(result, actionLength, parent1.Bounds);
     63    }
     64
    4065    protected override CombinedIntegerVector Cross(IRandom random, ItemArray<CombinedIntegerVector> parents) {
    4166      if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
    42       return new CombinedIntegerVector(HeuristicLab.Encodings.IntegerVectorEncoding.SinglePointCrossover.Apply(random, parents[0], parents[1]), parents[0].ActionLength, parents[0].Bounds);
     67      return Apply(random, parents[0], parents[1]);
    4368    }
    4469  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/HeuristicLab.Encodings.CombinedIntegerVectorEncoding-3.3.csproj

    r9089 r9090  
    118118    </Compile>
    119119    <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" />
    120     <Compile Include="Manipulator\UniformSomePositionsManipulator.cs" />
     120    <Compile Include="Manipulator\UniformSomePositionInConditionManipulator.cs" />
    121121    <Compile Include="Plugin.cs" />
    122122    <None Include="Properties\AssemblyInfo.cs.frame" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs

    r9089 r9090  
    4646
    4747    public static CombinedIntegerVector Manipulate(CombinedIntegerVector parent, CombinedIntegerVector child, int index) {
    48       int max = child.Bounds[index % child.Bounds.Rows, 1];
     48      int max = child.Bounds[index % child.Bounds.Rows, 1] - 1;
    4949      if (child[index].Equals(max)) {
    5050        child[index] = parent[index];
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3

    • Property svn:ignore set to
      obj
      Plugin.cs
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/CoveringOperator.cs

    r9089 r9090  
    3535
    3636    #region Parameter Properties
    37     public ILookupParameter<IClassifier> CoverClassifierParameter {
    38       get { return (ILookupParameter<IClassifier>)Parameters["CoverClassifier"]; }
    39     }
    4037    public ILookupParameter<IItemSet<IClassifier>> ActionsInMatchSetParameter {
    4138      get { return (ILookupParameter<IItemSet<IClassifier>>)Parameters["ActionsInMatchSet"]; }
     
    4845    }
    4946    public IValueLookupParameter<IOperator> EvaluatorParameter {
    50       get { return (IValueLookupParameter<IOperator>)Parameters[" Evaluator"]; }
     47      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
    5148    }
    5249    public IValueLookupParameter<ICoveringSolutionCreator> SolutionCreatorParameter {
     
    7875      : base() {
    7976      Parameters.Add(new LookupParameter<IClassifier>("CoverClassifier"));
    80       Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("ActionsInMatchSet"));
    81       Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("PossibleActions"));
     77      Parameters.Add(new LookupParameter<IItemSet<IClassifier>>("ActionsInMatchSet"));
     78      Parameters.Add(new LookupParameter<IItemSet<IClassifier>>("PossibleActions"));
    8279      Parameters.Add(new LookupParameter<IntValue>("MinimalNumberOfUniqueActions"));
    8380      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator"));
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/ICovering.cs

    r9089 r9090  
    2626namespace HeuristicLab.Encodings.ConditionActionEncoding {
    2727  public interface ICovering : IStochasticOperator {
    28     ILookupParameter<IClassifier> CoverClassifierParameter { get; }
    2928    ILookupParameter<IItemSet<IClassifier>> ActionsInMatchSetParameter { get; }
    3029    ILookupParameter<IItemSet<IClassifier>> PossibleActionsParameter { get; }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/ICoveringSolutionCreator.cs

    r9089 r9090  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2527
    2628namespace HeuristicLab.Encodings.ConditionActionEncoding {
    27   public interface ICoveringSolutionCreator : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable {
     29  public interface ICoveringSolutionCreator : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable, IStochasticOperator {
    2830    ILookupParameter<IClassifier> CoverClassifierParameter { get; }
    2931    ILookupParameter<IClassifier> ActionParameter { get; }
    3032
    3133    IValueLookupParameter<IClassifier> CreatedClassifierParameter { get; }
     34    ILookupParameter<PercentValue> ChangeSymbolProbabilityParameter { get; }
    3235  }
    3336}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblem.cs

    r9089 r9090  
    3131    IParameter ClassifierFetcherParameter { get; }
    3232    IClassifierFetcher ClassifierFetcher { get; }
     33    IParameter ThetaMinimalNumberOfActionsParameter { get; }
    3334
    3435    IParameter PossibleActionsParameter { get; }
    3536    IItemSet<IClassifier> PossibleActions { get; }
    3637
     38    ICoveringSolutionCreator CoveringSolutionCreator { get; }
     39    IParameter CoveringSolutionCreatorParameter { get; }
     40
    3741    new IXCSEvaluator Evaluator { get; }
    3842  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/CountNumberOfUniqueActions.cs

    r9089 r9090  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Operators;
    2526using HeuristicLab.Parameters;
     
    3738      get { return (IValueLookupParameter<IItemSet<IClassifier>>)Parameters["UniqueActions"]; }
    3839    }
     40    public IValueLookupParameter<IntValue> NumberOfUniqueActionsParameter {
     41      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfUniqueActions"]; }
     42    }
    3943
    4044    [StorableConstructor]
     
    5054      Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers"));
    5155      Parameters.Add(new ValueLookupParameter<IItemSet<IClassifier>>("UniqueActions"));
     56      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfUniqueActions"));
    5257    }
     58
    5359    public override IOperation Apply() {
    5460      ItemSet<IClassifier> actions = new ItemSet<IClassifier>();
     
    5662        actions.Add(classifier.Action);
    5763      }
    58       UniqueActionsParameter.Value = actions;
     64      UniqueActionsParameter.ActualValue = actions;
     65      NumberOfUniqueActionsParameter.ActualValue = new IntValue(actions.Count);
    5966      return base.Apply();
    6067    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Properties

    • Property svn:ignore set to
      AssemblyInfo.cs
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3

    • Property svn:ignore set to
      obj
      Plugin.cs
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Implementation/ConditionActionClassificationProblem.cs

    r9089 r9090  
    4545      get { return (IValueParameter<ConditionActionClassificationProblemData>)Parameters["ProblemData"]; }
    4646    }
     47    public IValueParameter<ICoveringSolutionCreator> CoveringSolutionCreatorParameter {
     48      get { return (IValueParameter<ICoveringSolutionCreator>)Parameters["CoveringSolutionCreator"]; }
     49    }
     50    public IFixedValueParameter<PercentValue> ChangeSymbolProbabilityInCoveringParameter {
     51      get { return (IFixedValueParameter<PercentValue>)Parameters["ChangeSymbolProbabilityInCovering"]; }
     52    }
    4753    public IFixedValueParameter<DoubleValue> PositiveRewardParameter {
    4854      get { return (IFixedValueParameter<DoubleValue>)Parameters["PositiveReward"]; }
     
    6066      get { return (IFixedValueParameter<DoubleValue>)Parameters["InitialFitness"]; }
    6167    }
    62     public IFixedValueParameter<IItemSet<IClassifier>> PossibleActionsParameter {
    63       get { return (IFixedValueParameter<IItemSet<IClassifier>>)Parameters["PossibleActions"]; }
    64     }
    65     private IFixedValueParameter<IntValue> ThetaMinimalNumberOfActionsParameter {
     68    public IFixedValueParameter<ItemSet<IClassifier>> PossibleActionsParameter {
     69      get { return (IFixedValueParameter<ItemSet<IClassifier>>)Parameters["PossibleActions"]; }
     70    }
     71    public IFixedValueParameter<IntValue> ThetaMinimalNumberOfActionsParameter {
    6672      get { return (IFixedValueParameter<IntValue>)Parameters["ThetaMinimalNumberOfActions"]; }
    6773    }
     
    94100      get { return PossibleActions; }
    95101    }
    96     public IItemSet<IClassifier> PossibleActions {
     102    public ItemSet<IClassifier> PossibleActions {
    97103      get { return PossibleActionsParameter.Value; }
    98104    }
     
    115121    private IntValue ThetaMinimalNumberOfActions {
    116122      get { return ThetaMinimalNumberOfActionsParameter.Value; }
     123    }
     124    IParameter IConditionActionProblem.ThetaMinimalNumberOfActionsParameter {
     125      get { return ThetaMinimalNumberOfActionsParameter; }
     126    }
     127    public ICoveringSolutionCreator CoveringSolutionCreator {
     128      get { return CoveringSolutionCreatorParameter.Value; }
     129    }
     130    IParameter IConditionActionProblem.CoveringSolutionCreatorParameter {
     131      get { return CoveringSolutionCreatorParameter; }
    117132    }
    118133    #endregion
     
    130145      this(new ConditionActionClassificationProblemData(new Dataset(ConditionActionClassificationProblemData.defaultVariableNames, ConditionActionClassificationProblemData.defaultData),
    131146        ConditionActionClassificationProblemData.defaultVariableNames.Take(ConditionActionClassificationProblemData.defaultVariableNames.Length - 1), ConditionActionClassificationProblemData.defaultVariableNames.Last().ToEnumerable()),
    132         new XCSEvaluator(), new UniformRandomCombinedIntegerVectorCreator()) {
    133     }
    134 
    135     public ConditionActionClassificationProblem(ConditionActionClassificationProblemData problemData, XCSEvaluator evaluator, UniformRandomCombinedIntegerVectorCreator solutionCreator)
     147        new XCSEvaluator(), new UniformRandomCombinedIntegerVectorCreator(), new CombinedIntegerVectorCoveringCreator()) {
     148    }
     149
     150    public ConditionActionClassificationProblem(ConditionActionClassificationProblemData problemData, XCSEvaluator evaluator, UniformRandomCombinedIntegerVectorCreator solutionCreator, ICoveringSolutionCreator coveringSolutionCreator)
    136151      : base(evaluator, solutionCreator) {
    137152      Parameters.Add(new FixedValueParameter<IntValue>("Length", "The operator to create a solution.", new IntValue(7)));
     
    151166      Parameters.Add(new FixedValueParameter<IntValue>("ThetaMinimalNumberOfActions", "Minimal number of actions, which have to be present in the match set, or else covering will occure."));
    152167
     168      Parameters.Add(new ValueParameter<ICoveringSolutionCreator>("CoveringSolutionCreator", "", coveringSolutionCreator));
     169      Parameters.Add(new FixedValueParameter<PercentValue>("ChangeSymbolProbabilityInCovering", "", new PercentValue(0.5)));
     170
    153171      Evaluator.InitialErrorParameter.ActualName = "InitialError";
    154172      Evaluator.InitialFitnessParameter.ActualName = "InitialFitness";
     
    158176      SolutionCreator.LengthParameter.ActualName = LengthParameter.Name;
    159177      SolutionCreator.BoundsParameter.ActualName = BoundsParameter.Name;
     178
     179      coveringSolutionCreator.ChangeSymbolProbabilityParameter.ActualName = ChangeSymbolProbabilityInCoveringParameter.Name;
     180      coveringSolutionCreator.CoverClassifierParameter.ActualName = ClassifierFetcher.CurrentClassifierToMatchParameter.ActualName;
     181      coveringSolutionCreator.CreatedClassifierParameter.ActualName = "CombinedIntegerVector";
    160182
    161183      ClassifierFetcher.ActionPartLengthParameter.ActualName = ActionPartLengthParameter.Name;
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Properties

    • Property svn:ignore set to
      AssemblyInfo.cs
Note: See TracChangeset for help on using the changeset viewer.