Changeset 9161
- Timestamp:
- 01/15/13 11:18:06 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionModel.cs
r9154 r9161 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Core; 23 24 … … 27 28 28 29 int ClassifierCount { get; } 30 IEnumerable<IClassifier> GetAction(IEnumerable<IClassifier> classifiers); 29 31 IClassifier GetAction(IClassifier classifier); 30 32 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblemData.cs
r9160 r9161 34 34 IEnumerable<string> AllowedActionVariables { get; } 35 35 36 IntRange TrainingPartition { get; } 37 IntRange TestPartition { get; } 38 39 IEnumerable<int> TrainingIndices { get; } 40 IEnumerable<int> TestIndices { get; } 41 42 bool IsTrainingSample(int index); 43 bool IsTestSample(int index); 44 45 IEnumerable<IClassifier> FetchClassifier(IEnumerable<int> rows); 36 46 IClassifier FetchClassifier(int rowNumber); 37 47 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/ClassifierFetcher.cs
r9154 r9161 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 44 45 #endregion 45 46 46 p ublic override IDeepCloneable Clone(Cloner cloner){47 return new ClassifierFetcher(this, cloner);47 private IConditionActionProblemData ProblemData { 48 get { return ProblemDataParameter.ActualValue; } 48 49 } 50 49 51 protected ClassifierFetcher(ClassifierFetcher original, Cloner cloner) 50 52 : base(original, cloner) { … … 58 60 Parameters.Add(new LookupParameter<IntValue>("Iteration")); 59 61 } 62 public override IDeepCloneable Clone(Cloner cloner) { 63 return new ClassifierFetcher(this, cloner); 64 } 60 65 61 66 public override IOperation Apply() { 62 Dataset dataset = ProblemDataParameter.ActualValue.Dataset; 63 int row = IterationParameter.ActualValue.Value % dataset.Rows; 64 CurrentClassifierToMatchParameter.ActualValue = ProblemDataParameter.ActualValue.FetchClassifier(row); 67 Dataset dataset = ProblemData.Dataset; 68 var trainingIndices = ProblemData.TrainingIndices.ToList(); 69 int index = IterationParameter.ActualValue.Value % trainingIndices.Count; 70 CurrentClassifierToMatchParameter.ActualValue = ProblemDataParameter.ActualValue.FetchClassifier(trainingIndices[index]); 65 71 return base.Apply(); 66 72 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSModel.cs
r9154 r9161 49 49 this.name = ItemName; 50 50 this.description = ItemDescription; 51 } 52 53 public IEnumerable<IClassifier> GetAction(IEnumerable<IClassifier> classifiers) { 54 foreach (var classifier in classifiers) { 55 yield return GetAction(classifier); 56 } 51 57 } 52 58 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSSolution.cs
r9154 r9161 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 34 35 private const string ModelResultName = "Model"; 35 36 private const string ProblemDataResultName = "ProblemData"; 36 private const string AccuracyResultName = "Accuracy"; 37 private const string TrainingAccuracyResultName = "Accuracy (training)"; 38 private const string TestAccuracyResultName = "Accuracy (test)"; 37 39 38 40 public string Filename { get; set; } 39 41 40 public double Accuracy { 41 get { return ((DoubleValue)this[AccuracyResultName].Value).Value; } 42 private set { ((DoubleValue)this[AccuracyResultName].Value).Value = value; } 42 public double TrainingAccuracy { 43 get { return ((DoubleValue)this[TrainingAccuracyResultName].Value).Value; } 44 private set { ((DoubleValue)this[TrainingAccuracyResultName].Value).Value = value; } 45 } 46 public double TestAccuracy { 47 get { return ((DoubleValue)this[TestAccuracyResultName].Value).Value; } 48 private set { ((DoubleValue)this[TestAccuracyResultName].Value).Value = value; } 43 49 } 44 50 … … 86 92 Add(new Result(ModelResultName, "The xcs model.", model)); 87 93 Add(new Result(ProblemDataResultName, "The condition-action problem data.", problemData)); 88 Add(new Result(AccuracyResultName, "Accuracy of the model (percentage of correctly classified instances).", new PercentValue())); 94 Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue())); 95 Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue())); 89 96 90 97 problemData.Changed += new EventHandler(ProblemData_Changed); … … 94 101 95 102 private void RecalculateResults() { 96 var original Classifiers = new List<IClassifier>();97 for (int i = 0; i < ProblemData.Dataset.Rows; i++) {98 originalClassifiers.Add(ProblemData.FetchClassifier(i));99 }100 101 var estimatedAction = new List<IClassifier>();102 foreach (var original in originalClassifiers) {103 estimatedAction.Add(Model.GetAction(original));104 } 105 103 var originalTrainingClassifer = ProblemData.FetchClassifier(ProblemData.TrainingIndices); 104 var originalTestClassifer = ProblemData.FetchClassifier(ProblemData.TestIndices); 105 var estimatedTrainingClassifier = Model.GetAction(originalTrainingClassifer); 106 var estimatedTestClassifier = Model.GetAction(originalTestClassifer); 107 108 TrainingAccuracy = CalculateAccuracy(originalTrainingClassifer, estimatedTrainingClassifier); 109 TestAccuracy = CalculateAccuracy(originalTestClassifer, estimatedTestClassifier); 110 } 111 112 private double CalculateAccuracy(IEnumerable<IClassifier> original, IEnumerable<IClassifier> estimated) { 106 113 double correctClassified = 0; 107 double rows = ProblemData.Dataset.Rows; 108 var originalEnumerator = originalClassifiers.GetEnumerator(); 109 var estimatedActionEnumerator = estimatedAction.GetEnumerator(); 114 115 double rows = original.Count(); 116 var originalEnumerator = original.GetEnumerator(); 117 var estimatedActionEnumerator = estimated.GetEnumerator(); 110 118 111 119 while (originalEnumerator.MoveNext() && estimatedActionEnumerator.MoveNext()) { … … 115 123 } 116 124 117 Accuracy =correctClassified / rows;125 return correctClassified / rows; 118 126 } 119 127 -
branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Implementation/ConditionActionClassificationProblemData.cs
r9160 r9161 64 64 get { return (IFixedValueParameter<IntMatrix>)Parameters["Bounds"]; } 65 65 } 66 public IFixedValueParameter<IntRange> TrainingPartitionParameter { 67 get { return (IFixedValueParameter<IntRange>)Parameters["TrainingPartition"]; } 68 } 69 public IFixedValueParameter<IntRange> TestPartitionParameter { 70 get { return (IFixedValueParameter<IntRange>)Parameters["TestPartition"]; } 71 } 66 72 #endregion 67 73 74 #region properties 68 75 public Dataset Dataset { 69 76 get { return DatasetParameter.Value; } 70 77 } 71 72 78 public ICheckedItemList<StringValue> ConditionVariables { 73 79 get { return ConditionVariablesParameter.Value; } 74 80 } 75 76 81 public ICheckedItemList<StringValue> ActionVariables { 77 82 get { return ActionVariablesParameter.Value; } 78 83 } 79 80 84 public IEnumerable<string> AllowedConditionVariables { 81 85 get { return ConditionVariables.CheckedItems.Select(x => x.Value.Value); } … … 84 88 get { return ActionVariables.CheckedItems.Select(x => x.Value.Value); } 85 89 } 90 public IntRange TrainingPartition { 91 get { return TrainingPartitionParameter.Value; } 92 } 93 public IntRange TestPartition { 94 get { return TestPartitionParameter.Value; } 95 } 96 public IEnumerable<int> TrainingIndices { 97 get { 98 return Enumerable.Range(TrainingPartition.Start, Math.Max(0, TrainingPartition.End - TrainingPartition.Start)) 99 .Where(IsTrainingSample); 100 } 101 } 102 public IEnumerable<int> TestIndices { 103 get { 104 return Enumerable.Range(TestPartition.Start, Math.Max(0, TestPartition.End - TestPartition.Start)) 105 .Where(IsTestSample); 106 } 107 } 108 public bool IsTrainingSample(int index) { 109 return index >= 0 && index < Dataset.Rows && 110 TrainingPartition.Start <= index && index < TrainingPartition.End && 111 (index < TestPartition.Start || TestPartition.End <= index); 112 } 113 public bool IsTestSample(int index) { 114 return index >= 0 && index < Dataset.Rows && 115 TestPartition.Start <= index && index < TestPartition.End; 116 } 117 #endregion 86 118 87 119 private IDictionary<int, IClassifier> fetchClassifiersCache = new Dictionary<int, IClassifier>(); … … 113 145 conditionVariables.SetItemCheckedState(x, allowedConditionVariables.Contains(x.Value)); 114 146 } 147 148 int trainingPartitionStart = 0; 149 int trainingPartitionEnd = dataset.Rows / 2; 150 int testPartitionStart = dataset.Rows / 2; 151 int testPartitionEnd = dataset.Rows; 115 152 116 153 Parameters.Add(new FixedValueParameter<Dataset>("Dataset", "", dataset)); … … 120 157 Parameters.Add(new FixedValueParameter<IntValue>("ActionLength", "", new IntValue(allowedActionVariables.Count()))); 121 158 Parameters.Add(new FixedValueParameter<IntMatrix>("Bounds", "", GetBoundsMatrix(dataset, allowedConditionVariables, allowedActionVariables))); 159 Parameters.Add(new FixedValueParameter<IntRange>("TrainingPartition", "", new IntRange(trainingPartitionStart, trainingPartitionEnd))); 160 Parameters.Add(new FixedValueParameter<IntRange>("TestPartition", "", new IntRange(testPartitionStart, testPartitionEnd))); 122 161 123 162 ((ValueParameter<Dataset>)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false; … … 158 197 public IntMatrix Bounds { 159 198 get { return BoundsParameter.Value; } 199 } 200 201 public IEnumerable<IClassifier> FetchClassifier(IEnumerable<int> rows) { 202 foreach (var row in rows) { 203 yield return FetchClassifier(row); 204 } 160 205 } 161 206 -
branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3
- Property svn:ignore
-
old new 1 1 *.user 2 obj 3 Plugin.cs
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3/Properties
-
Property
svn:ignore
set to
AssemblyInfo.cs
-
Property
svn:ignore
set to
-
branches/LearningClassifierSystems/HeuristicLab.Problems.XCS.Views/3.3
- Property svn:ignore
-
old new 1 1 Plugin.cs 2 2 *.user 3 obj
-
- Property svn:ignore
Note: See TracChangeset
for help on using the changeset viewer.