Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Evaluator/DecisionListEvaluator.cs @ 9334

Last change on this file since 9334 was 9334, checked in by sforsten, 11 years ago

#1980:

  • added Algorithms.GAssist
  • adapted Problems.DecisionListClassification and Encodings.DecisionList
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.Random;
33
34namespace HeuristicLab.Encodings.DecisionList {
35  [Item("DecisionListEvaluator", "Description missing")]
36  [StorableClass]
37  public abstract class DecisionListEvaluator : SingleSuccessorOperator, IDecisionListEvaluator, IDecisionListOperator, IStochasticOperator {
38
39    #region Parameter Properties
40    public ILookupParameter<IRandom> RandomParameter {
41      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
42    }
43    public ILookupParameter<DecisionList> DecisionListParameter {
44      get { return (ILookupParameter<DecisionList>)Parameters["DecisionList"]; }
45    }
46    public IValueLookupParameter<IntRange> EvaluationPartitionParameter {
47      get { return (IValueLookupParameter<IntRange>)Parameters["EvaluationPartition"]; }
48    }
49    public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
50      get { return (IValueLookupParameter<PercentValue>)Parameters["RelativeNumberOfEvaluatedSamples"]; }
51    }
52    public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter {
53      get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; }
54    }
55    public IValueLookupParameter<IntValue> SizePenaltyMinRulesParameter {
56      get { return (IValueLookupParameter<IntValue>)Parameters["SizePenaltyMinRules"]; }
57    }
58    public ILookupParameter<DoubleValue> QualityParameter {
59      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
60    }
61    #endregion
62
63    [StorableConstructor]
64    protected DecisionListEvaluator(bool deserializing) : base(deserializing) { }
65    protected DecisionListEvaluator(DecisionListEvaluator original, Cloner cloner)
66      : base(original, cloner) {
67    }
68    public DecisionListEvaluator()
69      : base() {
70      Parameters.Add(new LookupParameter<IRandom>("Random", "The random generator to use."));
71      Parameters.Add(new LookupParameter<DecisionList>("DecisionList", ""));
72      Parameters.Add(new ValueLookupParameter<IntRange>("EvaluationPartition", ""));
73      Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeNumberOfEvaluatedSamples", ""));
74      Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", ""));
75      Parameters.Add(new ValueLookupParameter<IntValue>("SizePenaltyMinRules", ""));
76      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
77    }
78
79    protected IEnumerable<int> GenerateRowsToEvaluate() {
80      return GenerateRowsToEvaluate(RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);
81    }
82
83    protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
84      IEnumerable<int> rows;
85      int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
86      int samplesEnd = EvaluationPartitionParameter.ActualValue.End;
87      int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
88      int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
89      if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
90
91      if (percentageOfRows.IsAlmost(1.0))
92        rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
93      else {
94        int seed = RandomParameter.ActualValue.Next();
95        int count = (int)((samplesEnd - samplesStart) * percentageOfRows);
96        if (count == 0) count = 1;
97        rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count);
98      }
99
100      rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
101      return rows;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.