Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/TestProblems/oesr-alps-master/HeuristicLab.Algorithms.OESRALPS/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredSlidingWindowEvaluator.cs @ 17479

Last change on this file since 17479 was 17479, checked in by kyang, 4 years ago

#3057

  1. upload the latest version of ALPS with SMS-EMOA
  2. upload the related dynamic test problems (dynamic, single-objective symbolic regression), written by David Daninel.
File size: 4.1 KB
Line 
1using HEAL.Attic;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Parameters;
6using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
7using HeuristicLab.Random;
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using System.Threading.Tasks;
13
14namespace 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}
Note: See TracBrowser for help on using the repository browser.