Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/29/20 15:12:55 (4 years ago)
Author:
chaider
Message:

#3076

  • Fixed some formating in SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator
  • Added linear scaling check in SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator
  • Added linear scaling for SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator
Location:
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator.cs

    r17636 r17705  
    6262      var minIntervalWidth      = MinSplittingWidth;
    6363      var maxIntervalSplitDepth = MaxSplittingDepth;
    64       //var applyLinearScaling  = ApplyLinearScalingParameter.ActualValue.Value;
    65       var applyLinearScaling = false;
     64      var applyLinearScaling  = ApplyLinearScalingParameter.ActualValue.Value;
     65
     66      if (applyLinearScaling) {
     67        //Check for interval arithmetic grammar
     68        //remove scaling nodes for linear scaling evaluation
     69        var                    rootNode  = new ProgramRootSymbol().CreateTreeNode();
     70        var                    startNode = new StartSymbol().CreateTreeNode();
     71        SymbolicExpressionTree newTree   = null;
     72        foreach (var node in solution.IterateNodesPrefix())
     73          if (node.Symbol.Name == "Scaling") {
     74            for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i));
     75            rootNode.AddSubtree(startNode);
     76            newTree = new SymbolicExpressionTree(rootNode);
     77            break;
     78          }
     79
     80        //calculate alpha and beta for scaling
     81        var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
     82        var targetValues    = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     83        OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
     84          out var errorState);
     85        //Set alpha and beta to the scaling nodes from ia grammar
     86        foreach (var node in solution.IterateNodesPrefix())
     87          if (node.Symbol.Name == "Offset") {
     88            node.RemoveSubtree(1);
     89            var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha};
     90            node.AddSubtree(alphaNode);
     91          } else if (node.Symbol.Name == "Scaling") {
     92            node.RemoveSubtree(1);
     93            var betaNode = new ConstantTreeNode(new Constant()) {Value = beta};
     94            node.AddSubtree(betaNode);
     95          }
     96      }
    6697
    6798      if (UseConstantOptimization)
    6899        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows,
    69           applyLinearScaling,
     100          false,
    70101          ConstantOptimizationIterations,
    71102          ConstantOptimizationUpdateVariableWeights,
     
    74105
    75106      var qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData,
    76         rows, applyLinearScaling, DecimalPlaces, minIntervalWidth, maxIntervalSplitDepth);
     107        rows, DecimalPlaces, minIntervalWidth, maxIntervalSplitDepth);
    77108      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    78109      return base.InstrumentedApply();
     
    88119      var quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
    89120        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
    90         problemData, rows,
    91         ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces, MinSplittingWidth,
     121        problemData, rows, DecimalPlaces, MinSplittingWidth,
    92122        MaxSplittingDepth);
    93123
     
    103133                                     ISymbolicExpressionTree solution, double lowerEstimationLimit,
    104134                                     double upperEstimationLimit,
    105                                      IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling,
     135                                     IRegressionProblemData problemData, IEnumerable<int> rows,
    106136                                     int decimalPlaces, double minIntervalSplitWidth, int maxIntervalSplitDepth) {
    107137      OnlineCalculatorError errorState;
     
    114144      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    115145      nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    116       if (errorState != OnlineCalculatorError.None) nmse = double.NaN;
     146      if (errorState != OnlineCalculatorError.None) nmse = 1.0;
    117147
    118148      if (nmse > 1)
    119         nmse = 1;
     149        nmse = 1.0;
    120150
    121151      var constraints    = problemData.IntervalConstraints.Constraints.Where(c => c.Enabled);
     
    190220        var objectives = new List<bool> {false};          //First NMSE ==> min
    191221        objectives.AddRange(Enumerable.Repeat(false, 2)); //Constraints ==> min
    192 
     222       
    193223        return objectives;
    194224      }
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs

    r17660 r17705  
    1 using System;
    2 using System.Collections.Generic;
     1using System.Collections.Generic;
    32using HEAL.Attic;
    43using HeuristicLab.Common;
     
    65using HeuristicLab.Data;
    76using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    8 using HeuristicLab.Parameters;
    97
    108namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective.Evaluators {
     
    1311  public class SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator
    1412    : SymbolicRegressionSingleObjectiveEvaluator {
    15 
    1613    [StorableConstructor]
    17     protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) {}
     14    protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) { }
    1815
    1916    protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(
     
    3128
    3229    public override IOperation InstrumentedApply() {
    33       var rows                                      = GenerateRowsToEvaluate();
    34       var solution                                  = SymbolicExpressionTreeParameter.ActualValue;
    35       var problemData                               = ProblemDataParameter.ActualValue;
    36       var interpreter                               = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    37       var estimationLimits                          = EstimationLimitsParameter.ActualValue;
    38       var applyLinearScaling                        = false;
    39      
    40      //Check for interval arithmetic grammar
    41      //remove scaling nodes for linear scaling evaluation
    42      var rootNode = new ProgramRootSymbol().CreateTreeNode();
    43      var startNode = new StartSymbol().CreateTreeNode();
    44      SymbolicExpressionTree newTree = null;
    45      foreach (var node in solution.IterateNodesPrefix()) {
    46        if (node.Symbol.Name == "Scaling") {
    47          for (var i = 0; i < node.SubtreeCount; ++i) {
    48            startNode.AddSubtree(node.GetSubtree(i));
    49          }
    50          rootNode.AddSubtree(startNode);
    51          newTree = new SymbolicExpressionTree(rootNode);
    52          break;
    53        }
    54      }
    55      //calculate alpha and beta for scaling
    56      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
    57      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58      OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, out var errorState);
    59      var a = alpha;
    60      var b = beta;
    61      //Set alpha and beta to the scaling nodes from ia grammar
    62      foreach (var node in solution.IterateNodesPrefix()) {
    63        if (node.Symbol.Name == "Offset") {
    64          node.RemoveSubtree(1);
    65          var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha};
    66          node.AddSubtree(alphaNode);
    67        } else if (node.Symbol.Name == "Scaling") {
    68          node.RemoveSubtree(1);
    69          var betaNode = new ConstantTreeNode(new Constant()) {Value = beta};
    70          node.AddSubtree(betaNode);
    71        }
    72      }
     30      var rows               = GenerateRowsToEvaluate();
     31      var solution           = SymbolicExpressionTreeParameter.ActualValue;
     32      var problemData        = ProblemDataParameter.ActualValue;
     33      var interpreter        = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     34      var estimationLimits   = EstimationLimitsParameter.ActualValue;
     35      var applyLinearScaling = true;
     36
     37      if (applyLinearScaling) {
     38        //Check for interval arithmetic grammar
     39        //remove scaling nodes for linear scaling evaluation
     40        var                    rootNode  = new ProgramRootSymbol().CreateTreeNode();
     41        var                    startNode = new StartSymbol().CreateTreeNode();
     42        SymbolicExpressionTree newTree   = null;
     43        foreach (var node in solution.IterateNodesPrefix())
     44          if (node.Symbol.Name == "Scaling") {
     45            for (var i = 0; i < node.SubtreeCount; ++i) startNode.AddSubtree(node.GetSubtree(i));
     46            rootNode.AddSubtree(startNode);
     47            newTree = new SymbolicExpressionTree(rootNode);
     48            break;
     49          }
     50
     51        //calculate alpha and beta for scaling
     52        var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
     53        var targetValues    = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     54        OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
     55          out var errorState);
     56        //Set alpha and beta to the scaling nodes from ia grammar
     57        foreach (var node in solution.IterateNodesPrefix())
     58          if (node.Symbol.Name == "Offset") {
     59            node.RemoveSubtree(1);
     60            var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha};
     61            node.AddSubtree(alphaNode);
     62          } else if (node.Symbol.Name == "Scaling") {
     63            node.RemoveSubtree(1);
     64            var betaNode = new ConstantTreeNode(new Constant()) {Value = beta};
     65            node.AddSubtree(betaNode);
     66          }
     67      }
     68
    7369
    7470      var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows,
    75         applyLinearScaling);
     71        false);
    7672      QualityParameter.ActualValue = new DoubleValue(quality);
    7773      return base.InstrumentedApply();
     
    8581      var estimatedValues =
    8682        interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    87       var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    88       var constraints = problemData.IntervalConstraints.EnabledConstraints;
     83      var targetValues   = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     84      var constraints    = problemData.IntervalConstraints.EnabledConstraints;
    8985      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
    9086
     
    9389
    9490      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    95       var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
     91      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues,
     92        out var errorState);
    9693      if (errorState != OnlineCalculatorError.None) nmse = 1.0;
    9794
    9895      return nmse;
    9996    }
    100    
     97
    10198    public override double Evaluate(
    10299      IExecutionContext context, ISymbolicExpressionTree tree, IRegressionProblemData problemData,
     
    108105      var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
    109106        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
    110         problemData, rows,
    111         ApplyLinearScalingParameter.ActualValue.Value);
     107        problemData, rows, false);
    112108
    113109      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset for help on using the changeset viewer.