Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17660


Ignore:
Timestamp:
07/09/20 12:57:32 (4 years ago)
Author:
chaider
Message:

#3076

  • Set worst nmse value to 1.0 in SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator
  • Added SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator which allows to use linear scaling within IA
Location:
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r17653 r17660  
    178178    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" />
    179179    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs" />
     180    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs" />
    180181    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs" />
    181182    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs" />
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs

    r17653 r17660  
    9999
    100100      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution))
    101         return double.MaxValue;
     101        return 1.0;
    102102
    103103      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    104104      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
    105       if (errorState != OnlineCalculatorError.None) nmse = double.NaN;
     105      if (errorState != OnlineCalculatorError.None) nmse = 1.0;
    106106
    107107      return nmse;
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs

    r17653 r17660  
    99
    1010namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective.Evaluators {
    11   [Item("Constraint ConstOpt NMSE Evaluator", "")]
    12   [StorableType("DED36D85-A4BA-4019-B12D-C523F7327899")]
    13   public class SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator
     11  [Item("Constraint Scaling NMSE Evaluator", "")]
     12  [StorableType("5B69083F-74EE-446C-A7D1-9DEAAA128AC6")]
     13  public class SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator
    1414    : SymbolicRegressionSingleObjectiveEvaluator {
    15     private const string UseConstOptParameterName = "Use ConstOpt";
    16     private const string ConstOptIterationsParameterName = "ConstOpt Iterations";
    17 
    18     public IFixedValueParameter<BoolValue> UseConstOptParamerter =>
    19       (IFixedValueParameter<BoolValue>) Parameters[UseConstOptParameterName];
    20 
    21     public IFixedValueParameter<IntValue> ConstOpterIterationsParameter =>
    22       (IFixedValueParameter<IntValue>) Parameters[ConstOptIterationsParameterName];
    23 
    24     public bool UseConstOpt {
    25       get => UseConstOptParamerter.Value.Value;
    26       set => UseConstOptParamerter.Value.Value = value;
    27     }
    28 
    29     public int ConstOptIterations {
    30       get => ConstOpterIterationsParameter.Value.Value;
    31       set => ConstOpterIterationsParameter.Value.Value = value;
    32     }
    3315
    3416    [StorableConstructor]
    35     protected SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator(StorableConstructorFlag _) : base(_) {}
     17    protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(StorableConstructorFlag _) : base(_) {}
    3618
    37     protected SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator(
    38       SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator original, Cloner cloner) :
     19    protected SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(
     20      SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator original, Cloner cloner) :
    3921      base(original, cloner) { }
    4022
    4123    public override IDeepCloneable Clone(Cloner cloner) {
    42       return new SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator(this, cloner);
     24      return new SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator(this, cloner);
    4325    }
    4426
    45     public SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator() {
    46       Parameters.Add(new FixedValueParameter<BoolValue>(UseConstOptParameterName,
    47         "Define whether constOpt is active or not.", new BoolValue(true)));
    48       Parameters.Add(new FixedValueParameter<IntValue>(ConstOptIterationsParameterName,
    49         "Define how many constOpt iterations should be performed.", new IntValue(10)));
    50     }
     27    public SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator() { }
    5128
    5229    public override bool Maximization => false;
    5330
    54     [StorableHook(HookType.AfterDeserialization)]
    55     private void AfterDeserialization() {
    56       if (!Parameters.ContainsKey(UseConstOptParameterName)) {
    57         Parameters.Add(new FixedValueParameter<BoolValue>(UseConstOptParameterName,
    58           "Define whether constOpt is active or not.", new BoolValue(true)));
    59       }
    60 
    61       if (!Parameters.ContainsKey(ConstOptIterationsParameterName)) {
    62         Parameters.Add(new FixedValueParameter<IntValue>(ConstOptIterationsParameterName,
    63           "Define how many constOpt iterations should be performed.", new IntValue(10)));
    64       }
    65     }
    6631
    6732    public override IOperation InstrumentedApply() {
     
    7136      var interpreter                               = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    7237      var estimationLimits                          = EstimationLimitsParameter.ActualValue;
    73       var applyLinearScaling                        = false;
    74       var constantOptimizationIterations            = ConstOptIterations;
    75       var constantOptimizationUpdateVariableWeights = true;
    76 
    77       //Use Const Opt
    78       if(UseConstOpt)
    79         SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows,
    80           applyLinearScaling, constantOptimizationIterations, constantOptimizationUpdateVariableWeights,
    81           estimationLimits.Lower, estimationLimits.Upper);
     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     }
    8273
    8374      var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows,
     
    9990
    10091      if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution))
    101         return double.MaxValue;
     92        return 1.0;
    10293
    10394      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    10495      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
    105       if (errorState != OnlineCalculatorError.None) nmse = double.NaN;
     96      if (errorState != OnlineCalculatorError.None) nmse = 1.0;
    10697
    10798      return nmse;
Note: See TracChangeset for help on using the changeset viewer.