Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12744


Ignore:
Timestamp:
07/12/15 11:01:59 (9 years ago)
Author:
gkronber
Message:

#2359: added after-deserialization code for backwards-compatibility

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs

    r12720 r12744  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4748      Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
    4849    }
     50
     51    [StorableHook(HookType.AfterDeserialization)]
     52    private void AfterDeserialization() {
     53      // BackwardsCompatibility3.3
     54
     55      #region Backwards compatible code, remove with 3.4
     56      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
     57        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
     58        if (oldParam != null) {
     59          Parameters.Remove(oldParam);
     60          Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
     61        }
     62      } else {
     63        // not yet contained
     64        Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
     65      }
     66
     67      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
     68        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
     69        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
     70      }
     71      if (Parameters.ContainsKey("ImpactThreshold")) {
     72        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
     73        Parameters.Remove(Parameters["ImpactThreshold"]);
     74      }
     75      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
     76        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
     77        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
     78      }
     79      #endregion
     80    }
    4981  }
    5082}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs

    r12720 r12744  
    6161    }
    6262
     63    [StorableHook(HookType.AfterDeserialization)]
     64    private void AfterDeserialization() {
     65      // BackwardsCompatibility3.3
     66      #region Backwards compatible code, remove with 3.4
     67      base.ImpactValuesCalculator = new SymbolicClassificationSolutionImpactValuesCalculator();
     68      if (!Parameters.ContainsKey(EvaluatorParameterName)) {
     69        Parameters.Add(new LookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>(EvaluatorParameterName));
     70      }
     71      #endregion
     72    }
     73
    6374    protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    6475      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs

    r12358 r12744  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4950      Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
    5051    }
     52
     53    [StorableHook(HookType.AfterDeserialization)]
     54    private void AfterDeserialization() {
     55      // BackwardsCompatibility3.3
     56
     57      #region Backwards compatible code, remove with 3.4
     58      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
     59        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
     60        if (oldParam != null) {
     61          Parameters.Remove(oldParam);
     62          Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     63        }
     64      } else {
     65        // not yet contained
     66        Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     67      }
     68
     69
     70      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
     71        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
     72        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
     73      }
     74      if (Parameters.ContainsKey("ImpactThreshold")) {
     75        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
     76        Parameters.Remove(Parameters["ImpactThreshold"]);
     77      }
     78      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
     79        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
     80        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
     81      }
     82
     83      #endregion
     84    }
    5185  }
    5286}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r12720 r12744  
    5757    }
    5858
     59    [StorableHook(HookType.AfterDeserialization)]
     60    private void AfterDeserialization() {
     61      // BackwardsCompatibility3.3
     62      #region Backwards compatible code, remove with 3.4
     63      base.ImpactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
     64      if (!Parameters.ContainsKey(EvaluatorParameterName)) {
     65        Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
     66      }
     67      #endregion
     68    }
     69
    5970    protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    6071      return new SymbolicRegressionModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r12720 r12744  
    133133    }
    134134
     135    [StorableHook(HookType.AfterDeserialization)]
     136    private void AfterDeserialization() {
     137      // BackwardsCompatibility3.3
     138      #region Backwards compatible code, remove with 3.4
     139      if (!Parameters.ContainsKey(PrunedNodesParameterName)) {
     140        Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned."));
     141      }
     142      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     143        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
     144      }
     145      if (!Parameters.ContainsKey(ImpactValuesCalculatorParameterName)) {
     146        // value must be set by derived operators (regression/classification)
     147        Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName));
     148      }
     149      #endregion
     150    }
     151
    135152    protected abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits);
    136153
Note: See TracChangeset for help on using the changeset viewer.