1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Problems.DataAnalysis;
|
---|
8 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
9 | using HeuristicLab.Random;
|
---|
10 | using System;
|
---|
11 | using System.Collections.Generic;
|
---|
12 | using System.Linq;
|
---|
13 | using System.Text;
|
---|
14 | using System.Threading.Tasks;
|
---|
15 |
|
---|
16 | namespace HeuristicLab.Algorithms.OESRALPS.Analyzers
|
---|
17 | {
|
---|
18 | [Item("SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer", "An operator that analyzes the validation best symbolic data analysis solution for single objective symbolic data analysis problems.")]
|
---|
19 | [StorableType("DD82C026-CF68-40D7-A798-77EA61272AA9")]
|
---|
20 | public abstract class SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer<T, U> : SymbolicDataAnalysisSingleObjectiveAnalyzer,
|
---|
21 | ISymbolicDataAnalysisValidationAnalyzer<T, U>, IStochasticOperator
|
---|
22 | where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
|
---|
23 | where U : class, IDataAnalysisProblemData
|
---|
24 | {
|
---|
25 | private const string RandomParameterName = "GlobalRandom";
|
---|
26 | private const string ProblemDataParameterName = "ProblemData";
|
---|
27 | private const string EvaluatorParameterName = "Evaluator";
|
---|
28 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
29 | private const string ValidationPartitionParameterName = "ValidationPartition";
|
---|
30 | private const string TestPartitionParameterName = "TestPartition";
|
---|
31 | private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
|
---|
32 | private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions";
|
---|
33 |
|
---|
34 | #region parameter properties
|
---|
35 | public ILookupParameter<IRandom> RandomParameter {
|
---|
36 | get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
|
---|
37 | }
|
---|
38 | public ILookupParameter<U> ProblemDataParameter {
|
---|
39 | get { return (ILookupParameter<U>)Parameters[ProblemDataParameterName]; }
|
---|
40 | }
|
---|
41 | public ILookupParameter<T> EvaluatorParameter {
|
---|
42 | get { return (ILookupParameter<T>)Parameters[EvaluatorParameterName]; }
|
---|
43 | }
|
---|
44 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
45 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
46 | }
|
---|
47 | public IValueLookupParameter<IntRange> ValidationPartitionParameter {
|
---|
48 | get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
|
---|
49 | }
|
---|
50 | public IValueLookupParameter<IntRange> TestPartitionParameter {
|
---|
51 | get { return (IValueLookupParameter<IntRange>)Parameters[TestPartitionParameterName]; }
|
---|
52 | }
|
---|
53 | public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
54 | get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
55 | }
|
---|
56 | public IValueLookupParameter<PercentValue> PercentageOfBestSolutionsParameter {
|
---|
57 | get { return (IValueLookupParameter<PercentValue>)Parameters[PercentageOfBestSolutionsParameterName]; }
|
---|
58 | }
|
---|
59 | #endregion
|
---|
60 |
|
---|
61 | [StorableConstructor]
|
---|
62 | protected SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
63 | protected SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer(SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer<T, U> original, Cloner cloner)
|
---|
64 | : base(original, cloner)
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected SymbolicDataAnalysisSingleObjectiveLayerValidationAnalyzer() : base()
|
---|
69 | {
|
---|
70 | Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator."));
|
---|
71 | Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem."));
|
---|
72 | Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition."));
|
---|
73 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees."));
|
---|
74 | Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
|
---|
75 | Parameters.Add(new ValueLookupParameter<IntRange>(TestPartitionParameterName, "The test partition."));
|
---|
76 | Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
|
---|
77 | Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName, "The percentage of the top solutions which should be analyzed.", new PercentValue(0.25)));
|
---|
78 | }
|
---|
79 |
|
---|
80 | protected virtual IEnumerable<int> GenerateRowsToEvaluate()
|
---|
81 | {
|
---|
82 | if (ValidationPartitionParameter.ActualValue == null)
|
---|
83 | return Enumerable.Empty<int>();
|
---|
84 |
|
---|
85 | int seed = RandomParameter.ActualValue.Next();
|
---|
86 | int samplesStart = ValidationPartitionParameter.ActualValue.Start;
|
---|
87 | int samplesEnd = ValidationPartitionParameter.ActualValue.End;
|
---|
88 | int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
|
---|
89 | int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
|
---|
90 |
|
---|
91 | if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
|
---|
92 | int count = (int)((samplesEnd - samplesStart) * RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);
|
---|
93 | if (count == 0) count = 1;
|
---|
94 | return RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count)
|
---|
95 | .Where(i => i < testPartitionStart && i < ProblemDataParameter.ActualValue.Dataset.Rows);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|