Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs @ 12965

Last change on this file since 12965 was 12958, checked in by bburlacu, 9 years ago

#1772: Properly remove older generations in the genealogy graph. Fix namespaces in the schema diversification operators.

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.EvolutionTracking;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [Item("UpdateEstimatedValuesOperator", "Put the estimated values of the tree in the scope to be used by the phenotypic similarity calculator")]
33  [StorableClass]
34  public class UpdateEstimatedValuesOperator : EvolutionTrackingOperator<ISymbolicExpressionTree> {
35    private const string ProblemDataParameterName = "ProblemData";
36    private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
37    private const string EstimationLimitsParameterName = "EstimationLimits";
38    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
39
40    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
41      get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
42    }
43    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter {
44      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
45    }
46    public ILookupParameter<DoubleLimit> EstimationLimitsParameter {
47      get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
48    }
49    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
50      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
51    }
52
53    public UpdateEstimatedValuesOperator() {
54      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName));
55      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName));
56      Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName));
57      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName));
58    }
59
60    [StorableConstructor]
61    protected UpdateEstimatedValuesOperator(bool deserializing) : base(deserializing) { }
62
63    protected UpdateEstimatedValuesOperator(UpdateEstimatedValuesOperator original, Cloner cloner) : base(original, cloner) {
64    }
65
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new UpdateEstimatedValuesOperator(this, cloner);
68    }
69
70    public override IOperation Apply() {
71      var tree = SymbolicExpressionTreeParameter.ActualValue;
72      var problemData = ProblemDataParameter.ActualValue;
73      var estimationLimits = EstimationLimitsParameter.ActualValue;
74      var interpreter = InterpreterParameter.ActualValue;
75
76      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndices)
77                                       .LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
78
79      var variables = ExecutionContext.Scope.Variables;
80      if (variables.ContainsKey("EstimatedValues"))
81        variables["EstimatedValues"].Value = new DoubleArray(estimatedValues);
82      else
83        variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(estimatedValues)));
84      return base.Apply();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.