Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/15/13 11:18:06 (12 years ago)
Author:
sforsten
Message:

#1980:

  • added training and test partition to ConditionActionClassificationProblemData
  • ClassifierFetcher only uses training partition
Location:
branches/LearningClassifierSystems
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionModel.cs

    r9154 r9161  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Core;
    2324
     
    2728
    2829    int ClassifierCount { get; }
     30    IEnumerable<IClassifier> GetAction(IEnumerable<IClassifier> classifiers);
    2931    IClassifier GetAction(IClassifier classifier);
    3032  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Interfaces/IConditionActionProblemData.cs

    r9160 r9161  
    3434    IEnumerable<string> AllowedActionVariables { get; }
    3535
     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);
    3646    IClassifier FetchClassifier(int rowNumber);
    3747
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/Reinforcement/ClassifierFetcher.cs

    r9154 r9161  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    4445    #endregion
    4546
    46     public override IDeepCloneable Clone(Cloner cloner) {
    47       return new ClassifierFetcher(this, cloner);
     47    private IConditionActionProblemData ProblemData {
     48      get { return ProblemDataParameter.ActualValue; }
    4849    }
     50
    4951    protected ClassifierFetcher(ClassifierFetcher original, Cloner cloner)
    5052      : base(original, cloner) {
     
    5860      Parameters.Add(new LookupParameter<IntValue>("Iteration"));
    5961    }
     62    public override IDeepCloneable Clone(Cloner cloner) {
     63      return new ClassifierFetcher(this, cloner);
     64    }
    6065
    6166    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]);
    6571      return base.Apply();
    6672    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSModel.cs

    r9154 r9161  
    4949      this.name = ItemName;
    5050      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      }
    5157    }
    5258
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/XCSSolution.cs

    r9154 r9161  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3435    private const string ModelResultName = "Model";
    3536    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)";
    3739
    3840    public string Filename { get; set; }
    3941
    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; }
    4349    }
    4450
     
    8692      Add(new Result(ModelResultName, "The xcs model.", model));
    8793      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()));
    8996
    9097      problemData.Changed += new EventHandler(ProblemData_Changed);
     
    94101
    95102    private void RecalculateResults() {
    96       var originalClassifiers = 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) {
    106113      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();
    110118
    111119      while (originalEnumerator.MoveNext() && estimatedActionEnumerator.MoveNext()) {
     
    115123      }
    116124
    117       Accuracy = correctClassified / rows;
     125      return correctClassified / rows;
    118126    }
    119127
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/Implementation/ConditionActionClassificationProblemData.cs

    r9160 r9161  
    6464      get { return (IFixedValueParameter<IntMatrix>)Parameters["Bounds"]; }
    6565    }
     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    }
    6672    #endregion
    6773
     74    #region properties
    6875    public Dataset Dataset {
    6976      get { return DatasetParameter.Value; }
    7077    }
    71 
    7278    public ICheckedItemList<StringValue> ConditionVariables {
    7379      get { return ConditionVariablesParameter.Value; }
    7480    }
    75 
    7681    public ICheckedItemList<StringValue> ActionVariables {
    7782      get { return ActionVariablesParameter.Value; }
    7883    }
    79 
    8084    public IEnumerable<string> AllowedConditionVariables {
    8185      get { return ConditionVariables.CheckedItems.Select(x => x.Value.Value); }
     
    8488      get { return ActionVariables.CheckedItems.Select(x => x.Value.Value); }
    8589    }
     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
    86118
    87119    private IDictionary<int, IClassifier> fetchClassifiersCache = new Dictionary<int, IClassifier>();
     
    113145        conditionVariables.SetItemCheckedState(x, allowedConditionVariables.Contains(x.Value));
    114146      }
     147
     148      int trainingPartitionStart = 0;
     149      int trainingPartitionEnd = dataset.Rows / 2;
     150      int testPartitionStart = dataset.Rows / 2;
     151      int testPartitionEnd = dataset.Rows;
    115152
    116153      Parameters.Add(new FixedValueParameter<Dataset>("Dataset", "", dataset));
     
    120157      Parameters.Add(new FixedValueParameter<IntValue>("ActionLength", "", new IntValue(allowedActionVariables.Count())));
    121158      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)));
    122161
    123162      ((ValueParameter<Dataset>)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
     
    158197    public IntMatrix Bounds {
    159198      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      }
    160205    }
    161206
  • branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3

    • Property svn:ignore
      •  

        old new  
        11*.user
         2obj
         3Plugin.cs
  • branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3/Properties

    • Property svn:ignore set to
      AssemblyInfo.cs
  • branches/LearningClassifierSystems/HeuristicLab.Problems.XCS.Views/3.3

    • Property svn:ignore
      •  

        old new  
        11Plugin.cs
        22*.user
         3obj
Note: See TracChangeset for help on using the changeset viewer.