Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicVectorRegressionEvaluator.cs @ 4752

Last change on this file since 4752 was 4401, checked in by gkronber, 14 years ago

Added model and solution classes for time series prognosis and added views for time series prognosis solutions. #1142

File size: 7.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Problems.DataAnalysis.Regression;
32using HeuristicLab.Problems.DataAnalysis.Symbolic;
33
34namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Evaluators {
35  [StorableClass]
36  public abstract class SymbolicVectorRegressionEvaluator : SingleSuccessorOperator, IMultiVariateDataAnalysisEvaluator {
37    private const string RandomParameterName = "Random";
38    private const string MultiVariateDataAnalysisProblemDataParameterName = "MultiVariateDataAnalysisProblemData";
39    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
40    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
41    private const string SamplesStartParameterName = "SamplesStart";
42    private const string SamplesEndParameterName = "SamplesEnd";
43    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
44    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
45    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
46
47    #region parameter properties
48    public ILookupParameter<IRandom> RandomParameter {
49      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
50    }
51    public ILookupParameter<MultiVariateDataAnalysisProblemData> MultiVariateDataAnalysisProblemDataParameter {
52      get { return (ILookupParameter<MultiVariateDataAnalysisProblemData>)Parameters[MultiVariateDataAnalysisProblemDataParameterName]; }
53    }
54    public IValueLookupParameter<IntValue> SamplesStartParameter {
55      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
56    }
57    public IValueLookupParameter<IntValue> SamplesEndParameter {
58      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
59    }
60    public IValueLookupParameter<DoubleArray> LowerEstimationLimitParameter {
61      get { return (IValueLookupParameter<DoubleArray>)Parameters[LowerEstimationLimitParameterName]; }
62    }
63    public IValueLookupParameter<DoubleArray> UpperEstimationLimitParameter {
64      get { return (IValueLookupParameter<DoubleArray>)Parameters[UpperEstimationLimitParameterName]; }
65    }
66    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
67      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
68    }
69    public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
70      get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
71    }
72    public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
73      get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
74    }
75
76    #endregion
77    #region properties
78    public IRandom Random {
79      get { return RandomParameter.ActualValue; }
80    }
81    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
82      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
83    }
84    public SymbolicExpressionTree SymbolicExpressionTree {
85      get { return SymbolicExpressionTreeParameter.ActualValue; }
86    }
87    public MultiVariateDataAnalysisProblemData MultiVariateDataAnalysisProblemData {
88      get { return MultiVariateDataAnalysisProblemDataParameter.ActualValue; }
89    }
90    public IntValue SamplesStart {
91      get { return SamplesStartParameter.ActualValue; }
92    }
93    public IntValue SamplesEnd {
94      get { return SamplesEndParameter.ActualValue; }
95    }
96    public DoubleArray LowerEstimationLimit {
97      get { return LowerEstimationLimitParameter.ActualValue; }
98    }
99    public DoubleArray UpperEstimationLimit {
100      get { return UpperEstimationLimitParameter.ActualValue; }
101    }
102    public PercentValue RelativeNumberOfEvaluatedSamples {
103      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
104    }
105    #endregion
106
107    public SymbolicVectorRegressionEvaluator(bool deserializing) : base(deserializing) { }
108    public SymbolicVectorRegressionEvaluator()
109      : base() {
110      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "A random number generator."));
111      Parameters.Add(new LookupParameter<MultiVariateDataAnalysisProblemData>(MultiVariateDataAnalysisProblemDataParameterName, "The multi-variate data analysis problem data to use for training."));
112      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The tree interpreter that should be used to evaluate the symbolic expression tree."));
113      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition to use for training."));
114      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The last index of the data set partition to use for training."));
115      Parameters.Add(new ValueLookupParameter<DoubleArray>(UpperEstimationLimitParameterName, "The upper limit for the estimated values for each component."));
116      Parameters.Add(new ValueLookupParameter<DoubleArray>(LowerEstimationLimitParameterName, "The lower limit for the estimated values for each component."));
117      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic vector regression solution encoded as a symbolic expression tree."));
118      Parameters.Add(new ValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.", new PercentValue(1)));
119    }
120
121    public static IEnumerable<int> GenerateRowsToEvaluate(int seed, double relativeAmount, int start, int end) {
122      if (end < start) throw new ArgumentException("Start value is larger than end value.");
123      int count = (int)((end - start) * relativeAmount);
124      if (count == 0) count = 1;
125      return RandomEnumerable.SampleRandomNumbers(seed, start, end, count);
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.