Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/13 13:31:29 (12 years ago)
Author:
sforsten
Message:

#1980:

  • several small bug fixes
  • added windowing technique ILAS to GAssist
  • GAssist and XCS work now with real-valued features
  • severely improved the performance of XCS
Location:
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3
Files:
3 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3

    • Property svn:ignore
      •  

        old new  
        11*.user
        22Plugin.cs
         3obj
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Evaluator/MDLEvaluator.cs

    r9334 r9392  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Data;
     27using HeuristicLab.Operators;
     28using HeuristicLab.Optimization;
     29using HeuristicLab.Optimization.Operators.LCS;
    2530using HeuristicLab.Parameters;
    2631using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2934  [Item("MDLEvaluator", "Description missing")]
    3035  [StorableClass]
    31   public class MDLEvaluator : DecisionListEvaluator {
     36  public class MDLEvaluator : SingleSuccessorOperator, IDecisionListEvaluator, IDecisionListOperator, IMDLCalculatorBasedOperator, IIterationBasedOperator, IStochasticOperator {
    3237
    33     public IValueLookupParameter<MDLCalculator> MDLCalculatorParameter {
    34       get { return (IValueLookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; }
     38    #region Parameter Properties
     39    public ILookupParameter<IRandom> RandomParameter {
     40      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     41    }
     42    public ILookupParameter<DecisionList> DecisionListParameter {
     43      get { return (ILookupParameter<DecisionList>)Parameters["DecisionList"]; }
     44    }
     45    public IValueLookupParameter<IntValue> SizePenaltyMinRulesParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters["SizePenaltyMinRules"]; }
     47    }
     48    public ILookupParameter<DoubleValue> QualityParameter {
     49      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     50    }
     51    public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter {
     52      get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; }
     53    }
     54
     55    public ILookupParameter<MDLCalculator> MDLCalculatorParameter {
     56      get { return (ILookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; }
     57    }
     58    public ILookupParameter<IntValue> IterationsParameter {
     59      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
     60    }
     61    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     62      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     63    }
     64
     65    public IValueLookupParameter<IntValue> IterationRuleDeletionParameter {
     66      get { return (IValueLookupParameter<IntValue>)Parameters["IterationRuleDeletion"]; }
     67    }
     68    public IValueLookupParameter<IntValue> RuleDeletionMinRulesParameter {
     69      get { return (IValueLookupParameter<IntValue>)Parameters["RuleDeletionMinRules"]; }
     70    }
     71
     72    public ILookupParameter<ItemList<ItemList<IntValue>>> StrataParameter {
     73      get { return (ILookupParameter<ItemList<ItemList<IntValue>>>)Parameters["Strata"]; }
     74    }
     75    #endregion
     76
     77    public IRandom Random {
     78      get { return RandomParameter.ActualValue; }
    3579    }
    3680
     
    4286    public MDLEvaluator()
    4387      : base() {
    44       Parameters.Add(new ValueLookupParameter<MDLCalculator>("MDLCalculator", ""));
     88      Parameters.Add(new LookupParameter<IRandom>("Random", "The random generator to use."));
     89      Parameters.Add(new LookupParameter<DecisionList>("DecisionList", ""));
     90      Parameters.Add(new ValueLookupParameter<IntValue>("SizePenaltyMinRules", ""));
     91      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     92      Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", ""));
     93      Parameters.Add(new LookupParameter<MDLCalculator>("MDLCalculator", ""));
     94      Parameters.Add(new LookupParameter<IntValue>("Iterations", ""));
     95      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", ""));
     96      Parameters.Add(new ValueLookupParameter<IntValue>("IterationRuleDeletion", "", new IntValue(5)));
     97      Parameters.Add(new ValueLookupParameter<IntValue>("RuleDeletionMinRules", "", new IntValue(12)));
     98      Parameters.Add(new ValueLookupParameter<ItemList<ItemList<IntValue>>>("Strata", ""));
    4599    }
    46100    public override IDeepCloneable Clone(Cloner cloner) {
     
    51105      double penalty = 1;
    52106
    53       var dls = new DecisionListSolution(DecisionListParameter.ActualValue, ProblemDataParameter.ActualValue);
     107      var strata = StrataParameter.ActualValue;
     108      int iteration = IterationsParameter.ActualValue.Value;
     109      int numberOfStrata = strata.Count;
     110      var dl = DecisionListParameter.ActualValue;
     111      var problemData = ProblemDataParameter.ActualValue;
     112      bool lastIteration = iteration == MaximumIterationsParameter.ActualValue.Value - 1;
     113      IEnumerable<int> rows;
     114      if (lastIteration) {
     115        rows = from s in strata
     116               from row in s
     117               select row.Value;
     118      } else {
     119        rows = strata[iteration % numberOfStrata].Select(x => x.Value);
     120      }
     121      var input = problemData.FetchInput(rows);
     122      var actions = problemData.FetchAction(rows);
     123      ItemSet<Rule> aliveRules;
     124      double theoryLength;
     125      var estimated = dl.Evaluate(input, out aliveRules, out theoryLength);
    54126
    55       if (dls.TrainingNumberOfAliveRules < SizePenaltyMinRulesParameter.ActualValue.Value) {
    56         penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - dls.TrainingNumberOfAliveRules));
     127      if (aliveRules.Count < SizePenaltyMinRulesParameter.ActualValue.Value) {
     128        penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - aliveRules.Count));
    57129        if (penalty <= 0) penalty = 0.01;
    58130        penalty *= penalty;
    59131      }
    60132
    61       QualityParameter.ActualValue = new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(dls) / penalty);
     133      double accuracy = DecisionListSolution.CalculateAccuracy(actions, estimated);
     134      QualityParameter.ActualValue = new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(theoryLength, accuracy) / penalty);
     135
     136      if (iteration >= IterationRuleDeletionParameter.ActualValue.Value) {
     137        if (lastIteration) {
     138          DoRuleDeletion(dl, aliveRules, 1);
     139        } else {
     140          DoRuleDeletion(dl, aliveRules, RuleDeletionMinRulesParameter.ActualValue.Value);
     141        }
     142      }
    62143      return base.Apply();
     144    }
     145
     146    // default rule cannot be deleted, but it has to be considered in the rule set size
     147    private void DoRuleDeletion(DecisionList dl, ItemSet<Rule> aliveRules, int minRules) {
     148      int ruleSetSize = dl.RuleSetSize;
     149      if (ruleSetSize <= minRules) { return; }
     150
     151      var deadRules = dl.Rules.Except(aliveRules).ToList();
     152      int numberOfDeadRules = deadRules.Count();
     153
     154      int keepRules = minRules - (ruleSetSize - numberOfDeadRules);
     155
     156      if (keepRules > 0) {
     157        for (int i = 0; i < keepRules; i++) {
     158          int pos = Random.Next(deadRules.Count);
     159          deadRules.RemoveAt(pos);
     160        }
     161      }
     162
     163      dl.RemoveRules(deadRules);
    63164    }
    64165  }
Note: See TracChangeset for help on using the changeset viewer.