Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9204


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
Files:
14 added
1 deleted
26 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
  • branches/LearningClassifierSystems/HeuristicLab.Core

  • branches/LearningClassifierSystems/HeuristicLab.Core/3.3/Interfaces/ILookupParameter.cs

    r7259 r9204  
    2626    string ActualName { get; set; }
    2727    string TranslatedName { get; }
     28    IExecutionContext ExecutionContext { get; set; }
    2829    event EventHandler ActualNameChanged;
    2930  }
  • branches/LearningClassifierSystems/HeuristicLab.Core/3.3/Interfaces/IParameter.cs

    r7259 r9204  
    2727    bool Hidden { get; set; }
    2828    IItem ActualValue { get; set; }
    29     IExecutionContext ExecutionContext { get; set; }
    3029
    3130    event EventHandler HiddenChanged;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVectorManipulator.cs

    r9194 r9204  
    3939      get { return (ILookupParameter<CombinedIntegerVector>)Parameters["Child"]; }
    4040    }
    41     public ILookupParameter<CombinedIntegerVector> FetchedConditionParameter {
    42       get { return (ILookupParameter<CombinedIntegerVector>)Parameters["Parent"]; }
     41    public ILookupParameter<CombinedIntegerVector> FetchedInputParameter {
     42      get { return (ILookupParameter<CombinedIntegerVector>)Parameters["Input"]; }
    4343    }
    4444    #endregion
     
    5353      Parameters.Add(new LookupParameter<IRandom>("Random"));
    5454      Parameters.Add(new LookupParameter<CombinedIntegerVector>("Child"));
    55       Parameters.Add(new LookupParameter<CombinedIntegerVector>("Parent"));
     55      Parameters.Add(new LookupParameter<CombinedIntegerVector>("Input"));
    5656    }
    5757
    5858    public sealed override IOperation Apply() {
    59       ChildParameter.ActualValue = Manipulate(RandomParameter.ActualValue, FetchedConditionParameter.ActualValue, ChildParameter.ActualValue);
     59      ChildParameter.ActualValue = Manipulate(RandomParameter.ActualValue, FetchedInputParameter.ActualValue, ChildParameter.ActualValue);
    6060      return base.Apply();
    6161    }
    6262
    63     protected abstract CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child);
     63    protected abstract CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector input, CombinedIntegerVector child);
    6464  }
    6565}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Covering/CombinedIntegerVectorCoveringCreator.cs

    r9194 r9204  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.ConditionActionEncoding;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Parameters;
    2825using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2926
     
    3128  [Item("CombinedIntegerVectorCoveringCreator", "Description missing")]
    3229  [StorableClass]
    33   public class CombinedIntegerVectorCoveringCreator : SingleSuccessorOperator, ICoveringSolutionCreator {
    34 
    35     #region Parameter Properties
    36     public ILookupParameter<IInput> CoverInputParameter {
    37       get { return (ILookupParameter<IInput>)Parameters["CoverInput"]; }
    38     }
    39     public ILookupParameter<IAction> ActionParameter {
    40       get { return (ILookupParameter<IAction>)Parameters["Action"]; }
    41     }
    42     public IValueLookupParameter<IClassifier> CreatedClassifierParameter {
    43       get { return (IValueLookupParameter<IClassifier>)Parameters["CreatedClassifier"]; }
    44     }
    45     public ILookupParameter<PercentValue> ChangeSymbolProbabilityParameter {
    46       get { return (ILookupParameter<PercentValue>)Parameters["ChangeSymbolProbability"]; }
    47     }
    48     public ILookupParameter<IRandom> RandomParameter {
    49       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    50     }
    51 
    52     #endregion
     30  public class CombinedIntegerVectorCoveringCreator : CoveringSolutionCreator, ICombinedIntegerVectorOperator {
    5331
    5432    [StorableConstructor]
     
    6240    public CombinedIntegerVectorCoveringCreator()
    6341      : base() {
    64       Parameters.Add(new LookupParameter<IInput>("CoverInput"));
    65       Parameters.Add(new LookupParameter<IAction>("Action"));
    66       Parameters.Add(new ValueLookupParameter<IClassifier>("CreatedClassifier"));
    67       Parameters.Add(new LookupParameter<PercentValue>("ChangeSymbolProbability"));
    68       Parameters.Add(new LookupParameter<IRandom>("Random"));
    6942    }
    7043
    71     public override IOperation Apply() {
    72       CombinedIntegerVector newCondition = (CombinedIntegerVector)CoverInputParameter.ActualValue.Clone();
     44    protected override IClassifier CreateCoveredClassifier(IInput input, IAction action, IRandom random, double changeSymbolProbability) {
     45      CombinedIntegerVector newCondition = (CombinedIntegerVector)input.Clone();
    7346
    74       CombinedIntegerVector condition = (CombinedIntegerVector)CoverInputParameter.ActualValue;
    75       CombinedIntegerVector action = (CombinedIntegerVector)ActionParameter.ActualValue;
     47      CombinedIntegerVector condition = (CombinedIntegerVector)input;
     48      CombinedIntegerVector newAction = (CombinedIntegerVector)action;
    7649
    77       newCondition = UniformSomePositionManipulator.ManipulateCondition(RandomParameter.ActualValue, condition, newCondition, ChangeSymbolProbabilityParameter.ActualValue.Value);
     50      newCondition = UniformSomePositionManipulator.ManipulateCondition(random, condition, newCondition, changeSymbolProbability);
    7851
    79       CreatedClassifierParameter.ActualValue = new CombinedIntegerVector(newCondition, newCondition.Bounds, action, action.Bounds);
    80       return base.Apply();
     52      return new CombinedIntegerVector(newCondition, newCondition.Bounds, newAction, newAction.Bounds);
    8153    }
    8254  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Interfaces/ICombinedIntegerVectorManipulator.cs

    r9194 r9204  
    2929  public interface ICombinedIntegerVectorManipulator : IManipulator, ICombinedIntegerVectorOperator {
    3030    ILookupParameter<CombinedIntegerVector> ChildParameter { get; }
    31     ILookupParameter<CombinedIntegerVector> FetchedConditionParameter { get; }
     31    ILookupParameter<CombinedIntegerVector> FetchedInputParameter { get; }
    3232  }
    3333}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Manipulator/UniformActionManipulator.cs

    r9089 r9204  
    4747    }
    4848
    49     protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector child, CombinedIntegerVector parent) {
    50       return Manipulate(random, parent, child, PossibleActionsParameter.ActualValue);
     49    protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector child, CombinedIntegerVector input) {
     50      return Manipulate(random, child, PossibleActionsParameter.ActualValue);
    5151    }
    5252
    53     public static CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child, IEnumerable<CombinedIntegerVector> possibleActions) {
    54       var otherActions = possibleActions.Except(((CombinedIntegerVector)parent.Action).ToEnumerable());
     53    public static CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector child, IEnumerable<CombinedIntegerVector> possibleActions) {
     54      var otherActions = possibleActions.Except(((CombinedIntegerVector)child.Action).ToEnumerable());
    5555      int actionIndex = random.Next(otherActions.Count());
    5656      CombinedIntegerVector newAction = otherActions.ElementAt(actionIndex);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs

    r9090 r9204  
    4141    }
    4242
    43     protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child) {
    44       return Manipulate(parent, child, random.Next(((CombinedIntegerVector)child.Condition).Length));
     43    protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector input, CombinedIntegerVector child) {
     44      return Manipulate(input, child, random.Next(((CombinedIntegerVector)child.Condition).Length));
    4545    }
    4646
    47     public static CombinedIntegerVector Manipulate(CombinedIntegerVector parent, CombinedIntegerVector child, int index) {
     47    public static CombinedIntegerVector Manipulate(CombinedIntegerVector input, CombinedIntegerVector child, int index) {
    4848      int max = child.Bounds[index % child.Bounds.Rows, 1] - 1;
    4949      if (child[index].Equals(max)) {
    50         child[index] = parent[index];
     50        child[index] = input[index];
    5151      } else {
    5252        child[index] = max;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Manipulator/UniformSomePositionManipulator.cs

    r9154 r9204  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
     25using HeuristicLab.Encodings.ConditionActionEncoding;
    2526using HeuristicLab.Parameters;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding {
    29   public class UniformSomePositionManipulator : CombinedIntegerVectorManipulator {
     30  public class UniformSomePositionManipulator : CombinedIntegerVectorManipulator, IProbabilityMutatorOperator {
    3031
    3132    public IValueLookupParameter<PercentValue> ProbabilityParameter {
     
    5051    }
    5152
    52     protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child) {
    53       return Manipulate(random, parent, child, ProbabilityParameter.ActualValue.Value, PossibleActionsParameter.ActualValue);
     53    protected override CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector input, CombinedIntegerVector child) {
     54      return Manipulate(random, input, child, ProbabilityParameter.ActualValue.Value, PossibleActionsParameter.ActualValue);
    5455    }
    5556
    56     public static CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child, double probability, IItemSet<CombinedIntegerVector> possibleActions) {
    57       child = ManipulateCondition(random, parent, child, probability);
    58       return ManipulateAction(random, parent, child, probability, possibleActions);
     57    public static CombinedIntegerVector Manipulate(IRandom random, CombinedIntegerVector input, CombinedIntegerVector child, double probability, IItemSet<CombinedIntegerVector> possibleActions) {
     58      child = ManipulateCondition(random, input, child, probability);
     59      return ManipulateAction(random, child, probability, possibleActions);
    5960    }
    6061
    61     public static CombinedIntegerVector ManipulateCondition(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child, double probability) {
     62    public static CombinedIntegerVector ManipulateCondition(IRandom random, CombinedIntegerVector input, CombinedIntegerVector child, double probability) {
    6263      int conditionLength = child.Length - child.ActionLength;
    6364      for (int index = 0; index < child.Length - child.ActionLength; index++) {
    6465        if (random.NextDouble() < probability) {
    65           child = UniformOnePositionInConditionManipulator.Manipulate(parent, child, index);
     66          child = UniformOnePositionInConditionManipulator.Manipulate(input, child, index);
    6667        }
    6768      }
     
    6970    }
    7071
    71     public static CombinedIntegerVector ManipulateAction(IRandom random, CombinedIntegerVector parent, CombinedIntegerVector child, double probability, IItemSet<CombinedIntegerVector> possibleActions) {
     72    public static CombinedIntegerVector ManipulateAction(IRandom random, CombinedIntegerVector child, double probability, IItemSet<CombinedIntegerVector> possibleActions) {
    7273      if (child.ActionLength > 0 && random.NextDouble() < probability) {
    73         UniformActionManipulator.Manipulate(random, parent, child, possibleActions);
     74        UniformActionManipulator.Manipulate(random, child, possibleActions);
    7475      }
    7576      return child;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj

    r9194 r9204  
    8989    <Compile Include="Analyzer\XCSSolutionAnalyzer.cs" />
    9090    <Compile Include="Covering\CoveringOperator.cs" />
     91    <Compile Include="Covering\CoveringSolutionCreator.cs" />
    9192    <Compile Include="Covering\DoDeletionBeforeCovering.cs" />
    9293    <Compile Include="Covering\ICovering.cs" />
     
    107108    <Compile Include="Interfaces\IXCSModel.cs" />
    108109    <Compile Include="Interfaces\IXCSSolution.cs" />
     110    <Compile Include="Manipulator\IProbabilityMutatorOperator.cs" />
    109111    <Compile Include="Operator\CalculateAccuracy.cs" />
    110112    <Compile Include="GA\XCSCheckIfGAShouldBeApplied.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblem.cs

    r9194 r9204  
    3535    IParameter PossibleActionsConcreteClassParameter { get; }
    3636    IParameter PossibleActionsParameter { get; }
    37     //IItemSet<IClassifier> PossibleActions { get; }
    3837
    3938    IParameter ClassifierComparerParameter { get; }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3

    • Property svn:ignore set to
      obj
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs

    r9194 r9204  
    6262      IList<IVariable> newCondition = new List<IVariable>(parent1Condition.Count);
    6363
    64       var keyEnumerator = parent1Condition.Keys.GetEnumerator();
     64      var keyEnumerator = parent1Condition.Order.GetEnumerator();
    6565
    6666      int index = 0;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/HeuristicLab.Encodings.VariableVector-3.3.csproj

    r9194 r9204  
    7171  </ItemGroup>
    7272  <ItemGroup>
     73    <Compile Include="Covering\VariableVectorCoveringCreator.cs" />
    7374    <Compile Include="Crossover\SinglePointCrossover.cs" />
     75    <Compile Include="Interfaces\IVariableVectorCoveringCreator.cs" />
    7476    <Compile Include="Interfaces\IVariableVectorCrossover.cs" />
     77    <Compile Include="Interfaces\IVariableVectorManipulator.cs" />
     78    <Compile Include="Manipulator\UniformActionManipulator.cs" />
     79    <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" />
     80    <Compile Include="Manipulator\UniformSomePositionManipulator.cs" />
    7581    <Compile Include="VariableVectorCrossover.cs" />
     82    <Compile Include="VariableVectorManipulator.cs" />
    7683    <Compile Include="Variable\IActionVariable.cs" />
    7784    <Compile Include="Variable\IVariable.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs

    r9194 r9204  
    137137    public override double GetGenerality() {
    138138      double delta = max - min;
    139       double intervalWidth = 2 * currentSpread;
    140       double generality = intervalWidth / delta;
     139      double intervalInBoundsWidth = Math.Min(max, currentCenter + currentSpread) - Math.Max(min, currentCenter - currentSpread);
     140      double generality = intervalInBoundsWidth / delta;
    141141      return generality > 1 ? 1 : generality;
    142142    }
     
    159159      return crossed;
    160160    }
     161
     162    public override void Manipulate(IRandom random, string stringValue, int pos) {
     163      if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); }
     164      Manipulate(random, pos, 10);
     165    }
     166
     167    public void Manipulate(IRandom random, int pos, double percentage) {
     168      if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); }
     169      double delta = max - min;
     170      double maxChange = delta * (percentage / 100);
     171      double actualChange = (random.NextDouble() * maxChange * 2) - maxChange;
     172      if (pos == 0) {
     173        currentCenter += actualChange;
     174      } else if (pos == 1) {
     175        currentSpread += actualChange;
     176        //otherwise the interval could be corrupt and no input could match the rule.
     177        currentSpread = currentSpread > 0 ? currentSpread : 0;
     178      }
     179    }
     180
     181    public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) {
     182      Cover(random, stringValue, 50);
     183    }
     184
     185    public void CoverWithSpreadPercentage(IRandom random, string stringValue, double spreadPercentage) {
     186      currentCenter = double.Parse(stringValue);
     187      double delta = max - min;
     188      currentSpread = random.NextDouble() * (delta * (spreadPercentage / 100));
     189    }
    161190  }
    162191}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IVariable.cs

    r9194 r9204  
    4141
    4242    IVariable CrossParentsAtPosition(IVariable parent2, int pos);
     43
     44    void Manipulate(IRandom random, string stringValue, int pos);
     45
     46    void Cover(IRandom random, string stringValue, double changeSymbolProbability);
    4347  }
    4448}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs

    r9194 r9204  
    8686
    8787    public override string ToString() {
    88       return currentValue.ToString();
     88      return Wildcard ? "#" : currentValue.ToString();
    8989    }
    9090
     
    145145      return this.GetSetCopy();
    146146    }
     147
     148    public override void Manipulate(IRandom random, string stringValue, int pos) {
     149      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
     150      Wildcard = !Wildcard;
     151      if (!Wildcard) {
     152        currentValue = int.Parse(stringValue);
     153      }
     154    }
     155
     156    public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) {
     157      Wildcard = random.NextDouble() < changeSymbolProbability;
     158      if (!Wildcard) {
     159        currentValue = int.Parse(stringValue);
     160      }
     161    }
    147162  }
    148163}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs

    r9194 r9204  
    134134
    135135    public override string ToString() {
    136       return CurrentStringValue;
     136      return Wildcard ? "#" : CurrentStringValue;
    137137    }
    138138
     
    197197      return this.GetSetCopy();
    198198    }
     199
     200    public override void Manipulate(IRandom random, string stringValue, int pos) {
     201      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
     202      Wildcard = !Wildcard;
     203      if (!Wildcard) {
     204        int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key;
     205        currentValue = newValue;
     206      }
     207    }
     208
     209    public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) {
     210      Wildcard = random.NextDouble() < changeSymbolProbability;
     211      if (!Wildcard) {
     212        int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key;
     213        currentValue = newValue;
     214      }
     215    }
    199216  }
    200217}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/Variable.cs

    r9194 r9204  
    6969
    7070    public virtual IVariable CrossParentsAtPosition(IVariable parent2, int pos) { throw new NotSupportedException("This method is not supported."); }
     71
     72    public abstract void Manipulate(IRandom random, string stringValue, int pos);
     73
     74    public abstract void Cover(IRandom random, string stringValue, double changeSymbolProbability);
    7175  }
    7276}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVector.cs

    r9194 r9204  
    3333  [Item("VariableVector", "")]
    3434  public class VariableVector : Item, IClassifier {
     35
    3536    [Storable]
    3637    protected VariableVectorCondition condition;
     
    131132      return true;
    132133    }
     134
     135    [StorableClass]
     136    [Item("VariableVectorActionComparer", "")]
     137    public class VariableVectorActionComparer : Item, IEqualityComparer<VariableVectorAction>, IClassifierComparer {
     138
     139      [StorableConstructor]
     140      protected VariableVectorActionComparer(bool deserializing) : base(deserializing) { }
     141      protected VariableVectorActionComparer(VariableVectorActionComparer original, Cloner cloner)
     142        : base(original, cloner) {
     143      }
     144      public override IDeepCloneable Clone(Cloner cloner) {
     145        return new VariableVectorActionComparer(this, cloner);
     146      }
     147      public VariableVectorActionComparer() : base() { }
     148
     149      public bool Equals(VariableVectorAction x, VariableVectorAction y) {
     150        throw new NotImplementedException();
     151      }
     152
     153      public int GetHashCode(VariableVectorAction obj) {
     154        throw new NotImplementedException();
     155      }
     156
     157      public bool Equals(IAction x, IAction y) {
     158        var xCast = x as VariableVectorAction;
     159        var yCast = y as VariableVectorAction;
     160        return x != null && y != null && Equals(xCast, yCast);
     161      }
     162
     163      public int GetHashCode(IAction obj) {
     164        var objCast = obj as VariableVectorAction;
     165        return objCast != null ? GetHashCode(objCast) : obj.GetHashCode();
     166      }
     167    }
    133168  }
    134169}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorAction.cs

    r9194 r9204  
    3535  public class VariableVectorAction : ItemDictionary<StringValue, IActionVariable>, IAction {
    3636
     37    public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }
     38
    3739    public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } }
    3840
     
    6163      var targetCast = target as VariableVectorAction;
    6264      if (targetCast == null) { return false; }
    63       if (!(this.Keys.Except(targetCast.Keys).Count() == 0 && targetCast.Keys.Except(this.Keys).Count() == 0)) { return false; }
     65      if (this.Order.SequenceEqual(targetCast.Order)) { return false; }
    6466      foreach (var keyValuePair in targetCast) {
    6567        if (!this[keyValuePair.Key].MatchVariable(keyValuePair.Value)) {
     
    9799
    98100    public bool Identical(VariableVectorCondition target) {
    99       if (!(target.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(target.Keys).Count() == 0)) { return false; }
     101      if (this.Order.SequenceEqual(target.Order)) { return false; }
    100102      foreach (var keyValuePair in target) {
    101103        if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) {
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs

    r9194 r9204  
    3434  public class VariableVectorCondition : ItemDictionary<StringValue, IVariable>, ICondition {
    3535
     36    public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }
     37
    3638    public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } }
    3739
     
    5153      var targetCast = target as VariableVectorInput;
    5254      if (targetCast == null) { return false; }
    53       if (!(targetCast.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(targetCast.Keys).Count() == 0)) { return false; }
     55      if (this.Order.SequenceEqual(targetCast.Order)) { return false; }
    5456      foreach (var keyValuePair in targetCast) {
    5557        if (!this[keyValuePair.Key].MatchInput(keyValuePair.Value.Value)) {
     
    9193
    9294    public bool Identical(VariableVectorCondition target) {
    93       if (!(target.Keys.Except(this.Keys).Count() == 0 && this.Keys.Except(target.Keys).Count() == 0)) { return false; }
     95      if (this.Order.SequenceEqual(target.Order)) { return false; }
    9496      foreach (var keyValuePair in target) {
    9597        if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) {
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs

    r9194 r9204  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3132  [Item("VariableVectorInput", "")]
    3233  public class VariableVectorInput : ItemDictionary<StringValue, StringValue>, IInput {
     34
     35    public IOrderedEnumerable<StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }
    3336
    3437    [StorableConstructor]
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Implementation/ConditionActionClassificationProblem.cs

    r9194 r9204  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    2930using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.PluginInfrastructure;
    3133using HeuristicLab.Problems.DataAnalysis;
    3234using HeuristicLab.Problems.Instances;
     
    233235
    234236    private void InitializeOperators() {
     237      Operators.AddRange(ApplicationManager.Manager.GetInstances<ICombinedIntegerVectorCrossover>());
     238      Operators.AddRange(AddManipulators());
    235239      Operators.Add(new BestTrainingXCSSolutionAnalyzer());
    236240      Operators.Add(new CurrentXCSSolutionAnalyzer());
    237241
    238       ParameterizeAnalyzers();
    239     }
    240 
    241     private void ParameterizeAnalyzers() {
    242       foreach (XCSSolutionAnalyzer xcsAnalyzer in Operators.Where(x => x is XCSSolutionAnalyzer)) {
     242      ParameterizeOperators();
     243    }
     244
     245    private IEnumerable<ICombinedIntegerVectorManipulator> AddManipulators() {
     246      var manipulator = new UniformSomePositionManipulator();
     247      manipulator.ChildParameter.ActualName = "CombinedIntegerVector";
     248      manipulator.FetchedInputParameter.ActualName = ClassifierFetcher.CurrentInputToMatchParameter.ActualName;
     249      manipulator.PossibleActionsParameter.ActualName = PossibleActionsConcreteClassParameter.Name;
     250      return new List<ICombinedIntegerVectorManipulator>() { manipulator };
     251    }
     252
     253    private void ParameterizeOperators() {
     254      foreach (XCSSolutionAnalyzer xcsAnalyzer in Operators.OfType<XCSSolutionAnalyzer>()) {
    243255        xcsAnalyzer.ClassifierParameter.ActualName = SolutionCreator.CombinedIntegerVectorParameter.ActualName;
    244256        xcsAnalyzer.PredictionParameter.ActualName = Evaluator.PredictionParameter.ActualName;
Note: See TracChangeset for help on using the changeset viewer.