Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17751


Ignore:
Timestamp:
09/20/20 22:21:24 (4 years ago)
Author:
chaider
Message:

#3076 Added Splitting-Parameter

Location:
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs

    r17733 r17751  
    115115      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    116116      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
    117       if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error))
     117      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, false, out double error))
    118118      {
    119119        if (double.IsNaN(error) || double.IsInfinity(error))
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintEvaluator.cs

    r17750 r17751  
    11using System;
     2using System.CodeDom;
    23using System.Collections.Generic;
    34using System.Linq;
     
    2627    private const string PenaltyMultiplierParameterName = "Constraints Penalty Multiplier";
    2728
     29    private const string UseIntervalSplittingParameterName = "Use Interval Splitting";
     30
    2831    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter =>
    2932      (IFixedValueParameter<BoolValue>) Parameters[UseConstantOptimizationParameterName];
     
    3740    public IFixedValueParameter<DoubleValue> PenaltyMultiplierParameter =>
    3841      (IFixedValueParameter<DoubleValue>) Parameters[PenaltyMultiplierParameterName];
     42
     43    public IFixedValueParameter<BoolValue> UseIntervalSplittingParameter =>
     44      (IFixedValueParameter<BoolValue>) Parameters[UseIntervalSplittingParameterName];
    3945
    4046    public bool UseConstantOptimization {
     
    5662      get => PenaltyMultiplierParameter.Value.Value;
    5763      set => PenaltyMultiplierParameter.Value.Value = value;
     64    }
     65
     66    public bool UseIntervalSplitting {
     67      get => UseIntervalSplittingParameter.Value.Value;
     68      set => UseIntervalSplittingParameter.Value.Value = value;
    5869    }
    5970
     
    8091      Parameters.Add(new FixedValueParameter<DoubleValue>(PenaltyMultiplierParameterName,
    8192        "Specify how hard constraints violations should be punished", new DoubleValue(1.0)));
     93      Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName,
     94        "Define whether interval splitting is used or not.", new BoolValue(false)));
    8295    }
    8396
     
    103116          "Specify how hard constraints violations should be punished", new DoubleValue(1.0)));
    104117      }
     118
     119      if (!Parameters.ContainsKey(UseIntervalSplittingParameterName)) {
     120        Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName,
     121          "Define whether interval splitting is used or not.", new BoolValue(false)));
     122      }
    105123    }
    106124
     
    112130
    113131    public override IOperation InstrumentedApply() {
    114       var rows               = GenerateRowsToEvaluate();
    115       var solution           = SymbolicExpressionTreeParameter.ActualValue;
    116       var problemData        = ProblemDataParameter.ActualValue;
    117       var interpreter        = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    118       var estimationLimits   = EstimationLimitsParameter.ActualValue;
     132      var rows = GenerateRowsToEvaluate();
     133      var solution = SymbolicExpressionTreeParameter.ActualValue;
     134      var problemData = ProblemDataParameter.ActualValue;
     135      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     136      var estimationLimits = EstimationLimitsParameter.ActualValue;
    119137      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
    120138
     
    127145          //Check for interval arithmetic grammar
    128146          //remove scaling nodes for linear scaling evaluation
    129           var                    rootNode = new ProgramRootSymbol().CreateTreeNode();
    130           var                    startNode = new StartSymbol().CreateTreeNode();
    131           SymbolicExpressionTree newTree   = null;
     147          var rootNode = new ProgramRootSymbol().CreateTreeNode();
     148          var startNode = new StartSymbol().CreateTreeNode();
     149          SymbolicExpressionTree newTree = null;
    132150          foreach (var node in solution.IterateNodesPrefix())
    133151            if (node.Symbol.Name == "Scaling") {
     
    140158          //calculate alpha and beta for scaling
    141159          var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
    142           var targetValues    = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     160          var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    143161          OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
    144162            out var errorState);
     
    159177      var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows,
    160178        UseSoftConstraints,
    161         PenaltyMultiplier);
     179        PenaltyMultiplier, UseIntervalSplitting);
    162180      QualityParameter.ActualValue = new DoubleValue(quality);
    163181
     
    170188      double upperEstimationLimit,
    171189      IRegressionProblemData problemData, IEnumerable<int> rows, bool useSoftConstraints,
    172       double penaltyMultiplier) {
     190      double penaltyMultiplier, bool useSplitting) {
    173191      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    174       var targetValues    = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    175       var constraints     = problemData.IntervalConstraints.EnabledConstraints;
    176       var variableRanges  = problemData.VariableRanges.GetReadonlyDictionary();
    177      
     192      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     193      var constraints = problemData.IntervalConstraints.EnabledConstraints;
     194      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
     195
    178196      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    179197      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues,
    180198        out var errorState);
    181199
    182       if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution,
     200      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, useSplitting,
    183201        out var error)) {
    184202        if (useSoftConstraints) {
     
    188206            nmse += penaltyMultiplier * error;
    189207          }
    190          
     208
    191209          nmse = Math.Min(1.0, nmse);
    192210        } else {
     
    206224      IEnumerable<int> rows) {
    207225      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    208       EstimationLimitsParameter.ExecutionContext                    = context;
    209       ApplyLinearScalingParameter.ExecutionContext                  = context;
     226      EstimationLimitsParameter.ExecutionContext = context;
     227      ApplyLinearScalingParameter.ExecutionContext = context;
    210228
    211229      var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
    212230        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
    213         problemData, rows, UseSoftConstraints, PenaltyMultiplier);
     231        problemData, rows, UseSoftConstraints, PenaltyMultiplier, UseIntervalSplitting);
    214232
    215233      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    216       EstimationLimitsParameter.ExecutionContext                    = null;
    217       ApplyLinearScalingParameter.ExecutionContext                  = null;
     234      EstimationLimitsParameter.ExecutionContext = null;
     235      ApplyLinearScalingParameter.ExecutionContext = null;
    218236
    219237      return nmse;
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs

    r17733 r17751  
    8585      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
    8686
    87       if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error))
     87      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, false, out double error))
    8888        return 1.0;
    8989
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs

    r17735 r17751  
    191191      // calculate result interval
    192192      if (!constraint.IsDerivative) {
    193         resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges));
     193        resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges), 0);
    194194      }
    195195      else {
     
    201201        }
    202202
    203         resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, new ReadOnlyDictionary<string, Interval>(regionRanges));
     203        resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, new ReadOnlyDictionary<string, Interval>(regionRanges), 0);
    204204      }
    205205
     
    226226    public static bool ConstraintsSatisfied(IEnumerable<IntervalConstraint> constraints,
    227227                                            IReadOnlyDictionary<string, Interval> variableRanges,
    228                                             ISymbolicExpressionTree solution,
     228                                            ISymbolicExpressionTree solution, bool useSplitting,
    229229                                            out double error) {
    230       var intervalInterpreter = new IntervalInterpreter();
     230      var intervalInterpreter = new IntervalInterpreter() {UseIntervalSplitting = useSplitting};
    231231      error = 0.0;
    232232      var satisfied = true;
Note: See TracChangeset for help on using the changeset viewer.