1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Parameters;
|
---|
6 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
7 | using HeuristicLab.Random;
|
---|
8 | using System;
|
---|
9 | using System.Collections.Generic;
|
---|
10 | using System.Linq;
|
---|
11 | using System.Text;
|
---|
12 | using System.Threading.Tasks;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Algorithms.OESRALPS.Evaluators
|
---|
15 | {
|
---|
16 | [Item("Sliding Window Pearson R² Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")]
|
---|
17 | [StorableType("6FAEC6C2-C711-452A-A60D-29AE37898A90")]
|
---|
18 | public class SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator : SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator
|
---|
19 | {
|
---|
20 | private const string TestPartitionParameterName = "TestPartition";
|
---|
21 | private const string TrainingPartitionParameterName = "TrainingPartition";
|
---|
22 |
|
---|
23 | public ILookupParameter<IntRange> TrainingPartitionParameter {
|
---|
24 | get { return (ILookupParameter<IntRange>)Parameters[TrainingPartitionParameterName]; }
|
---|
25 | }
|
---|
26 | public ILookupParameter<IntRange> TestPartitionParameter {
|
---|
27 | get { return (ILookupParameter<IntRange>)Parameters[TestPartitionParameterName]; }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [StorableConstructor]
|
---|
31 | protected SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator(StorableConstructorFlag _) : base(_) { }
|
---|
32 | protected SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator(SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator original, Cloner cloner)
|
---|
33 | : base(original, cloner)
|
---|
34 | {
|
---|
35 | }
|
---|
36 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
37 | {
|
---|
38 | return new SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator(this, cloner);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator() : base()
|
---|
42 | {
|
---|
43 | Parameters.Add(new ValueLookupParameter<IntRange>(TrainingPartitionParameterName, "The current training sliding window position or range."));
|
---|
44 | Parameters.Add(new ValueLookupParameter<IntRange>(TestPartitionParameterName, "The current test sliding window position or range."));
|
---|
45 | }
|
---|
46 |
|
---|
47 | //protected override IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows)
|
---|
48 | //{
|
---|
49 | // if (TrainingPartitionParameter.ActualValue == null
|
---|
50 | // || TestPartitionParameter.ActualValue == null)
|
---|
51 | // return base.GenerateRowsToEvaluate(percentageOfRows);
|
---|
52 |
|
---|
53 | // IEnumerable<int> rows;
|
---|
54 | // int samplesStart = TrainingPartitionParameter.ActualValue.Start;
|
---|
55 | // int samplesEnd = TrainingPartitionParameter.ActualValue.End;
|
---|
56 | // int testPartitionStart = TestPartitionParameter.ActualValue.Start;
|
---|
57 | // int testPartitionEnd = TestPartitionParameter.ActualValue.End;
|
---|
58 | // if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
|
---|
59 |
|
---|
60 | // if (percentageOfRows.IsAlmost(1.0))
|
---|
61 | // rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
|
---|
62 | // else
|
---|
63 | // {
|
---|
64 | // int seed = RandomParameter.ActualValue.Next();
|
---|
65 | // int count = (int)((samplesEnd - samplesStart) * percentageOfRows);
|
---|
66 | // if (count == 0) count = 1;
|
---|
67 | // rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count);
|
---|
68 | // }
|
---|
69 |
|
---|
70 | // rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
|
---|
71 | // if (ValidRowIndicatorParameter.ActualValue != null)
|
---|
72 | // {
|
---|
73 | // string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value;
|
---|
74 | // var problemData = ProblemDataParameter.ActualValue;
|
---|
75 | // var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar);
|
---|
76 | // rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0));
|
---|
77 | // }
|
---|
78 | // return rows;
|
---|
79 | //}
|
---|
80 | }
|
---|
81 | }
|
---|