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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.