Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/13 13:32:32 (12 years ago)
Author:
sforsten
Message:

#1980:

  • set plugin dependencies
  • added smart initialization
  • added hierarchical selection
  • fixed major and minor default rule
  • fixed several smaller bugs
  • some refactoring has been done
Location:
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3
Files:
1 added
18 edited

Legend:

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

    r9352 r9605  
    3434    bool Match(IAction action);
    3535    void SetTo(string value);
     36    void SetTo(IGAssistNiche action);
    3637
    3738    IEnumerable<int> GetPossibleActionPositions();
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/IntAction.cs

    r9411 r9605  
    117117
    118118    public void SetTo(string value) {
    119       currentAction = int.Parse(value);
     119      SetToPosition(int.Parse(value));
     120    }
     121
     122    public void SetTo(IGAssistNiche action) {
     123      var castAction = action as IntAction;
     124      if (castAction == null) throw new ArgumentException("action has to be IntAction");
     125      SetToPosition(castAction.CurrentAction);
    120126    }
    121127
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/StringAction.cs

    r9411 r9605  
    122122
    123123    public void SetTo(string value) {
    124       currentActionIndex = possibleFeatures.IndexOf(value);
     124      SetToPosition(possibleFeatures.IndexOf(value));
     125    }
     126
     127    public void SetTo(IGAssistNiche action) {
     128      var castAction = action as StringAction;
     129      if (castAction == null) throw new ArgumentException("action has to be IntAction");
     130      SetToPosition(castAction.CurrentPosition);
    125131    }
    126132
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Creators/UniformRandomDecisionListCreator.cs

    r9352 r9605  
    4343    }
    4444
    45     protected override DecisionList Create(IRandom random, Rule sampleRule, int initialNumberOfRules, double oneProbability, ItemCollection<IDiscretizer> discretizers) {
     45    protected override DecisionList Create(IRandom random, Rule sampleRule, int initialNumberOfRules, double oneProbability, ItemCollection<IDiscretizer> discretizers, IAction niche) {
    4646      List<Rule> rules = new List<Rule>();
    4747      for (int i = 0; i < initialNumberOfRules; i++) {
    4848        var newRule = (Rule)sampleRule.Clone();
    49         newRule.Randomize(random, oneProbability, discretizers);
     49        if (niche != null) {
     50          newRule.Randomize(random, oneProbability, discretizers, new List<IAction>() { niche });
     51        } else {
     52          newRule.Randomize(random, oneProbability, discretizers);
     53        }
    5054        rules.Add(newRule);
    5155      }
    5256
    53       return new DecisionList(rules);
     57      if (niche != null) {
     58        return new DecisionList(rules, niche);
     59      } else {
     60        return new DecisionList(rules);
     61      }
    5462    }
    5563  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Crossover/SinglePointCrossover.cs

    r9352 r9605  
    4848
    4949    public static DecisionList Apply(IRandom random, DecisionList parent1, DecisionList parent2) {
    50       if (!parent1.DefaultAction.Match(parent2.DefaultAction)) { throw new ArgumentException("Default action of parents have to match!"); }
     50      if (parent1 == null && parent1 != parent2) { throw new ArgumentException("Either both parents have a default action or none does."); }
     51      if (parent1.DefaultAction != null && !parent1.DefaultAction.Match(parent2.DefaultAction)) { throw new ArgumentException("Default action of parents have to match!"); }
    5152
    5253      int rulesP1 = random.Next(0, parent1.Rules.Count());
     
    6465      }
    6566
     67      if (parent1.DefaultAction == null) {
     68        return new DecisionList(rules);
     69      }
    6670      return new DecisionList(rules, parent1.DefaultAction);
    6771    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionList.cs

    r9411 r9605  
    4444    }
    4545
     46    public double Length {
     47      get { return 1 + rules.Sum(r => r.Length); }
     48    }
     49
    4650    // default rule (action) is part of the rule set size
    4751    public int RuleSetSize {
     
    5357    protected DecisionList(DecisionList original, Cloner cloner)
    5458      : base(original, cloner) {
    55       defaultAction = original.DefaultAction;
     59      defaultAction = cloner.Clone(original.DefaultAction);
    5660      rules = new List<Rule>(original.rules.Count);
    5761      foreach (var rule in original.Rules) {
     
    124128    }
    125129
    126     public void SetNiche(IRandom random, IGAssistNiche niche) {
    127       var action = niche as IAction;
    128       if (action == null) {
    129         throw new ArgumentException("Niche has to be an action");
    130       }
    131       if (Niche != null) {
    132         throw new ArgumentException("Niche has already been set. It cannot be set again.");
    133       }
    134       defaultAction = action;
    135       var except = new List<IAction>() { action };
    136       foreach (var rule in rules.Where(x => x.Action.SameNiche(niche))) {
    137         rule.Action.Randomize(random, except);
    138       }
    139     }
    140 
    141130    public void ApplySplit(IRandom random, double probability) {
    142131      foreach (var rule in rules) {
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListCreator.cs

    r9352 r9605  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5253      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    5354    }
     55    public ILookupParameter<IGAssistNiche> GAssistNicheParameter {
     56      get { return (ILookupParameter<IGAssistNiche>)Parameters["GAssistNiche"]; }
     57    }
    5458    #endregion
    5559
     
    6771      Parameters.Add(new LookupParameter<DecisionList>("DecisionList", ""));
    6872      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    69       Parameters.Add(new ValueLookupParameter<IAction>("DefaultAction", ""));
     73      Parameters.Add(new LookupParameter<IGAssistNiche>("GAssistNiche", ""));
    7074    }
    7175
    7276    public override IOperation Apply() {
    73       DecisionListParameter.ActualValue = Create(RandomParameter.ActualValue, ProblemDataParameter.ActualValue.SampleRuleParameter.Value, InitialNumberOfRulesParameter.ActualValue.Value, OneProbabilityParameter.ActualValue.Value, DiscretizersParameter.ActualValue);
     77      if (GAssistNicheParameter.ActualValue != null && !(GAssistNicheParameter.ActualValue is IAction)) throw new ArgumentException("GAssistNiche has to be a IAction.");
     78      DecisionListParameter.ActualValue = Create(RandomParameter.ActualValue,
     79                                              ProblemDataParameter.ActualValue.SampleRuleParameter.Value,
     80                                              InitialNumberOfRulesParameter.ActualValue.Value,
     81                                              OneProbabilityParameter.ActualValue.Value,
     82                                              DiscretizersParameter.ActualValue,
     83                                              (IAction)GAssistNicheParameter.ActualValue);
    7484      return base.Apply();
    7585    }
    7686
    77     protected abstract DecisionList Create(IRandom random, Rule sampleRule, int initialNumberOfRules, double oneProbability, ItemCollection<IDiscretizer> discretizers);
     87    protected abstract DecisionList Create(IRandom random, Rule sampleRule, int initialNumberOfRules, double oneProbability, ItemCollection<IDiscretizer> discretizers, IAction niche);
    7888  }
    7989}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Evaluator/MDLEvaluator.cs

    r9475 r9605  
    4949      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    5050    }
     51    public ILookupParameter<DoubleValue> LengthParameter {
     52      get { return (ILookupParameter<DoubleValue>)Parameters["Length"]; }
     53    }
    5154    public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter {
    5255      get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; }
    5356    }
    5457
     58    public IValueLookupParameter<BoolValue> UseMDLParameter {
     59      get { return (IValueLookupParameter<BoolValue>)Parameters["UseMDL"]; }
     60    }
    5561    public ILookupParameter<MDLCalculator> MDLCalculatorParameter {
    5662      get { return (ILookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; }
     
    7379      get { return (ILookupParameter<ItemList<ItemList<IntValue>>>)Parameters["Strata"]; }
    7480    }
     81    public IValueLookupParameter<BoolValue> MaximizationParameter {
     82      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     83    }
    7584    #endregion
    7685
     
    9099      Parameters.Add(new ValueLookupParameter<IntValue>("SizePenaltyMinRules", ""));
    91100      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
     101      Parameters.Add(new LookupParameter<DoubleValue>("Length", ""));
    92102      Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", ""));
     103      Parameters.Add(new ValueLookupParameter<BoolValue>("UseMDL", "", new BoolValue(true)));
    93104      Parameters.Add(new LookupParameter<MDLCalculator>("MDLCalculator", ""));
    94105      Parameters.Add(new LookupParameter<IntValue>("Iterations", ""));
     
    97108      Parameters.Add(new ValueLookupParameter<IntValue>("RuleDeletionMinRules", "", new IntValue(12)));
    98109      Parameters.Add(new ValueLookupParameter<ItemList<ItemList<IntValue>>>("Strata", ""));
     110      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "", new BoolValue(false)));
     111
     112      UseMDLParameter.Value.ValueChanged += UseMDLParameter_ValueChanged;
     113    }
     114
     115    private void UseMDLParameter_ValueChanged(object sender, System.EventArgs e) {
     116      MaximizationParameter.Value.Value = !UseMDLParameter.Value.Value;
    99117    }
    100118    public override IDeepCloneable Clone(Cloner cloner) {
     
    103121
    104122    public override IOperation Apply() {
    105       double penalty = 1;
    106 
    107123      var strata = StrataParameter.ActualValue;
    108124      int iteration = IterationsParameter.ActualValue.Value;
     
    125141      var estimated = dl.Evaluate(input, out aliveRules, out theoryLength);
    126142
     143      double penalty = 1;
    127144      if (aliveRules.Count < SizePenaltyMinRulesParameter.ActualValue.Value) {
    128145        penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - aliveRules.Count));
     
    132149
    133150      double accuracy = DecisionListSolution.CalculateAccuracy(actions, estimated);
    134       QualityParameter.ActualValue = new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(theoryLength, accuracy) / penalty);
     151      if (UseMDLParameter.ActualValue.Value) {
     152        QualityParameter.ActualValue =
     153          new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(theoryLength, accuracy) / penalty);
     154      } else {
     155        QualityParameter.ActualValue = new DoubleValue(accuracy * accuracy * penalty);
     156      }
    135157
    136158      if (iteration >= IterationRuleDeletionParameter.ActualValue.Value) {
     
    141163        }
    142164      }
     165
     166      LengthParameter.ActualValue = new DoubleValue(dl.Length * aliveRules.Count / dl.RuleSetSize);
    143167      return base.Apply();
    144168    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/HeuristicLab.Encodings.DecisionList-3.3.csproj

    r9411 r9605  
    9393    <Compile Include="Action\IntAction.cs" />
    9494    <Compile Include="Analyzer\BestTrainingDecisionListAnalyzer.cs" />
     95    <Compile Include="Creators\SmartDecisionListCreator.cs" />
    9596    <Compile Include="Creators\UniformRandomDecisionListCreator.cs" />
    9697    <Compile Include="Crossover\SinglePointCrossover.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListCreator.cs

    r9352 r9605  
    2626
    2727namespace HeuristicLab.Encodings.DecisionList {
    28   public interface IDecisionListCreator : IDecisionListOperator, ISolutionCreator, IStochasticOperator, IGAssistIndividualCreator {
     28  public interface IDecisionListCreator : IDecisionListOperator, ISolutionCreator, IStochasticOperator, IGAssistSolutionCreator {
    2929    IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { get; }
    3030    ILookupParameter<DecisionList> DecisionListParameter { get; }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListEvaluator.cs

    r9392 r9605  
    2525
    2626namespace HeuristicLab.Encodings.DecisionList {
    27   public interface IDecisionListEvaluator : IStrataSingleObjectiveEvaluator {
     27  public interface IDecisionListEvaluator : IGAssistObjectiveEvaluator {
    2828    ILookupParameter<DecisionList> DecisionListParameter { get; }
    2929    IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { get; }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Plugin.cs.frame

    r9334 r9605  
    2727  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2828  [PluginDependency("HeuristicLab.Common", "3.3")]
    29   [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
     29  [PluginDependency("HeuristicLab.Core", "3.3")]
     30  [PluginDependency("HeuristicLab.Data", "3.3")]
     31  [PluginDependency("HeuristicLab.Operators", "3.3")]
     32  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     33  [PluginDependency("HeuristicLab.Optimization.Operators.LCS", "3.3")]
     34  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3035  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     36  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
    3137  public class HeuristicLabEncodingsDecisionListPlugin : PluginBase {
    3238  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Rule.cs

    r9392 r9605  
    4343    public IAction Action { get { return action; } }
    4444
     45    public double Length {
     46      get { return variables.Values.Sum(x => x.Length); }
     47    }
     48
    4549    [StorableConstructor]
    4650    protected Rule(bool deserializing) : base(deserializing) { }
     
    7781    }
    7882
    79     public void Randomize(IRandom random, double onePercentage, IEnumerable<IDiscretizer> discretizer) {
     83    public void Randomize(IRandom random, double oneProbability, IEnumerable<IDiscretizer> discretizers, IEnumerable<IAction> exceptActions = null) {
    8084      foreach (var variable in variables.Values) {
    81         variable.Randomize(random, onePercentage, discretizer);
     85        variable.Randomize(random, oneProbability, discretizers);
    8286      }
    83       action.Randomize(random);
     87      if (exceptActions == null) {
     88        action.Randomize(random);
     89      } else {
     90        action.Randomize(random, exceptActions);
     91      }
     92    }
     93
     94    public void SetToMatchInput(IGAssistInput input) {
     95      foreach (var variable in variables) {
     96        if (!input.VariableNames.Contains(variable.Key)) {
     97          throw new ArgumentException("input does not contain variable name of rule");
     98        }
     99        variable.Value.SetToMatch(input.GetVariableValue(variable.Key));
     100      }
    84101    }
    85102
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/DoubleVariable.cs

    r9392 r9605  
    191191    public override void Reinitialize(IRandom random, double onePercentage, IEnumerable<IDiscretizer> descretizers) {
    192192      Randomize(random, onePercentage, descretizers);
    193       return;
     193    }
     194
     195    public override void SetToMatch(string variableValue) {
     196      var value = double.Parse(variableValue);
     197      var realCutpoints = GetValuesToCutPoints(discretizer.GetCutPoints(variableName), curIntervals);
     198      int pos = 0;
     199      while (value >= realCutpoints[pos]) {
     200        pos++;
     201      }
     202      attributes[pos] = true;
    194203    }
    195204  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/IVariable.cs

    r9342 r9605  
    2727namespace HeuristicLab.Encodings.DecisionList {
    2828  public interface IVariable : IItem {
     29    double Length { get; }
    2930    string VariableName { get; }
    3031    Type VariableType { get; }
     
    4344
    4445    void Split(IRandom Random);
     46
     47    void SetToMatch(string variableValue);
    4548  }
    4649}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/IntVariable.cs

    r9334 r9605  
    6868      return attributes[possibleFeatures.IndexOf(input)];
    6969    }
     70
     71    public override void SetToMatch(string variableValue) {
     72      var value = int.Parse(variableValue);
     73      if (!possibleFeatures.Contains(value)) throw new ArgumentException("variableValue " + variableValue + " is not a possible value of variable " + variableName);
     74
     75      attributes[possibleFeatures.IndexOf(value)] = true;
     76    }
    7077  }
    7178}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/StringVariable.cs

    r9334 r9605  
    6464      return attributes[possibleFeatures.IndexOf(input)];
    6565    }
     66
     67    public override void SetToMatch(string variableValue) {
     68      var valueIndex = possibleFeatures.IndexOf(variableValue);
     69      if (valueIndex == -1) throw new ArgumentException("variableValue " + variableValue + " is not a possible value of variable " + variableName);
     70
     71      attributes[valueIndex] = true;
     72    }
    6673  }
    6774}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/Variable.cs

    r9352 r9605  
    3838    }
    3939
     40    public double Length {
     41      get { return attributes.Count; }
     42    }
     43
    4044    [Storable]
    4145    protected string variableName;
     
    7276    public abstract bool Match(string input);
    7377
     78    public abstract void SetToMatch(string variableValue);
     79
    7480    public virtual string ToFullString() { throw new NotImplementedException(); }
    7581
Note: See TracChangeset for help on using the changeset viewer.