Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/13 15:15:13 (12 years ago)
Author:
sforsten
Message:

#1980:

  • added DecisionListView
  • added event handlers in *ProblemData
  • renamed project Problems.XCS.Views to Problems.lCS.Views and Problems.Instances.ConditionActionClassification to Problems.Instances.LCS
  • integrated niching in GAssist and added NichingTournamentSelector
  • minor code improvements and property changes
Location:
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3
Files:
3 added
13 edited

Legend:

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

    r9334 r9352  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Optimization.Operators.LCS;
    2425
    2526namespace HeuristicLab.Encodings.DecisionList {
    26   public interface IAction : IItem {
     27  public interface IAction : IGAssistNiche {
    2728    string VariableName { get; }
    2829
    2930    int Possibilities { get; }
    3031    void Randomize(IRandom random);
     32    void Randomize(IRandom random, IEnumerable<IAction> except);
    3133
    3234    bool Match(IAction action);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/IntAction.cs

    r9334 r9352  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Optimization.Operators.LCS;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    3132  [Item("IntAction", "")]
    3233  public class IntAction : Item, IAction<int> {
     34
     35    public static IEqualityComparer<IGAssistNiche> Comparer {
     36      get { return new DecisionListNicheComparer(); }
     37    }
     38    IEqualityComparer<IGAssistNiche> IGAssistNiche.Comparer {
     39      get { return Comparer; }
     40    }
    3341
    3442    [Storable]
     
    8896    }
    8997
     98    public void Randomize(IRandom random, IEnumerable<IAction> except) {
     99      if (except.Count() == 0) {
     100        Randomize(random);
     101        return;
     102      }
     103      try {
     104        var exceptInt = except.Cast<IntAction>().Select(x => x.currentAction);
     105        var newPossibleFeatures = possibleFeatures.Except(exceptInt);
     106        currentAction = newPossibleFeatures.ElementAt(random.Next(0, newPossibleFeatures.Count()));
     107      }
     108      catch (InvalidCastException) {
     109        throw new InvalidCastException("Actions have to be of type IntAction");
     110      }
     111    }
     112
    90113    public bool Match(IAction action) {
    91114      var targetCast = action as IntAction;
     
    103126
    104127    public override string ToString() {
    105       return currentAction.ToString();
     128      return variableName + ": " + currentAction.ToString();
     129    }
     130
     131    public bool SameNiche(IGAssistNiche niche) {
     132      return Match(niche as IAction);
     133    }
     134
     135    public int GetNicheHashCode() {
     136      int result = 1;
     137      result = 37 * result + currentAction;
     138      result = 37 * result + variableName.GetHashCode();
     139      foreach (var feature in possibleFeatures) {
     140        result = 37 * result + feature;
     141      }
     142      return result;
    106143    }
    107144  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/StringAction.cs

    r9334 r9352  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Optimization.Operators.LCS;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    3132  [Item("StringAction", "")]
    3233  public class StringAction : Item, IAction<string> {
     34
     35    public static IEqualityComparer<IGAssistNiche> Comparer {
     36      get { return new DecisionListNicheComparer(); }
     37    }
     38
     39    IEqualityComparer<IGAssistNiche> IGAssistNiche.Comparer {
     40      get { return Comparer; }
     41    }
    3342
    3443    [Storable]
     
    92101    }
    93102
     103    public void Randomize(IRandom random, IEnumerable<IAction> except) {
     104      if (except.Count() == 0) {
     105        Randomize(random);
     106        return;
     107      }
     108      try {
     109        var exceptInt = except.Cast<StringAction>().Select(x => x.CurrentActionIndex);
     110        var newPossibleFeatures = Enumerable.Range(0, possibleFeatures.Count()).Except(exceptInt);
     111        currentActionIndex = newPossibleFeatures.ElementAt(random.Next(0, newPossibleFeatures.Count()));
     112      }
     113      catch (InvalidCastException) {
     114        throw new InvalidCastException("Actions have to be of type IntAction");
     115      }
     116    }
     117
    94118    public bool Match(IAction action) {
    95119      var targetCast = action as StringAction;
     
    107131
    108132    public override string ToString() {
    109       return CurrentAction;
     133      return variableName + ": " + CurrentAction;
     134    }
     135
     136    public bool SameNiche(IGAssistNiche niche) {
     137      return Match(niche as IAction);
     138    }
     139
     140    public int GetNicheHashCode() {
     141      int result = 1;
     142      result = 37 * result + currentActionIndex;
     143      result = 37 * result + variableName.GetHashCode();
     144      foreach (var feature in possibleFeatures) {
     145        result = 37 * result + feature.GetHashCode();
     146      }
     147      return result;
    110148    }
    111149  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Creators/UniformRandomDecisionListCreator.cs

    r9342 r9352  
    5151      }
    5252
    53       return new DecisionList(rules); //, DefaultActionParameter.ActualValue);
     53      return new DecisionList(rules);
    5454    }
    5555  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Crossover/SinglePointCrossover.cs

    r9342 r9352  
    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!"); }
     51
    5052      int rulesP1 = random.Next(0, parent1.Rules.Count());
    5153      int rulesP2 = random.Next(0, parent2.Rules.Count());
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionList.cs

    r9342 r9352  
    109109    #region IGAssistIndividual Members
    110110
     111    public IGAssistNiche Niche {
     112      get { return defaultAction; }
     113    }
     114
     115    public void SetNiche(IRandom random, IGAssistNiche niche) {
     116      var action = niche as IAction;
     117      if (action == null) {
     118        throw new ArgumentException("Niche has to be an action");
     119      }
     120      if (Niche != null) {
     121        throw new ArgumentException("Niche has already been set. It cannot be set again.");
     122      }
     123      defaultAction = action;
     124      var except = new List<IAction>() { action };
     125      foreach (var rule in rules.Where(x => x.Action.SameNiche(niche))) {
     126        rule.Action.Randomize(random, except);
     127      }
     128    }
     129
    111130    public void ApplySplit(IRandom random, double probability) {
    112131      foreach (var rule in rules) {
     
    126145      }
    127146    }
    128 
    129147    #endregion
    130148  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListCreator.cs

    r9342 r9352  
    5252      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    5353    }
    54     public IValueLookupParameter<IAction> DefaultActionParameter {
    55       get { return (IValueLookupParameter<IAction>)Parameters["DefaultAction"]; }
    56     }
    5754    #endregion
    5855
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/HeuristicLab.Encodings.DecisionList-3.3.csproj

    r9342 r9352  
    9292    <Compile Include="Action\IAction.cs" />
    9393    <Compile Include="Action\IntAction.cs" />
     94    <Compile Include="Analyzer\BestTrainingDecisionListAnalyzer.cs" />
    9495    <Compile Include="Creators\UniformRandomDecisionListCreator.cs" />
    9596    <Compile Include="Crossover\SinglePointCrossover.cs" />
     
    9798    <Compile Include="DecisionListCrossover.cs" />
    9899    <Compile Include="DecisionListManipulator.cs" />
     100    <Compile Include="DecisionListNicheComparer.cs" />
    99101    <Compile Include="DecisionListSolution.cs" />
    100102    <Compile Include="Evaluator\DecisionListEvaluator.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListClassificationProblemData.cs

    r9342 r9352  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization.Operators.LCS;
    2627using HeuristicLab.Problems.DataAnalysis;
    2728
    2829namespace HeuristicLab.Encodings.DecisionList {
    29   public interface IDecisionListClassificationProblemData : INamedItem {
     30  public interface IDecisionListClassificationProblemData : IGAssistNichesProblemData {
    3031    Dataset Dataset { get; }
    3132    ICheckedItemList<StringValue> ConditionVariables { get; }
     
    4546    int Classes { get; }
    4647
    47     IFixedValueParameter<Rule> SampleRuleParameter { get; }
     48    IValueParameter<Rule> SampleRuleParameter { get; }
    4849
    4950    DecisionListInput FetchInput(int row);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListCreator.cs

    r9342 r9352  
    3131    IValueLookupParameter<IntValue> InitialNumberOfRulesParameter { get; }
    3232    IValueLookupParameter<PercentValue> OneProbabilityParameter { get; }
    33     IValueLookupParameter<IAction> DefaultActionParameter { get; }
    3433  }
    3534}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Properties/AssemblyInfo.cs

    r9334 r9352  
    2121
    2222using System.Reflection;
     23using System.Runtime.CompilerServices;
    2324using System.Runtime.InteropServices;
    2425
     
    5455// [assembly: AssemblyVersion("1.0.*")]
    5556[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.7.9204")]
     57[assembly: AssemblyFileVersion("3.3.7.9342")]
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Rule.cs

    r9342 r9352  
    7373        sb.Append(variable.Value + "|");
    7474      }
    75       sb.Append(Action);
     75      sb.Append("|" + Action);
    7676      return sb.ToString();
    7777    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/Variable.cs

    r9342 r9352  
    7676    public override string ToString() {
    7777      StringBuilder sb = new StringBuilder();
     78      sb.Append(variableName + ": ");
    7879      foreach (var attr in attributes) {
    7980        if (attr) {
Note: See TracChangeset for help on using the changeset viewer.