Changeset 9110 for branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding
- Timestamp:
- 01/04/13 20:46:18 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3
- Files:
-
- 4 added
- 1 deleted
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/CoveringOperator.cs
r9105 r9110 101 101 throw new ArgumentException("More classifiers with unique actions shall be created than unique actions are available."); 102 102 } 103 if (count > 0) { 104 CurrentPopulationSizeParameter.ActualValue.Value += count; 103 105 104 CurrentPopulationSizeParameter.ActualValue.Value += count; 106 int current = CurrentScope.SubScopes.Count; 107 for (int i = 0; i < count; i++) { 108 CurrentScope.SubScopes.Add(new Scope((current + i).ToString())); 109 } 105 110 106 int current = CurrentScope.SubScopes.Count; 107 for (int i = 0; i < count; i++) { 108 CurrentScope.SubScopes.Add(new Scope((current + i).ToString())); 111 creator.ActionParameter.ActualName = "Action"; 112 OperationCollection variableCreation = new OperationCollection() { Parallel = parallel }; 113 OperationCollection creation = new OperationCollection(); 114 OperationCollection evaluation = new OperationCollection() { Parallel = parallel }; 115 for (int i = 0; i < count; i++) { 116 VariableCreator variableCreator = new VariableCreator(); 117 int pos = RandomParameter.ActualValue.Next(clone.Count); 118 IClassifier action = clone.ElementAt(pos); 119 clone.Remove(action); 120 variableCreator.CollectedValues.Add(new ValueParameter<IClassifier>("Action", action)); 121 variableCreation.Add(ExecutionContext.CreateOperation(variableCreator, CurrentScope.SubScopes[current + i])); 122 creation.Add(ExecutionContext.CreateOperation(creator, CurrentScope.SubScopes[current + i])); 123 evaluation.Add(ExecutionContext.CreateOperation(evaluator, CurrentScope.SubScopes[current + i])); 124 } 125 OperationCollection next = new OperationCollection(); 126 next.Add(variableCreation); 127 next.Add(creation); 128 next.Add(evaluation); 129 next.Add(base.Apply()); 130 return next; 131 } else { 132 return base.Apply(); 109 133 } 110 111 creator.ActionParameter.ActualName = "Action";112 OperationCollection variableCreation = new OperationCollection() { Parallel = parallel };113 OperationCollection creation = new OperationCollection();114 OperationCollection evaluation = new OperationCollection() { Parallel = parallel };115 for (int i = 0; i < count; i++) {116 VariableCreator variableCreator = new VariableCreator();117 int pos = RandomParameter.ActualValue.Next(clone.Count);118 IClassifier action = clone.ElementAt(pos);119 clone.Remove(action);120 variableCreator.CollectedValues.Add(new ValueParameter<IClassifier>("Action", action));121 variableCreation.Add(ExecutionContext.CreateOperation(variableCreator, CurrentScope.SubScopes[current + i]));122 creation.Add(ExecutionContext.CreateOperation(creator, CurrentScope.SubScopes[current + i]));123 evaluation.Add(ExecutionContext.CreateOperation(evaluator, CurrentScope.SubScopes[current + i]));124 }125 OperationCollection next = new OperationCollection();126 next.Add(variableCreation);127 next.Add(creation);128 next.Add(evaluation);129 next.Add(base.Apply());130 return next;131 134 } 132 135 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/DoDeletionBeforeCovering.cs
r9105 r9110 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 33 34 34 35 #region Parameter Properties 36 public ILookupParameter<ItemArray<IClassifier>> ClassifiersParameter { 37 get { return (ILookupParameter<ItemArray<IClassifier>>)Parameters["Classifiers"]; } 38 } 39 public ILookupParameter<ItemArray<BoolValue>> MatchConditionParameter { 40 get { return (ILookupParameter<ItemArray<BoolValue>>)Parameters["MatchCondition"]; } 41 } 35 42 public ILookupParameter<IntValue> MinimalNumberOfUniqueActionsParameter { 36 43 get { return (ILookupParameter<IntValue>)Parameters["MinimalNumberOfUniqueActions"]; } 37 }38 public ILookupParameter<IntValue> NumberOfUniqueActionsParameter {39 get { return (ILookupParameter<IntValue>)Parameters["NumberOfUniqueActions"]; }40 44 } 41 45 public ILookupParameter<IntValue> CurrentPopulationSizeParameter { … … 60 64 public DoDeletionBeforeCoveringOperator() 61 65 : base() { 66 Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers")); 67 Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("MatchCondition")); 62 68 Parameters.Add(new LookupParameter<IntValue>("MinimalNumberOfUniqueActions")); 63 Parameters.Add(new LookupParameter<IntValue>("NumberOfUniqueActions"));64 69 Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize")); 65 70 Parameters.Add(new LookupParameter<IntValue>("PopulationSize")); … … 72 77 73 78 public override IOperation Apply() { 79 IItemSet<IClassifier> uniqueActions = new ItemSet<IClassifier>(); 80 var classifiers = ClassifiersParameter.ActualValue; 81 var matchcondition = MatchConditionParameter.ActualValue; 82 83 if (classifiers.Length != matchcondition.Length) { 84 throw new ArgumentException("Number of classifiers is not equal to the number of 'MatchCondition' variables."); 85 } 86 87 for (int i = 0; i < classifiers.Length; i++) { 88 if (matchcondition[i].Value) { 89 uniqueActions.Add(classifiers[i].Action); 90 } 91 } 92 74 93 int populationAfterCovering = MinimalNumberOfUniqueActionsParameter.ActualValue.Value 75 - NumberOfUniqueActionsParameter.ActualValue.Value94 - uniqueActions.Count 76 95 + CurrentPopulationSizeParameter.ActualValue.Value; 77 96 BoolValue doDeletion = new BoolValue(populationAfterCovering > PopulationSizeParameter.ActualValue.Value); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Deletion/XCSDeletionOperator.cs
r9105 r9110 51 51 get { return (ILookupParameter<ItemArray<IntValue>>)Parameters["Experiences"]; } 52 52 } 53 public ILookupParameter<ItemArray<BoolValue>> HasToBeDeletedParameter { 54 get { return (ILookupParameter<ItemArray<BoolValue>>)Parameters["HasToBeDeleted"]; } 55 } 53 56 public ILookupParameter<IntValue> ThetaDeletionParameter { 54 57 get { return (ILookupParameter<IntValue>)Parameters["ThetaDeletion"]; } … … 63 66 get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; } 64 67 } 65 protected ScopeParameter CurrentScopeParameter {66 get { return (ScopeParameter)Parameters["CurrentScope"]; }67 }68 public IScope CurrentScope {69 get { return CurrentScopeParameter.ActualValue; }70 }71 public string HasToBeDeletedVariableName { get { return "HasToBeDeleted"; } }72 68 #endregion 73 69 … … 89 85 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Fitnesses")); 90 86 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Experiences")); 87 Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("HasToBeDeleted")); 91 88 Parameters.Add(new LookupParameter<IntValue>("ThetaDeletion")); 92 89 Parameters.Add(new LookupParameter<PercentValue>("Delta")); 93 90 Parameters.Add(new LookupParameter<IRandom>("Random")); 94 Parameters.Add(new ScopeParameter("CurrentScope"));95 91 Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize")); 96 92 } … … 104 100 var experiences = ExperiencesParameter.ActualValue; 105 101 var averageActionSetSizes = AverageActionSetSizesParameter.ActualValue; 106 var subscopes = CurrentScope.SubScopes;102 var hasToBeDeleted = HasToBeDeletedParameter.ActualValue; 107 103 double fitnessSum = fitnesses.Select(x => x.Value).Sum(); 108 104 double numerositySum = numerosities.Select(x => x.Value).Sum(); 109 105 110 if (fitnesses.Length != numerosities.Length && fitnesses.Length != experiences.Length && fitnesses.Length != subscopes.Count) {106 if (fitnesses.Length != numerosities.Length && fitnesses.Length != experiences.Length) { 111 107 throw new ArgumentException("Different number of fitness, numerosity and experience values."); 112 }113 114 for (int cl = 0; cl < fitnesses.Length; cl++) {115 if (subscopes[cl].Variables.ContainsKey(HasToBeDeletedVariableName)) {116 ((BoolValue)subscopes[cl].Variables[HasToBeDeletedVariableName].Value).Value = false;117 } else {118 subscopes[cl].Variables.Add(new Variable(HasToBeDeletedVariableName, new BoolValue(false)));119 }120 108 } 121 109 … … 131 119 voteSum = 0; 132 120 for (int cl = 0; cl < fitnesses.Length; cl++) { 133 if (numerosities[cl].Value > 0 ) {121 if (numerosities[cl].Value > 0 && !hasToBeDeleted[cl].Value) { 134 122 voteSum += DeletionVote(averageFitnessInPopulation, averageActionSetSizes[cl].Value, numerosities[cl].Value, fitnesses[cl].Value, experiences[cl].Value); 135 123 if (voteSum > choicePoint) { 136 124 if (numerosities[cl].Value <= 1) { 137 ((BoolValue)subscopes[cl].Variables[HasToBeDeletedVariableName].Value).Value = true;125 hasToBeDeleted[cl].Value = true; 138 126 fitnessSum -= fitnesses[cl].Value; 139 127 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Evaluators/XCSEvaluator.cs
r9089 r9110 56 56 public IValueLookupParameter<IntValue> NumerosityParameter { 57 57 get { return (IValueLookupParameter<IntValue>)Parameters["Numerosity"]; } 58 } 59 public IValueLookupParameter<BoolValue> InsertInPopulationParameter { 60 get { return (IValueLookupParameter<BoolValue>)Parameters["InsertInPopulation"]; } 58 61 } 59 62 public ILookupParameter<DoubleValue> InitialPredictionParameter { … … 156 159 Parameters.Add(new LookupParameter<DoubleValue>("AccuracySum", "")); 157 160 Parameters.Add(new ValueLookupParameter<IntValue>("Numerosity", "")); 161 Parameters.Add(new ValueLookupParameter<BoolValue>("InsertInPopulation", "")); 158 162 159 163 Parameters.Add(new LookupParameter<DoubleValue>("InitialPrediction")); … … 178 182 AverageActionSetSizeParameter.ActualValue = new DoubleValue(1); 179 183 NumerosityParameter.ActualValue = new IntValue(1); 184 InsertInPopulationParameter.ActualValue = new BoolValue(false); 180 185 } else { 181 186 Experience += 1; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/GA/XCSAfterCrossoverOperator.cs
r9105 r9110 55 55 get { return (IValueLookupParameter<DoubleValue>)Parameters["Fitness"]; } 56 56 } 57 public IValueLookupParameter<BoolValue> InsertInPopulationParameter { 58 get { return (IValueLookupParameter<BoolValue>)Parameters["InsertInPopulation"]; } 59 } 60 public IValueLookupParameter<IntValue> TempIDParameter { 61 get { return (IValueLookupParameter<IntValue>)Parameters["TempID"]; } 62 } 57 63 public ILookupParameter<IntValue> CurrentIterationParameter { 58 64 get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; } … … 86 92 Parameters.Add(new ValueLookupParameter<DoubleValue>("Error")); 87 93 Parameters.Add(new ValueLookupParameter<DoubleValue>("Fitness")); 94 Parameters.Add(new ValueLookupParameter<BoolValue>("InsertInPopulation")); 95 Parameters.Add(new ValueLookupParameter<IntValue>("TempID")); 88 96 Parameters.Add(new LookupParameter<IntValue>("CurrentIteration")); 89 97 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParentAverageActionSetSize")); … … 108 116 ErrorParameter.ActualValue = new DoubleValue(0.25 * parentPrecisionError.Select(x => x.Value).Average()); 109 117 FitnessParameter.ActualValue = new DoubleValue(0.1 * parentFitness.Select(x => x.Value).Average()); 118 InsertInPopulationParameter.ActualValue = new BoolValue(true); 119 TempIDParameter.ActualValue = new IntValue(-1); 110 120 return base.Apply(); 111 121 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj
r9105 r9110 92 92 <Compile Include="Evaluators\IConditionActionEvaluator.cs" /> 93 93 <Compile Include="Evaluators\IXCSEvaluator.cs" /> 94 <Compile Include="GA\InsertInPopulationOperator.cs" /> 94 95 <Compile Include="GA\XCSAfterCrossoverOperator.cs" /> 95 96 <Compile Include="IClassifier.cs" /> … … 102 103 <Compile Include="Operator\MatchActionOperator.cs" /> 103 104 <Compile Include="Operator\MatchConditionOperator.cs" /> 104 <Compile Include="Operator\SubScopeVariableCopier.cs" />105 105 <Compile Include="Operator\SumAccuracy.cs" /> 106 <Compile Include="GA\TempSubScopeIDAssigner.cs" /> 106 107 <Compile Include="Properties\AssemblyInfo.cs" /> 107 108 <Compile Include="Plugin.cs" /> … … 111 112 <Compile Include="Selectors\IMatchSelector.cs" /> 112 113 <Compile Include="Selectors\MatchSelector.cs" /> 113 <Compile Include="Subsumption\ActionSetSubsumptionoperator.cs" /> 114 <Compile Include="Subsumption\ActionSetSubsumptionOperator.cs" /> 115 <Compile Include="Subsumption\CheckGASubsumptionOperator.cs" /> 116 <Compile Include="Subsumption\ExecuteGASubsumptionOperator.cs" /> 114 117 <Compile Include="Subsumption\IActionSetSubsumption.cs" /> 115 118 <None Include="Properties\AssemblyInfo.cs.frame" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblem.cs
r9105 r9110 33 33 IParameter ThetaMinimalNumberOfActionsParameter { get; } 34 34 35 IParameter PossibleActionsConcreteClassParameter { get; } 35 36 IParameter PossibleActionsParameter { get; } 36 IItemSet<IClassifier> PossibleActions { get; }37 //IItemSet<IClassifier> PossibleActions { get; } 37 38 38 39 ICoveringSolutionCreator CoveringSolutionCreator { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/MatchConditionOperator.cs
r9089 r9110 31 31 [StorableClass] 32 32 public class MatchConditionOperator : SingleSuccessorOperator { 33 p rotectedILookupParameter<BoolValue> MatchConditionParameter {33 public ILookupParameter<BoolValue> MatchConditionParameter { 34 34 get { return (ILookupParameter<BoolValue>)Parameters["MatchCondition"]; } 35 35 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Subsumption/ActionSetSubsumptionOperator.cs
r9106 r9110 31 31 [Item("ActionSetSubsumptionoperator", "Description missing")] 32 32 [StorableClass] 33 public class ActionSetSubsumption operator : SingleSuccessorOperator, IActionSetSubsumption {33 public class ActionSetSubsumptionOperator : SingleSuccessorOperator, IActionSetSubsumption { 34 34 35 35 #region Parameter Properties … … 46 46 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Errors"]; } 47 47 } 48 public ILookupParameter<ItemArray<BoolValue>> HasBeenSubsumedParameter { 49 get { return (ILookupParameter<ItemArray<BoolValue>>)Parameters["HasBeenSubsumed"]; } 50 } 48 51 public ILookupParameter<DoubleValue> ErrorZeroParameter { 49 52 get { return (ILookupParameter<DoubleValue>)Parameters["ErrorZero"]; } … … 52 55 get { return (ILookupParameter<IntValue>)Parameters["ThetaSubsumption"]; } 53 56 } 54 protected ScopeParameter CurrentScopeParameter {55 get { return (ScopeParameter)Parameters["CurrentScope"]; }56 }57 public IScope CurrentScope {58 get { return CurrentScopeParameter.ActualValue; }59 }60 61 public string HasBeenSubsumedParameterName {62 get { return "HasBeenSubsumed"; }63 }64 57 #endregion 65 58 66 59 [StorableConstructor] 67 protected ActionSetSubsumption operator(bool deserializing) : base(deserializing) { }68 protected ActionSetSubsumption operator(ActionSetSubsumptionoperator original, Cloner cloner)60 protected ActionSetSubsumptionOperator(bool deserializing) : base(deserializing) { } 61 protected ActionSetSubsumptionOperator(ActionSetSubsumptionOperator original, Cloner cloner) 69 62 : base(original, cloner) { 70 63 } 71 public ActionSetSubsumption operator()64 public ActionSetSubsumptionOperator() 72 65 : base() { 73 66 Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers")); … … 75 68 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Experiences")); 76 69 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Errors")); 70 Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("HasBeenSubsumed")); 77 71 Parameters.Add(new LookupParameter<DoubleValue>("ErrorZero")); 78 72 Parameters.Add(new LookupParameter<IntValue>("ThetaSubsumption")); 79 Parameters.Add(new ScopeParameter("CurrentScope"));80 73 } 81 74 public override IDeepCloneable Clone(Cloner cloner) { 82 return new ActionSetSubsumption operator(this, cloner);75 return new ActionSetSubsumptionOperator(this, cloner); 83 76 } 84 77 85 78 public override IOperation Apply() { 86 var subscopes = CurrentScope.SubScopes;87 79 var classifiers = ClassifiersParameter.ActualValue; 88 80 var numerosities = NumerositiesParameter.ActualValue; 89 81 var experiences = ExperiencesParameter.ActualValue; 82 var hasBeenSubsumed = HasBeenSubsumedParameter.ActualValue; 90 83 var errors = ErrorsParameter.ActualValue; 91 if ( subscopes.Count != classifiers.Length || subscopes.Count!= numerosities.Length92 || subscopes.Count != experiences.Length || subscopes.Count != errors.Length) {93 throw new ArgumentException("The number of subscopes is not equal to the number of classifiers.");84 if (errors.Length != classifiers.Length || errors.Length != numerosities.Length 85 || errors.Length != experiences.Length || errors.Length != hasBeenSubsumed.Length) { 86 throw new ArgumentException("The number of classifiers, error, numerosity, hasBeenSubsumed and experience values is not equal."); 94 87 } 95 88 … … 108 101 if (classifiers[subsumptionClassifier].IsMoreGeneral(classifiers[i])) { 109 102 numerosities[subsumptionClassifier].Value += numerosities[i].Value; 110 AddVariableToScope(subscopes[i], new BoolValue(true)); 111 } else { 112 AddVariableToScope(subscopes[i], new BoolValue(false)); 103 hasBeenSubsumed[i].Value = true; 113 104 } 114 }115 } else {116 for (int i = 0; i < classifiers.Length; i++) {117 AddVariableToScope(subscopes[i], new BoolValue(false));118 105 } 119 106 } 120 107 121 108 return base.Apply(); 122 }123 124 private void AddVariableToScope(IScope scope, BoolValue boolValue) {125 if (scope.Variables.ContainsKey(HasBeenSubsumedParameterName)) {126 scope.Variables[HasBeenSubsumedParameterName].Value = boolValue;127 } else {128 scope.Variables.Add(new Variable(HasBeenSubsumedParameterName, boolValue));129 }130 109 } 131 110 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Subsumption/IActionSetSubsumption.cs
r9105 r9110 31 31 ILookupParameter<ItemArray<IntValue>> ExperiencesParameter { get; } 32 32 ILookupParameter<ItemArray<DoubleValue>> ErrorsParameter { get; } 33 ILookupParameter<ItemArray<BoolValue>> HasBeenSubsumedParameter { get; } 33 34 ILookupParameter<DoubleValue> ErrorZeroParameter { get; } 34 35 ILookupParameter<IntValue> ThetaSubsumptionParameter { get; } 35 36 string HasBeenSubsumedParameterName { get; }37 36 } 38 37 }
Note: See TracChangeset
for help on using the changeset viewer.