[12951] | 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 |
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 27 | using HeuristicLab.EvolutionTracking;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[12958] | 31 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[12951] | 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 | }
|
---|