Changeset 9175


Ignore:
Timestamp:
01/21/13 16:33:47 (7 years ago)
Author:
sforsten
Message:

#1980:

  • added BestTrainingXCSSolutionAnalyzer and CurrentXCSSolutionAnalyzer
  • fixed bug: Equals method was not correct in CombinedIntegerVector
Location:
branches/LearningClassifierSystems
Files:
2 added
10 edited

Legend:

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

    r9154 r9175  
    112112      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    113113    }
     114    private ValueParameter<MultiAnalyzer> FinalAnalyzerParameter {
     115      get { return (ValueParameter<MultiAnalyzer>)Parameters["FinalAnalyzer"]; }
     116    }
    114117    private ValueParameter<IntValue> MaxIterationsParameter {
    115118      get { return (ValueParameter<IntValue>)Parameters["MaxIterations"]; }
     
    197200      get { return AnalyzerParameter.Value; }
    198201      set { AnalyzerParameter.Value = value; }
     202    }
     203    public MultiAnalyzer FinalAnalyzer {
     204      get { return FinalAnalyzerParameter.Value; }
     205      set { FinalAnalyzerParameter.Value = value; }
    199206    }
    200207    private RandomCreator RandomCreator {
     
    228235      Parameters.Add(new ValueParameter<BoolValue>("DoActionSetSubsumption", "Specifies if action set is tested for subsuming classifiers.", new BoolValue(true)));
    229236      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
     237      Parameters.Add(new ValueParameter<MultiAnalyzer>("FinalAnalyzer", "The operator used to analyze the last generation.", new MultiAnalyzer()));
    230238      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "The maximum number of iterations.", new IntValue(1000)));
    231239      #endregion
     
    246254
    247255      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     256      mainLoop.FinalAnalyzerParameter.ActualName = FinalAnalyzerParameter.Name;
    248257      mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name;
    249258      #endregion
     
    298307    private void UpdateAnalyzers() {
    299308      Analyzer.Operators.Clear();
     309      FinalAnalyzer.Operators.Clear();
    300310      if (Problem != null) {
    301311        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
    302312          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
     313          FinalAnalyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
    303314        }
    304315      }
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs

    r9167 r9175  
    6464      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
    6565    }
     66    public ValueLookupParameter<IOperator> FinalAnalyzerParameter {
     67      get { return (ValueLookupParameter<IOperator>)Parameters["FinalAnalyzer"]; }
     68    }
    6669    #endregion
    6770
     
    110113      Parameters.Add(new LookupParameter<IntValue>("MaxIterations", "The maximum number of iterations the algorithm will do."));
    111114      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
     115      Parameters.Add(new ValueLookupParameter<IOperator>("FinalAnalyzer", "The operator used to analyze the last generation."));
    112116      #endregion
    113117
     
    115119      VariableCreator variableCreator = new VariableCreator();
    116120      ResultsCollector resultsCollector = new ResultsCollector();
     121      Placeholder analyzer = new Placeholder();
    117122      Placeholder finalAnalyzer = new Placeholder();
    118123      ConditionalBranch initialPopulationConditionalBranch = new ConditionalBranch();
     
    179184      resultsCollector.ResultsParameter.ActualName = "Results";
    180185
    181       finalAnalyzer.Name = "Analyzer";
    182       finalAnalyzer.OperatorParameter.ActualName = "Analyzer";
     186      analyzer.Name = "Analyzer";
     187      analyzer.OperatorParameter.ActualName = "Analyzer";
     188
     189      finalAnalyzer.Name = "FinalAnalyzer";
     190      finalAnalyzer.OperatorParameter.ActualName = "FinalAnalyzer";
    183191
    184192      initialPopulationConditionalBranch.ConditionParameter.ActualName = "CreateInitialPopulation";
     
    349357      initialPopulationConditionalBranch.Successor = maxIterationsComparator;
    350358      maxIterationsComparator.Successor = terminationConditionalBranch1;
    351       //terminationConditionalBranch1.TrueBranch = finalAnalyzer;
     359      terminationConditionalBranch1.TrueBranch = finalAnalyzer;
    352360      terminationConditionalBranch1.FalseBranch = classifierFetcher;
    353361      classifierFetcher.Successor = matchCondtionSubScopesProcessor;
     
    406414      deletionSelectorAfterGA.Successor = leftReducerAfterGA;
    407415      leftReducerAfterGA.Successor = iterationCounter;
    408       //iterationCounter.Successor = maxIterationsComparator;
    409 
    410       iterationCounter.Successor = finalAnalyzer;
    411       finalAnalyzer.Successor = maxIterationsComparator;
     416      iterationCounter.Successor = analyzer;
     417      analyzer.Successor = maxIterationsComparator;
    412418      #endregion
    413419    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVector.cs

    r9167 r9175  
    142142      IntMatrix actionBounds = new IntMatrix(actionPartLength, bounds.Columns);
    143143      int start = length - actionPartLength;
     144      int rows = bounds.Rows;
    144145      for (int i = start; i < length; i++) {
    145         int pos = i % bounds.Rows;
     146        int pos = i % rows;
    146147        for (int j = 0; j < bounds.Columns; j++) {
    147148          actionBounds[i - start, j] = bounds[pos, j];
     
    160161        curbounds = i % bounds.Rows;
    161162        //if don't care symbol is matched, next indices can be checked
    162         if (this[i].Equals(bounds[curbounds, 1] - 1)) {
     163        if (this[i] == bounds[curbounds, 1] - 1) {
    163164          continue;
    164165        }
    165         if (!this[i].Equals(targetVector[i])) {
     166        if (this[i] != targetVector[i]) {
    166167          return false;
    167168        }
     
    241242
    242243    public bool Equals(IClassifier other) {
    243       return this.MatchAction(other) && this.MatchCondition(other);
     244      var cast = other as CombinedIntegerVector;
     245      if (cast == null) { return false; }
     246      for (int i = 0; i < array.Length; i++) {
     247        if (!array[i].Equals(cast.array[i])) {
     248          return false;
     249        }
     250      }
     251      return true;
    244252    }
    245253
     
    251259      return result.GetHashCode();
    252260    }
    253 
    254     public bool Identical(IClassifier classifier) {
    255       var cast = classifier as CombinedIntegerVector;
    256       if (cast != null) {
    257         for (int i = 0; i < array.Length; i++) {
    258           if (!array[i].Equals(cast.array[i])) {
    259             return false;
    260           }
    261         }
    262       }
    263       return true;
    264     }
    265261  }
    266262}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Analyzer/XCSSolutionAnalyzer.cs

    r9154 r9175  
    3131  [Item("ConditionActionSolutionAnalyzer", "")]
    3232  [StorableClass]
    33   public sealed class XCSSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     33  public abstract class XCSSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    3434    public bool EnabledByDefault {
    3535      get { return true; }
     
    6767    }
    6868
     69    public ResultCollection Results { get { return ResultsParameter.ActualValue; } }
     70
    6971    [StorableConstructor]
    70     private XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { }
    71     private XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    72     public override IDeepCloneable Clone(Cloner cloner) {
    73       return new XCSSolutionAnalyzer(this, cloner);
    74     }
     72    protected XCSSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     73    protected XCSSolutionAnalyzer(XCSSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    7574    public XCSSolutionAnalyzer()
    7675      : base() {
     
    9695      ItemArray<DoubleValue> averageActionSetSizes = AverageActionSetSizeParameter.ActualValue;
    9796      ItemArray<IntValue> numerosities = NumerosityParameter.ActualValue;
    98       ResultCollection results = ResultsParameter.ActualValue;
    9997      IConditionActionProblemData problemData = ProblemDataParameter.ActualValue;
    10098
     
    108106      XCSModel xcsModel = new XCSModel(xcsClassifiers);
    109107
    110       if (results.ContainsKey("XCSSolution")) {
    111         results.Remove("XCSSolution");
    112       }
    113       results.Add(new Result("XCSSolution", xcsModel.CreateConditionActionSolution(problemData)));
    114 
     108      UseCurrentXCSSolution(xcsModel.CreateConditionActionSolution(problemData));
    115109      return base.Apply();
    116110    }
     111
     112    protected abstract void UseCurrentXCSSolution(IXCSSolution xcsSolution);
    117113  }
    118114}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj

    r9167 r9175  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    4041    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4142      <Private>False</Private>
     
    5657      <Private>False</Private>
    5758    </Reference>
     59    <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    5860    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    5961      <Private>False</Private>
     
    8688    <Compile Include="ActionSelection\MaxValueActionSelector.cs" />
    8789    <Compile Include="ActionSelection\RandomActionSelector.cs" />
     90    <Compile Include="Analyzer\BestTrainingXCSSolutionAnalyzer.cs" />
     91    <Compile Include="Analyzer\CurrentXCSSolutionAnalyzer.cs" />
    8892    <Compile Include="Analyzer\XCSSolutionAnalyzer.cs" />
    8993    <Compile Include="Covering\CoveringOperator.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/IClassifier.cs

    r9167 r9175  
    4141    bool Equals(object obj);
    4242    int GetHashCode();
    43 
    44     //test
    45     bool Identical(IClassifier classifier);
    4643  }
    4744}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionSolution.cs

    r9154 r9175  
    3131    event EventHandler ModelChanged;
    3232    event EventHandler ProblemDataChanged;
     33
     34    double TrainingAccuracy { get; }
     35    double TestAccuracy { get; }
    3336  }
    3437}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/ActionExecuter.cs

    r9089 r9175  
    6969
    7070    public override IOperation Apply() {
    71       if (SelectedActionParameter.ActualValue.Action.Equals(CurrentClassifierToMatchParameter.ActualValue.Action)) {
     71      if (SelectedActionParameter.ActualValue.MatchAction(CurrentClassifierToMatchParameter.ActualValue)) {
    7272        CurrentPayoffParameter.ActualValue = PositiveRewardParameter.ActualValue;
    7373      } else {
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSSolution.cs

    r9161 r9175  
    8686      description = original.Description;
    8787    }
     88    public override IDeepCloneable Clone(Cloner cloner) {
     89      return new XCSSolution(this, cloner);
     90    }
    8891    public XCSSolution(IConditionActionModel model, IConditionActionProblemData problemData)
    8992      : base() {
     
    118121
    119122      while (originalEnumerator.MoveNext() && estimatedActionEnumerator.MoveNext()) {
    120         if (originalEnumerator.Current.Action.Equals(estimatedActionEnumerator.Current)) {
     123        if (originalEnumerator.Current.MatchAction(estimatedActionEnumerator.Current)) {
    121124          correctClassified++;
    122125        }
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Implementation/ConditionActionClassificationProblem.cs

    r9167 r9175  
    149149      get { return CoveringSolutionCreatorParameter; }
    150150    }
    151     private XCSSolutionAnalyzer XCSSolutionAnalyzer {
    152       get { return Operators.OfType<XCSSolutionAnalyzer>().FirstOrDefault(); }
    153     }
    154151    #endregion
    155152
     
    226223
    227224    private void InitializeOperators() {
    228       Operators.Add(new XCSSolutionAnalyzer());
     225      Operators.Add(new BestTrainingXCSSolutionAnalyzer());
     226      Operators.Add(new CurrentXCSSolutionAnalyzer());
    229227
    230228      ParameterizeAnalyzers();
     
    232230
    233231    private void ParameterizeAnalyzers() {
    234       if (XCSSolutionAnalyzer != null) {
    235         XCSSolutionAnalyzer.ClassifierParameter.ActualName = SolutionCreator.CombinedIntegerVectorParameter.ActualName;
    236         XCSSolutionAnalyzer.PredictionParameter.ActualName = Evaluator.PredictionParameter.ActualName;
    237         XCSSolutionAnalyzer.ErrorParameter.ActualName = Evaluator.ErrorParameter.ActualName;
    238         XCSSolutionAnalyzer.FitnessParameter.ActualName = Evaluator.FitnessParameter.ActualName;
    239         XCSSolutionAnalyzer.ExperienceParameter.ActualName = Evaluator.ExperienceParameter.ActualName;
    240         XCSSolutionAnalyzer.AverageActionSetSizeParameter.ActualName = Evaluator.AverageActionSetSizeParameter.ActualName;
    241         XCSSolutionAnalyzer.NumerosityParameter.ActualName = Evaluator.NumerosityParameter.ActualName;
    242         XCSSolutionAnalyzer.TimestampParameter.ActualName = Evaluator.TimestampParameter.ActualName;
    243         XCSSolutionAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    244         XCSSolutionAnalyzer.ResultsParameter.ActualName = "Results";
     232      foreach (XCSSolutionAnalyzer xcsAnalyzer in Operators.Where(x => x is XCSSolutionAnalyzer)) {
     233        xcsAnalyzer.ClassifierParameter.ActualName = SolutionCreator.CombinedIntegerVectorParameter.ActualName;
     234        xcsAnalyzer.PredictionParameter.ActualName = Evaluator.PredictionParameter.ActualName;
     235        xcsAnalyzer.ErrorParameter.ActualName = Evaluator.ErrorParameter.ActualName;
     236        xcsAnalyzer.FitnessParameter.ActualName = Evaluator.FitnessParameter.ActualName;
     237        xcsAnalyzer.ExperienceParameter.ActualName = Evaluator.ExperienceParameter.ActualName;
     238        xcsAnalyzer.AverageActionSetSizeParameter.ActualName = Evaluator.AverageActionSetSizeParameter.ActualName;
     239        xcsAnalyzer.NumerosityParameter.ActualName = Evaluator.NumerosityParameter.ActualName;
     240        xcsAnalyzer.TimestampParameter.ActualName = Evaluator.TimestampParameter.ActualName;
     241        xcsAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     242        xcsAnalyzer.ResultsParameter.ActualName = "Results";
    245243      }
    246244    }
Note: See TracChangeset for help on using the changeset viewer.