Changeset 9194 for branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding
- Timestamp:
- 01/28/13 17:54:46 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3
- Files:
-
- 2 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/ActionSelection/ActionSelector.cs
r9089 r9194 37 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 38 } 39 public IValueLookupParameter<I Classifier> SelectedActionParameter {40 get { return (IValueLookupParameter<I Classifier>)Parameters["SelectedAction"]; }39 public IValueLookupParameter<IAction> SelectedActionParameter { 40 get { return (IValueLookupParameter<IAction>)Parameters["SelectedAction"]; } 41 41 } 42 public ILookupParameter<IItemDictionary<I Classifier, DoubleValue>> PredictionArrayParameter {43 get { return (ILookupParameter<IItemDictionary<I Classifier, DoubleValue>>)Parameters["PredictionArray"]; }42 public ILookupParameter<IItemDictionary<IAction, DoubleValue>> PredictionArrayParameter { 43 get { return (ILookupParameter<IItemDictionary<IAction, DoubleValue>>)Parameters["PredictionArray"]; } 44 44 } 45 45 public ILookupParameter<PercentValue> ExplorationProbabilityParameter { … … 55 55 : base() { 56 56 Parameters.Add(new LookupParameter<IRandom>("Random")); 57 Parameters.Add(new ValueLookupParameter<I Classifier>("SelectedAction", "Action, which has been selected."));58 Parameters.Add(new LookupParameter<IItemDictionary<I Classifier, DoubleValue>>("PredictionArray"));57 Parameters.Add(new ValueLookupParameter<IAction>("SelectedAction", "Action, which has been selected.")); 58 Parameters.Add(new LookupParameter<IItemDictionary<IAction, DoubleValue>>("PredictionArray")); 59 59 Parameters.Add(new LookupParameter<PercentValue>("ExplorationProbability")); 60 60 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/ActionSelection/MaxValueActionSelector.cs
r9089 r9194 36 36 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["ValueParameter"]; } 37 37 } 38 public ILookupParameter<IClassifierComparer> ClassifierComparerParameter { 39 get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; } 40 } 38 41 39 42 [StorableConstructor] … … 43 46 : base() { 44 47 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ValueParameter", "DoubleValue which will be summed up.")); 48 Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer")); 45 49 } 46 50 public override IDeepCloneable Clone(Cloner cloner) { … … 48 52 } 49 53 50 protected override I ClassifierSelectAction(List<IScope> scopes) {51 Dictionary<I Classifier, double> actionSet = new Dictionary<IClassifier, double>();54 protected override IAction SelectAction(List<IScope> scopes) { 55 Dictionary<IAction, double> actionSet = new Dictionary<IAction, double>(ClassifierComparerParameter.ActualValue); 52 56 for (int i = 0; i < MatchParameter.ActualValue.Length; i++) { 53 57 var action = MatchParameter.ActualValue[i].Action; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/ActionSelection/OldActionSelector.cs
r9089 r9194 38 38 get { return (ILookupParameter<ItemArray<IClassifier>>)Parameters["MatchParameter"]; } 39 39 } 40 public IValueLookupParameter<I Classifier> SelectedActionParameter {41 get { return (IValueLookupParameter<I Classifier>)Parameters["SelectedAction"]; }40 public IValueLookupParameter<IAction> SelectedActionParameter { 41 get { return (IValueLookupParameter<IAction>)Parameters["SelectedAction"]; } 42 42 } 43 43 … … 54 54 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which sub-scopes should be selected.")); 55 55 Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("MatchParameter", "The matching encoding contained in each sub-scope which is used for selection.")); 56 Parameters.Add(new ValueLookupParameter<I Classifier>("SelectedAction", "Action, which has been selected."));56 Parameters.Add(new ValueLookupParameter<IAction>("SelectedAction", "Action, which has been selected.")); 57 57 } 58 58 … … 63 63 } 64 64 65 protected abstract I ClassifierSelectAction(List<IScope> scopes);65 protected abstract IAction SelectAction(List<IScope> scopes); 66 66 } 67 67 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/ActionSelection/RandomActionSelector.cs
r9089 r9194 45 45 } 46 46 47 protected override I ClassifierSelectAction(List<IScope> scopes) {47 protected override IAction SelectAction(List<IScope> scopes) { 48 48 IRandom random = RandomParameter.ActualValue; 49 49 int index = random.Next(MatchParameter.ActualValue.Length); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Analyzer/XCSSolutionAnalyzer.cs
r9175 r9194 66 66 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 67 67 } 68 public ILookupParameter<IClassifierComparer> ClassifierComparerParameter { 69 get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; } 70 } 68 71 69 72 public ResultCollection Results { get { return ResultsParameter.ActualValue; } } … … 84 87 Parameters.Add(new LookupParameter<IConditionActionProblemData>("ProblemData", "")); 85 88 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the solution should be stored.")); 89 Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer")); 86 90 } 87 91 … … 105 109 106 110 XCSModel xcsModel = new XCSModel(xcsClassifiers); 107 111 xcsModel.ClassifierComparer = ClassifierComparerParameter.ActualValue; 108 112 UseCurrentXCSSolution(xcsModel.CreateConditionActionSolution(problemData)); 109 113 return base.Apply(); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/CoveringOperator.cs
r9110 r9194 35 35 36 36 #region Parameter Properties 37 public ILookupParameter<IItemSet<I Classifier>> ActionsInMatchSetParameter {38 get { return (ILookupParameter<IItemSet<I Classifier>>)Parameters["ActionsInMatchSet"]; }37 public ILookupParameter<IItemSet<IAction>> ActionsInMatchSetParameter { 38 get { return (ILookupParameter<IItemSet<IAction>>)Parameters["ActionsInMatchSet"]; } 39 39 } 40 public ILookupParameter<IItemSet<I Classifier>> PossibleActionsParameter {41 get { return (ILookupParameter<IItemSet<I Classifier>>)Parameters["PossibleActions"]; }40 public ILookupParameter<IItemSet<IAction>> PossibleActionsParameter { 41 get { return (ILookupParameter<IItemSet<IAction>>)Parameters["PossibleActions"]; } 42 42 } 43 43 public ILookupParameter<IntValue> MinimalNumberOfUniqueActionsParameter { … … 77 77 public CoveringOperator() 78 78 : base() { 79 Parameters.Add(new LookupParameter<IClassifier>("CoverClassifier")); 80 Parameters.Add(new LookupParameter<IItemSet<IClassifier>>("ActionsInMatchSet")); 81 Parameters.Add(new LookupParameter<IItemSet<IClassifier>>("PossibleActions")); 79 Parameters.Add(new LookupParameter<IItemSet<IAction>>("ActionsInMatchSet")); 80 Parameters.Add(new LookupParameter<IItemSet<IAction>>("PossibleActions")); 82 81 Parameters.Add(new LookupParameter<IntValue>("MinimalNumberOfUniqueActions")); 83 82 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator")); … … 95 94 bool parallel = ParallelParameter.ActualValue.Value; 96 95 97 IItemSet<I Classifier> clone = (IItemSet<IClassifier>)PossibleActionsParameter.ActualValue.Clone();96 IItemSet<IAction> clone = (IItemSet<IAction>)PossibleActionsParameter.ActualValue.Clone(); 98 97 clone.ExceptWith(ActionsInMatchSetParameter.ActualValue); 99 98 … … 116 115 VariableCreator variableCreator = new VariableCreator(); 117 116 int pos = RandomParameter.ActualValue.Next(clone.Count); 118 I Classifieraction = clone.ElementAt(pos);117 IAction action = clone.ElementAt(pos); 119 118 clone.Remove(action); 120 variableCreator.CollectedValues.Add(new ValueParameter<I Classifier>("Action", action));119 variableCreator.CollectedValues.Add(new ValueParameter<IAction>("Action", action)); 121 120 variableCreation.Add(ExecutionContext.CreateOperation(variableCreator, CurrentScope.SubScopes[current + i])); 122 121 creation.Add(ExecutionContext.CreateOperation(creator, CurrentScope.SubScopes[current + i])); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/DoDeletionBeforeCovering.cs
r9110 r9194 55 55 get { return (IValueLookupParameter<IntValue>)Parameters["NumberToDelete"]; } 56 56 } 57 public ILookupParameter<IClassifierComparer> ClassifierComparerParameter { 58 get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; } 59 } 57 60 #endregion 58 61 … … 71 74 Parameters.Add(new ValueLookupParameter<BoolValue>("DoDeletion")); 72 75 Parameters.Add(new ValueLookupParameter<IntValue>("NumberToDelete")); 76 Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer")); 73 77 } 74 78 public override IDeepCloneable Clone(Cloner cloner) { … … 77 81 78 82 public override IOperation Apply() { 79 IItemSet<I Classifier> uniqueActions = new ItemSet<IClassifier>();83 IItemSet<IAction> uniqueActions = new ItemSet<IAction>(ClassifierComparerParameter.ActualValue); 80 84 var classifiers = ClassifiersParameter.ActualValue; 81 85 var matchcondition = MatchConditionParameter.ActualValue; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/ICovering.cs
r9105 r9194 26 26 namespace HeuristicLab.Encodings.ConditionActionEncoding { 27 27 public interface ICovering : IStochasticOperator { 28 ILookupParameter<IItemSet<I Classifier>> ActionsInMatchSetParameter { get; }29 ILookupParameter<IItemSet<I Classifier>> PossibleActionsParameter { get; }28 ILookupParameter<IItemSet<IAction>> ActionsInMatchSetParameter { get; } 29 ILookupParameter<IItemSet<IAction>> PossibleActionsParameter { get; } 30 30 31 31 ILookupParameter<IntValue> MinimalNumberOfUniqueActionsParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Covering/ICoveringSolutionCreator.cs
r9090 r9194 28 28 namespace HeuristicLab.Encodings.ConditionActionEncoding { 29 29 public interface ICoveringSolutionCreator : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable, IStochasticOperator { 30 ILookupParameter<I Classifier> CoverClassifierParameter { get; }31 ILookupParameter<I Classifier> ActionParameter { get; }30 ILookupParameter<IInput> CoverInputParameter { get; } 31 ILookupParameter<IAction> ActionParameter { get; } 32 32 33 33 IValueLookupParameter<IClassifier> CreatedClassifierParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/GA/InsertInPopulationOperator.cs
r9110 r9194 86 86 IClassifier cl = classifiers[indices]; 87 87 for (int i = 0; i < classifiers.Length; i++) { 88 if (!hasToBeDeleted[i].Value && !insertInPopulation[i].Value && cl. Equals(classifiers[i])) {88 if (!hasToBeDeleted[i].Value && !insertInPopulation[i].Value && cl.Identical(classifiers[i])) { 89 89 numerosities[i].Value += numerosities[indices].Value; 90 90 hasToBeDeleted[indices].Value = true; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj
r9175 r9194 43 43 </Reference> 44 44 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 45 <Private>False</Private>46 </Reference>47 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">48 45 <Private>False</Private> 49 46 </Reference> … … 124 121 <Compile Include="Reinforcement\IActionExecuter.cs" /> 125 122 <Compile Include="Reinforcement\IClassifierFetcher.cs" /> 126 <Compile Include="Selectors\IMatchSelector.cs" />127 <Compile Include="Selectors\MatchSelector.cs" />128 123 <Compile Include="Selectors\PreservingRightReducer.cs" /> 129 124 <Compile Include="Subsumption\ActionSetSubsumptionOperator.cs" /> … … 140 135 <None Include="Plugin.cs.frame" /> 141 136 </ItemGroup> 142 <ItemGroup /> 137 <ItemGroup> 138 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 139 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> 140 <Name>HeuristicLab.Core-3.3</Name> 141 </ProjectReference> 142 </ItemGroup> 143 143 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 144 144 <PropertyGroup> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/IClassifier.cs
r9175 r9194 20 20 #endregion 21 21 22 using System ;22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 24 25 25 namespace HeuristicLab.Encodings.ConditionActionEncoding { 26 /// <summary> 27 /// IMatching is used in dictinoaries, therefore the methods "Equals" and "GetHashCode" have to be overriden 28 /// IEquatable<IMatching> should be implemented as well. 29 /// 30 /// This also helps to implement macroclassifiers later on 31 /// </summary> 32 public interface IClassifier : IItem, IEquatable<IClassifier> { 33 IClassifier Condition { get; } 34 IClassifier Action { get; } 35 bool MatchCondition(IClassifier target); 36 bool MatchAction(IClassifier target); 26 public interface IClassifier : IItem { 27 ICondition Condition { get; } 28 IAction Action { get; } 29 30 bool MatchInput(IInput target); 31 bool MatchAction(IAction target); 37 32 bool IsMoreGeneral(IClassifier target); 33 bool IsMoreGeneral(ICondition target); 38 34 39 //to use IMatching as key in a dictionary, Equals and GetHashCode have to be override. 40 //Also IEquatable<Class> should be implemented. 41 bool Equals(object obj); 42 int GetHashCode(); 35 bool Identical(IClassifier target); 43 36 } 37 38 public interface ICondition : IItem { 39 bool Match(IInput target); 40 } 41 42 public interface IAction : IItem { 43 bool Match(IAction target); 44 } 45 46 public interface IInput : IItem { } 47 48 public interface IClassifierComparer : IEqualityComparer<IAction>, IItem { } 44 49 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionModel.cs
r9161 r9194 28 28 29 29 int ClassifierCount { get; } 30 IEnumerable<I Classifier> GetAction(IEnumerable<IClassifier> classifiers);31 I Classifier GetAction(IClassifierclassifier);30 IEnumerable<IAction> GetAction(IEnumerable<IInput> classifiers); 31 IAction GetAction(IInput classifier); 32 32 } 33 33 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblem.cs
r9110 r9194 37 37 //IItemSet<IClassifier> PossibleActions { get; } 38 38 39 IParameter ClassifierComparerParameter { get; } 40 39 41 ICoveringSolutionCreator CoveringSolutionCreator { get; } 40 42 IParameter CoveringSolutionCreatorParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblemData.cs
r9161 r9194 43 43 bool IsTestSample(int index); 44 44 45 IEnumerable<IClassifier> FetchClassifier(IEnumerable<int> rows); 46 IClassifier FetchClassifier(int rowNumber); 45 IEnumerable<IInput> FetchInput(IEnumerable<int> rows); 46 IInput FetchInput(int rowNumber); 47 48 IEnumerable<IAction> FetchAction(IEnumerable<int> rows); 49 IAction FetchAction(int rowNumber); 47 50 48 51 event EventHandler Changed; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/CountNumberOfUniqueActions.cs
r9090 r9194 35 35 get { return (ILookupParameter<ItemArray<IClassifier>>)Parameters["Classifiers"]; } 36 36 } 37 public IValueLookupParameter<IItemSet<IClassifier>> UniqueActionsParameter { 38 get { return (IValueLookupParameter<IItemSet<IClassifier>>)Parameters["UniqueActions"]; } 37 public ILookupParameter<IClassifierComparer> ClassifierComparerParameter { 38 get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; } 39 } 40 public IValueLookupParameter<IItemSet<IAction>> UniqueActionsParameter { 41 get { return (IValueLookupParameter<IItemSet<IAction>>)Parameters["UniqueActions"]; } 39 42 } 40 43 public IValueLookupParameter<IntValue> NumberOfUniqueActionsParameter { … … 53 56 : base() { 54 57 Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("Classifiers")); 55 Parameters.Add(new ValueLookupParameter<IItemSet<IClassifier>>("UniqueActions")); 58 Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer")); 59 Parameters.Add(new ValueLookupParameter<IItemSet<IAction>>("UniqueActions")); 56 60 Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfUniqueActions")); 57 61 } 58 62 59 63 public override IOperation Apply() { 60 ItemSet<I Classifier> actions = new ItemSet<IClassifier>();64 ItemSet<IAction> actions = new ItemSet<IAction>(ClassifierComparerParameter.ActualValue); 61 65 foreach (var classifier in ClassifiersParameter.ActualValue) { 62 66 actions.Add(classifier.Action); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/MatchActionOperator.cs
r9089 r9194 34 34 get { return (ILookupParameter<BoolValue>)Parameters["MatchAction"]; } 35 35 } 36 public ILookupParameter<I Classifier> TargetMatchParameter {37 get { return (ILookupParameter<I Classifier>)Parameters["TargetMatchParameter"]; }36 public ILookupParameter<IAction> TargetMatchParameter { 37 get { return (ILookupParameter<IAction>)Parameters["TargetMatchParameter"]; } 38 38 } 39 39 public ILookupParameter<IClassifier> MatchParameter { … … 49 49 : base() { 50 50 Parameters.Add(new LookupParameter<BoolValue>("MatchAction", "True if the action matches.")); 51 Parameters.Add(new ValueLookupParameter<I Classifier>("TargetMatchParameter", "Target that has to be matched by the match parameter."));51 Parameters.Add(new ValueLookupParameter<IAction>("TargetMatchParameter", "Target that has to be matched by the match parameter.")); 52 52 Parameters.Add(new ValueLookupParameter<IClassifier>("MatchParameter", "The matching encoding contained in each sub-scope which is used for selection.")); 53 53 } … … 57 57 58 58 public override IOperation Apply() { 59 I Classifiertarget = TargetMatchParameter.ActualValue;59 IAction target = TargetMatchParameter.ActualValue; 60 60 IClassifier match = MatchParameter.ActualValue; 61 61 MatchActionParameter.ActualValue = new BoolValue(match.MatchAction(target)); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/MatchConditionOperator.cs
r9110 r9194 34 34 get { return (ILookupParameter<BoolValue>)Parameters["MatchCondition"]; } 35 35 } 36 public ILookupParameter<I Classifier> TargetMatchParameter {37 get { return (ILookupParameter<I Classifier>)Parameters["TargetMatchParameter"]; }36 public ILookupParameter<IInput> TargetMatchParameter { 37 get { return (ILookupParameter<IInput>)Parameters["TargetMatchParameter"]; } 38 38 } 39 39 public ILookupParameter<IClassifier> MatchParameter { … … 49 49 : base() { 50 50 Parameters.Add(new LookupParameter<BoolValue>("MatchCondition", "True if the condition matches.")); 51 Parameters.Add(new ValueLookupParameter<I Classifier>("TargetMatchParameter", "Target that has to be matched by the match parameter."));51 Parameters.Add(new ValueLookupParameter<IInput>("TargetMatchParameter", "Target that has to be matched by the match parameter.")); 52 52 Parameters.Add(new ValueLookupParameter<IClassifier>("MatchParameter", "The matching encoding contained in each sub-scope which is used for selection.")); 53 53 } … … 57 57 58 58 public override IOperation Apply() { 59 I Classifiertarget = TargetMatchParameter.ActualValue;59 IInput target = TargetMatchParameter.ActualValue; 60 60 IClassifier match = MatchParameter.ActualValue; 61 MatchConditionParameter.ActualValue = new BoolValue(match.Match Condition(target));61 MatchConditionParameter.ActualValue = new BoolValue(match.MatchInput(target)); 62 62 return base.Apply(); 63 63 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Operator/PredictionArrayCalculator.cs
r9089 r9194 33 33 public class PredictionArrayCalculator : SingleSuccessorOperator { 34 34 35 public ILookupParameter<IClassifierComparer> ClassifierComparerParameter { 36 get { return (ILookupParameter<IClassifierComparer>)Parameters["ClassifierComparer"]; } 37 } 35 38 public ILookupParameter<ItemArray<DoubleValue>> FitnessParameter { 36 39 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Fitness"]; } … … 39 42 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Prediction"]; } 40 43 } 41 public IValueParameter<IItemDictionary<I Classifier, DoubleValue>> PredictionArrayParameter {42 get { return (IValueParameter<IItemDictionary<I Classifier, DoubleValue>>)Parameters["PredictionArray"]; }44 public IValueParameter<IItemDictionary<IAction, DoubleValue>> PredictionArrayParameter { 45 get { return (IValueParameter<IItemDictionary<IAction, DoubleValue>>)Parameters["PredictionArray"]; } 43 46 } 44 47 public ILookupParameter<ItemArray<IClassifier>> MatchParameter { … … 53 56 public PredictionArrayCalculator() 54 57 : base() { 58 Parameters.Add(new LookupParameter<IClassifierComparer>("ClassifierComparer")); 55 59 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Fitness")); 56 60 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Prediction")); 57 Parameters.Add(new ValueLookupParameter<IItemDictionary<I Classifier, DoubleValue>>("PredictionArray"));61 Parameters.Add(new ValueLookupParameter<IItemDictionary<IAction, DoubleValue>>("PredictionArray")); 58 62 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which sub-scopes should be selected.")); 59 63 Parameters.Add(new ScopeTreeLookupParameter<IClassifier>("MatchParameter", "The matching encoding contained in each sub-scope which is used for selection.")); … … 64 68 65 69 public sealed override IOperation Apply() { 66 IItemDictionary<I Classifier, DoubleValue> predictionArray = new ItemDictionary<IClassifier, DoubleValue>();67 IDictionary<I Classifier, double> fitnessSumPerAction = new Dictionary<IClassifier, double>();70 IItemDictionary<IAction, DoubleValue> predictionArray = new ItemDictionary<IAction, DoubleValue>(ClassifierComparerParameter.ActualValue); 71 IDictionary<IAction, double> fitnessSumPerAction = new Dictionary<IAction, double>(ClassifierComparerParameter.ActualValue); 68 72 ItemArray<DoubleValue> fitnesses = FitnessParameter.ActualValue; 69 73 ItemArray<DoubleValue> predictions = PredictionParameter.ActualValue; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/ActionExecuter.cs
r9175 r9194 33 33 34 34 #region parameter 35 public IValueLookupParameter<I Classifier> SelectedActionParameter {36 get { return (IValueLookupParameter<I Classifier>)Parameters["SelectedAction"]; }35 public IValueLookupParameter<IAction> SelectedActionParameter { 36 get { return (IValueLookupParameter<IAction>)Parameters["SelectedAction"]; } 37 37 } 38 public IValueLookupParameter<I Classifier> CurrentClassifierToMatchParameter {39 get { return (IValueLookupParameter<I Classifier>)Parameters["CurrentClassifierToMatch"]; }38 public IValueLookupParameter<IAction> CurrentActionToMatchParameter { 39 get { return (IValueLookupParameter<IAction>)Parameters["CurrentActionToMatch"]; } 40 40 } 41 41 public IValueLookupParameter<DoubleValue> CurrentPayoffParameter { … … 61 61 public ActionExecuter() 62 62 : base() { 63 Parameters.Add(new ValueLookupParameter<I Classifier>("SelectedAction"));64 Parameters.Add(new ValueLookupParameter<I Classifier>("CurrentClassifierToMatch"));63 Parameters.Add(new ValueLookupParameter<IAction>("SelectedAction")); 64 Parameters.Add(new ValueLookupParameter<IAction>("CurrentActionToMatch")); 65 65 Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentPayoff")); 66 66 Parameters.Add(new ValueLookupParameter<DoubleValue>("NegativeReward")); … … 69 69 70 70 public override IOperation Apply() { 71 if (SelectedActionParameter.ActualValue.Match Action(CurrentClassifierToMatchParameter.ActualValue)) {71 if (SelectedActionParameter.ActualValue.Match(CurrentActionToMatchParameter.ActualValue)) { 72 72 CurrentPayoffParameter.ActualValue = PositiveRewardParameter.ActualValue; 73 73 } else { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/ClassifierFetcher.cs
r9161 r9194 33 33 [StorableClass] 34 34 public class ClassifierFetcher : SingleSuccessorOperator, IClassifierFetcher { 35 35 36 #region parameters 36 public IValueLookupParameter<IClassifier> CurrentClassifierToMatchParameter { 37 get { return (IValueLookupParameter<IClassifier>)Parameters["CurrentClassifierToMatch"]; } 37 public IValueLookupParameter<IInput> CurrentInputToMatchParameter { 38 get { return (IValueLookupParameter<IInput>)Parameters["CurrentConditionToMatch"]; } 39 } 40 public IValueLookupParameter<IAction> CurrentActionToMatchParameter { 41 get { return (IValueLookupParameter<IAction>)Parameters["CurrentActionToMatch"]; } 38 42 } 39 43 public ILookupParameter<IConditionActionProblemData> ProblemDataParameter { … … 56 60 public ClassifierFetcher() 57 61 : base() { 58 Parameters.Add(new ValueLookupParameter<IClassifier>("CurrentClassifierToMatch")); 62 Parameters.Add(new ValueLookupParameter<IInput>("CurrentConditionToMatch")); 63 Parameters.Add(new ValueLookupParameter<IAction>("CurrentActionToMatch")); 59 64 Parameters.Add(new LookupParameter<IConditionActionProblemData>("ProblemData")); 60 65 Parameters.Add(new LookupParameter<IntValue>("Iteration")); … … 68 73 var trainingIndices = ProblemData.TrainingIndices.ToList(); 69 74 int index = IterationParameter.ActualValue.Value % trainingIndices.Count; 70 CurrentClassifierToMatchParameter.ActualValue = ProblemDataParameter.ActualValue.FetchClassifier(trainingIndices[index]); 75 CurrentInputToMatchParameter.ActualValue = ProblemDataParameter.ActualValue.FetchInput(trainingIndices[index]); 76 CurrentActionToMatchParameter.ActualValue = ProblemDataParameter.ActualValue.FetchAction(trainingIndices[index]); 71 77 return base.Apply(); 72 78 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/IActionExecuter.cs
r9089 r9194 27 27 namespace HeuristicLab.Encodings.ConditionActionEncoding { 28 28 public interface IActionExecuter : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable { 29 IValueLookupParameter<I Classifier> SelectedActionParameter { get; }30 IValueLookupParameter<I Classifier> CurrentClassifierToMatchParameter { get; }29 IValueLookupParameter<IAction> SelectedActionParameter { get; } 30 IValueLookupParameter<IAction> CurrentActionToMatchParameter { get; } 31 31 IValueLookupParameter<DoubleValue> CurrentPayoffParameter { get; } 32 32 ILookupParameter<DoubleValue> NegativeRewardParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/IClassifierFetcher.cs
r9089 r9194 27 27 namespace HeuristicLab.Encodings.ConditionActionEncoding { 28 28 public interface IClassifierFetcher : IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable { 29 IValueLookupParameter<IClassifier> CurrentClassifierToMatchParameter { get; } 29 IValueLookupParameter<IInput> CurrentInputToMatchParameter { get; } 30 IValueLookupParameter<IAction> CurrentActionToMatchParameter { get; } 30 31 ILookupParameter<IConditionActionProblemData> ProblemDataParameter { get; } 31 32 ILookupParameter<IntValue> IterationParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Subsumption/CheckGASubsumptionOperator.cs
r9110 r9194 105 105 for (int i = 0; i < parents.Length; i++) { 106 106 IClassifier curParent = parents[i]; 107 if (curParent.MatchAction(child )) {107 if (curParent.MatchAction(child.Action)) { 108 108 if (CouldSubsume(experiences[i], errors[i])) { 109 109 if (curParent.IsMoreGeneral(child)) { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSModel.cs
r9161 r9194 34 34 public int ClassifierCount { get { return Count; } } 35 35 36 public IClassifierComparer ClassifierComparer { get; set; } 37 36 38 [StorableConstructor] 37 39 protected XCSModel(bool deserializing) : base(deserializing) { } … … 51 53 } 52 54 53 public IEnumerable<I Classifier> GetAction(IEnumerable<IClassifier> classifiers) {55 public IEnumerable<IAction> GetAction(IEnumerable<IInput> classifiers) { 54 56 foreach (var classifier in classifiers) { 55 57 yield return GetAction(classifier); … … 57 59 } 58 60 59 public I Classifier GetAction(IClassifierclassifier) {61 public IAction GetAction(IInput classifier) { 60 62 var matchedClassifiers = new ItemCollection<XCSClassifier>(); 61 63 foreach (var xcsClassifier in this) { 62 if (xcsClassifier.Classifier.Match Condition(classifier)) {64 if (xcsClassifier.Classifier.MatchInput(classifier)) { 63 65 matchedClassifiers.Add(xcsClassifier); 64 66 } … … 67 69 if (matchedClassifiers.Count == 0) { return null; } 68 70 69 IDictionary<I Classifier, double> predictionArray = CreatePredictionArray(matchedClassifiers);71 IDictionary<IAction, double> predictionArray = CreatePredictionArray(matchedClassifiers); 70 72 return predictionArray.OrderByDescending(x => x.Value).First().Key; 71 73 } 72 74 73 private IDictionary<I Classifier, double> CreatePredictionArray(ItemCollection<XCSClassifier> matchedClassifiers) {74 var predictionArray = new Dictionary<I Classifier, double>();75 var fitnessSumPerAction = new Dictionary<I Classifier, double>();75 private IDictionary<IAction, double> CreatePredictionArray(ItemCollection<XCSClassifier> matchedClassifiers) { 76 var predictionArray = new Dictionary<IAction, double>(ClassifierComparer); 77 var fitnessSumPerAction = new Dictionary<IAction, double>(ClassifierComparer); 76 78 77 79 foreach (var xcsClassifier in matchedClassifiers) { … … 86 88 } 87 89 88 var actions = new List<I Classifier>(predictionArray.Keys);90 var actions = new List<IAction>(predictionArray.Keys); 89 91 foreach (var action in actions) { 90 92 if (fitnessSumPerAction[action] != 0) { -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSSolution.cs
r9175 r9194 104 104 105 105 private void RecalculateResults() { 106 var originalTrainingClassifer = ProblemData.FetchClassifier(ProblemData.TrainingIndices); 107 var originalTestClassifer = ProblemData.FetchClassifier(ProblemData.TestIndices); 108 var estimatedTrainingClassifier = Model.GetAction(originalTrainingClassifer); 109 var estimatedTestClassifier = Model.GetAction(originalTestClassifer); 110 111 TrainingAccuracy = CalculateAccuracy(originalTrainingClassifer, estimatedTrainingClassifier); 112 TestAccuracy = CalculateAccuracy(originalTestClassifer, estimatedTestClassifier); 113 } 114 115 private double CalculateAccuracy(IEnumerable<IClassifier> original, IEnumerable<IClassifier> estimated) { 106 var originalTrainingCondition = ProblemData.FetchInput(ProblemData.TrainingIndices); 107 var originalTestCondition = ProblemData.FetchInput(ProblemData.TestIndices); 108 var estimatedTrainingClassifier = Model.GetAction(originalTrainingCondition); 109 var estimatedTestClassifier = Model.GetAction(originalTestCondition); 110 111 var originalTrainingAction = ProblemData.FetchAction(ProblemData.TrainingIndices); 112 var originalTestAction = ProblemData.FetchAction(ProblemData.TestIndices); 113 114 TrainingAccuracy = CalculateAccuracy(originalTrainingAction, estimatedTrainingClassifier); 115 TestAccuracy = CalculateAccuracy(originalTestAction, estimatedTestClassifier); 116 } 117 118 private double CalculateAccuracy(IEnumerable<IAction> original, IEnumerable<IAction> estimated) { 116 119 double correctClassified = 0; 117 120 … … 121 124 122 125 while (originalEnumerator.MoveNext() && estimatedActionEnumerator.MoveNext()) { 123 if (originalEnumerator.Current.Match Action(estimatedActionEnumerator.Current)) {126 if (originalEnumerator.Current.Match(estimatedActionEnumerator.Current)) { 124 127 correctClassified++; 125 128 }
Note: See TracChangeset
for help on using the changeset viewer.