- Timestamp:
- 06/11/13 13:32:32 (12 years ago)
- 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 34 34 bool Match(IAction action); 35 35 void SetTo(string value); 36 void SetTo(IGAssistNiche action); 36 37 37 38 IEnumerable<int> GetPossibleActionPositions(); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/IntAction.cs
r9411 r9605 117 117 118 118 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); 120 126 } 121 127 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Action/StringAction.cs
r9411 r9605 122 122 123 123 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); 125 131 } 126 132 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Creators/UniformRandomDecisionListCreator.cs
r9352 r9605 43 43 } 44 44 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) { 46 46 List<Rule> rules = new List<Rule>(); 47 47 for (int i = 0; i < initialNumberOfRules; i++) { 48 48 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 } 50 54 rules.Add(newRule); 51 55 } 52 56 53 return new DecisionList(rules); 57 if (niche != null) { 58 return new DecisionList(rules, niche); 59 } else { 60 return new DecisionList(rules); 61 } 54 62 } 55 63 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Crossover/SinglePointCrossover.cs
r9352 r9605 48 48 49 49 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!"); } 51 52 52 53 int rulesP1 = random.Next(0, parent1.Rules.Count()); … … 64 65 } 65 66 67 if (parent1.DefaultAction == null) { 68 return new DecisionList(rules); 69 } 66 70 return new DecisionList(rules, parent1.DefaultAction); 67 71 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionList.cs
r9411 r9605 44 44 } 45 45 46 public double Length { 47 get { return 1 + rules.Sum(r => r.Length); } 48 } 49 46 50 // default rule (action) is part of the rule set size 47 51 public int RuleSetSize { … … 53 57 protected DecisionList(DecisionList original, Cloner cloner) 54 58 : base(original, cloner) { 55 defaultAction = original.DefaultAction;59 defaultAction = cloner.Clone(original.DefaultAction); 56 60 rules = new List<Rule>(original.rules.Count); 57 61 foreach (var rule in original.Rules) { … … 124 128 } 125 129 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 141 130 public void ApplySplit(IRandom random, double probability) { 142 131 foreach (var rule in rules) { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListCreator.cs
r9352 r9605 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 52 53 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 53 54 } 55 public ILookupParameter<IGAssistNiche> GAssistNicheParameter { 56 get { return (ILookupParameter<IGAssistNiche>)Parameters["GAssistNiche"]; } 57 } 54 58 #endregion 55 59 … … 67 71 Parameters.Add(new LookupParameter<DecisionList>("DecisionList", "")); 68 72 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", "")); 70 74 } 71 75 72 76 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); 74 84 return base.Apply(); 75 85 } 76 86 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); 78 88 } 79 89 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Evaluator/MDLEvaluator.cs
r9475 r9605 49 49 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 50 50 } 51 public ILookupParameter<DoubleValue> LengthParameter { 52 get { return (ILookupParameter<DoubleValue>)Parameters["Length"]; } 53 } 51 54 public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { 52 55 get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; } 53 56 } 54 57 58 public IValueLookupParameter<BoolValue> UseMDLParameter { 59 get { return (IValueLookupParameter<BoolValue>)Parameters["UseMDL"]; } 60 } 55 61 public ILookupParameter<MDLCalculator> MDLCalculatorParameter { 56 62 get { return (ILookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; } … … 73 79 get { return (ILookupParameter<ItemList<ItemList<IntValue>>>)Parameters["Strata"]; } 74 80 } 81 public IValueLookupParameter<BoolValue> MaximizationParameter { 82 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 83 } 75 84 #endregion 76 85 … … 90 99 Parameters.Add(new ValueLookupParameter<IntValue>("SizePenaltyMinRules", "")); 91 100 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 101 Parameters.Add(new LookupParameter<DoubleValue>("Length", "")); 92 102 Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", "")); 103 Parameters.Add(new ValueLookupParameter<BoolValue>("UseMDL", "", new BoolValue(true))); 93 104 Parameters.Add(new LookupParameter<MDLCalculator>("MDLCalculator", "")); 94 105 Parameters.Add(new LookupParameter<IntValue>("Iterations", "")); … … 97 108 Parameters.Add(new ValueLookupParameter<IntValue>("RuleDeletionMinRules", "", new IntValue(12))); 98 109 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; 99 117 } 100 118 public override IDeepCloneable Clone(Cloner cloner) { … … 103 121 104 122 public override IOperation Apply() { 105 double penalty = 1;106 107 123 var strata = StrataParameter.ActualValue; 108 124 int iteration = IterationsParameter.ActualValue.Value; … … 125 141 var estimated = dl.Evaluate(input, out aliveRules, out theoryLength); 126 142 143 double penalty = 1; 127 144 if (aliveRules.Count < SizePenaltyMinRulesParameter.ActualValue.Value) { 128 145 penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - aliveRules.Count)); … … 132 149 133 150 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 } 135 157 136 158 if (iteration >= IterationRuleDeletionParameter.ActualValue.Value) { … … 141 163 } 142 164 } 165 166 LengthParameter.ActualValue = new DoubleValue(dl.Length * aliveRules.Count / dl.RuleSetSize); 143 167 return base.Apply(); 144 168 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/HeuristicLab.Encodings.DecisionList-3.3.csproj
r9411 r9605 93 93 <Compile Include="Action\IntAction.cs" /> 94 94 <Compile Include="Analyzer\BestTrainingDecisionListAnalyzer.cs" /> 95 <Compile Include="Creators\SmartDecisionListCreator.cs" /> 95 96 <Compile Include="Creators\UniformRandomDecisionListCreator.cs" /> 96 97 <Compile Include="Crossover\SinglePointCrossover.cs" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListCreator.cs
r9352 r9605 26 26 27 27 namespace HeuristicLab.Encodings.DecisionList { 28 public interface IDecisionListCreator : IDecisionListOperator, ISolutionCreator, IStochasticOperator, IGAssist IndividualCreator {28 public interface IDecisionListCreator : IDecisionListOperator, ISolutionCreator, IStochasticOperator, IGAssistSolutionCreator { 29 29 IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { get; } 30 30 ILookupParameter<DecisionList> DecisionListParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListEvaluator.cs
r9392 r9605 25 25 26 26 namespace HeuristicLab.Encodings.DecisionList { 27 public interface IDecisionListEvaluator : I StrataSingleObjectiveEvaluator {27 public interface IDecisionListEvaluator : IGAssistObjectiveEvaluator { 28 28 ILookupParameter<DecisionList> DecisionListParameter { get; } 29 29 IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Plugin.cs.frame
r9334 r9605 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] 28 28 [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")] 30 35 [PluginDependency("HeuristicLab.Persistence", "3.3")] 36 [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")] 31 37 public class HeuristicLabEncodingsDecisionListPlugin : PluginBase { 32 38 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Rule.cs
r9392 r9605 43 43 public IAction Action { get { return action; } } 44 44 45 public double Length { 46 get { return variables.Values.Sum(x => x.Length); } 47 } 48 45 49 [StorableConstructor] 46 50 protected Rule(bool deserializing) : base(deserializing) { } … … 77 81 } 78 82 79 public void Randomize(IRandom random, double oneP ercentage, IEnumerable<IDiscretizer> discretizer) {83 public void Randomize(IRandom random, double oneProbability, IEnumerable<IDiscretizer> discretizers, IEnumerable<IAction> exceptActions = null) { 80 84 foreach (var variable in variables.Values) { 81 variable.Randomize(random, oneP ercentage, discretizer);85 variable.Randomize(random, oneProbability, discretizers); 82 86 } 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 } 84 101 } 85 102 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/DoubleVariable.cs
r9392 r9605 191 191 public override void Reinitialize(IRandom random, double onePercentage, IEnumerable<IDiscretizer> descretizers) { 192 192 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; 194 203 } 195 204 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/IVariable.cs
r9342 r9605 27 27 namespace HeuristicLab.Encodings.DecisionList { 28 28 public interface IVariable : IItem { 29 double Length { get; } 29 30 string VariableName { get; } 30 31 Type VariableType { get; } … … 43 44 44 45 void Split(IRandom Random); 46 47 void SetToMatch(string variableValue); 45 48 } 46 49 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/IntVariable.cs
r9334 r9605 68 68 return attributes[possibleFeatures.IndexOf(input)]; 69 69 } 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 } 70 77 } 71 78 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/StringVariable.cs
r9334 r9605 64 64 return attributes[possibleFeatures.IndexOf(input)]; 65 65 } 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 } 66 73 } 67 74 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/Variable.cs
r9352 r9605 38 38 } 39 39 40 public double Length { 41 get { return attributes.Count; } 42 } 43 40 44 [Storable] 41 45 protected string variableName; … … 72 76 public abstract bool Match(string input); 73 77 78 public abstract void SetToMatch(string variableValue); 79 74 80 public virtual string ToFullString() { throw new NotImplementedException(); } 75 81
Note: See TracChangeset
for help on using the changeset viewer.