Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10764 was 5275, checked in by gkronber, 14 years ago

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

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