Changeset 17733 for branches/3076_IA_evaluators_analyzers
- Timestamp:
- 08/27/20 13:01:18 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiHardConstraintEvaluator.cs
r17652 r17733 106 106 ISymbolicExpressionTree solution) { 107 107 return SymbolicRegressionConstraintAnalyzer.ConstraintSatisfied(constraint, new IntervalInterpreter(), 108 variableRanges, solution ) ? 0 : 1;108 variableRanges, solution, out double error) ? 0 : 1; 109 109 } 110 110 -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator.cs
r17722 r17733 41 41 42 42 public IFixedValueParameter<IntValue> DimensionsParameter => (IFixedValueParameter<IntValue>)Parameters[DimensionsParameterName]; 43 43 44 44 45 #region Constructors -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs
r17636 r17733 46 46 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 47 47 48 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree )) return 0;48 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree, out double error)) return 0; 49 49 50 50 var r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs
r17660 r17733 15 15 private const string UseConstOptParameterName = "Use ConstOpt"; 16 16 private const string ConstOptIterationsParameterName = "ConstOpt Iterations"; 17 private const string PenalityMultiplierParameterName = "ConstraintsPenalityMultiplier"; 17 18 18 19 public IFixedValueParameter<BoolValue> UseConstOptParamerter => … … 21 22 public IFixedValueParameter<IntValue> ConstOpterIterationsParameter => 22 23 (IFixedValueParameter<IntValue>) Parameters[ConstOptIterationsParameterName]; 24 25 public ILookupParameter<DoubleValue> PenalityMultiplierParameter => 26 (ILookupParameter<DoubleValue>)Parameters[PenalityMultiplierParameterName]; 23 27 24 28 public bool UseConstOpt { … … 48 52 Parameters.Add(new FixedValueParameter<IntValue>(ConstOptIterationsParameterName, 49 53 "Define how many constOpt iterations should be performed.", new IntValue(10))); 54 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName, 55 "Lookup parameter for the penality multiplier.", "PenalityMultiplier")); 50 56 } 51 57 … … 63 69 "Define how many constOpt iterations should be performed.", new IntValue(10))); 64 70 } 71 72 if (!Parameters.ContainsKey(PenalityMultiplierParameterName)) 73 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName, 74 "Lookup parameter for the penality multiplier.", "PenalityMultiplier")); 65 75 } 66 76 … … 81 91 estimationLimits.Lower, estimationLimits.Upper); 82 92 93 var penalityMultiplier = PenalityMultiplierParameter.ActualValue?.Value ?? 1.0; 94 83 95 var quality = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, 84 applyLinearScaling );96 applyLinearScaling, penalityMultiplier); 85 97 QualityParameter.ActualValue = new DoubleValue(quality); 98 99 86 100 return base.InstrumentedApply(); 87 101 } … … 91 105 ISymbolicExpressionTree solution, double lowerEstimationLimit, 92 106 double upperEstimationLimit, 93 IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 107 IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, 108 double penalityMultiplier) { 94 109 var estimatedValues = 95 110 interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); … … 98 113 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 99 114 100 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution))101 return 1.0;102 103 115 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 104 116 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 117 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error)) 118 { 119 if (double.IsNaN(error) || double.IsInfinity(error)) 120 nmse += penalityMultiplier * 1.0; 121 else 122 nmse += penalityMultiplier * error; 123 nmse = Math.Min(1.0, nmse); 124 } 125 105 126 if (errorState != OnlineCalculatorError.None) nmse = 1.0; 106 127 … … 115 136 ApplyLinearScalingParameter.ExecutionContext = context; 116 137 138 var penalityMultiplier = PenalityMultiplierParameter.ActualValue?.Value ?? 1.0; 139 117 140 var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, 118 141 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 119 142 problemData, rows, 120 ApplyLinearScalingParameter.ActualValue.Value); 143 ApplyLinearScalingParameter.ActualValue.Value, 144 penalityMultiplier); 121 145 122 146 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs
r17652 r17733 50 50 var tree = solution; 51 51 52 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree )) return 0;52 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree, out double error)) return 0; 53 53 54 54 var r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs
r17705 r17733 85 85 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 86 86 87 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution ))87 if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, solution, out double error)) 88 88 return 1.0; 89 89 -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17722 r17733 3 3 using System.Collections.ObjectModel; 4 4 using System.Linq; 5 using System.Threading; 5 6 using HEAL.Attic; 6 7 using HeuristicLab.Analysis; 7 8 using HeuristicLab.Common; 8 9 using HeuristicLab.Core; 10 using HeuristicLab.Data; 9 11 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 10 12 using HeuristicLab.Optimization; 13 using HeuristicLab.Optimization.Operators; 11 14 using HeuristicLab.Parameters; 12 15 … … 17 20 private const string ProblemDataParameterName = "ProblemData"; 18 21 private const string ConstraintViolationParameterName = "ConstraintViolations"; 22 private const string PenalityMultiplierParameterName = "ConstraintsPenalityMultiplier"; 19 23 20 24 #region parameter properties … … 26 30 (IResultParameter<DataTable>) Parameters[ConstraintViolationParameterName]; 27 31 32 public ILookupParameter<DoubleValue> PenalityMultiplierParameter => 33 (ILookupParameter<DoubleValue>)Parameters[PenalityMultiplierParameterName]; 34 28 35 #endregion 29 36 30 37 public override bool EnabledByDefault => false; 38 public static int Iterations { get; set; } = 0; 31 39 32 40 [StorableConstructor] … … 42 50 public SymbolicRegressionConstraintAnalyzer() { 43 51 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, 44 52 "The problem data of the symbolic data analysis problem.")); 45 53 Parameters.Add(new ResultParameter<DataTable>(ConstraintViolationParameterName, 46 "Shows the number of constraint violations!")); 54 "Shows the number of constraint violations!")); 55 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName, 56 "Lookup parameter for the penality multiplier.", "PenalityMultiplier")); 57 47 58 ConstraintViolationParameter.DefaultValue = new DataTable(ConstraintViolationParameterName) { 48 VisualProperties = { 49 XAxisTitle 50 = "Generations", 51 YAxisTitle 52 = "Constraint Violations" 53 } 54 }; 59 VisualProperties = 60 { 61 XAxisTitle = "Generations", 62 YAxisTitle = "Constraint Violations" 63 } 64 }; 55 65 } 56 66 67 public override void InitializeState() 68 { 69 Iterations = 0; 70 base.InitializeState(); 71 } 72 73 public override void ClearState() 74 { 75 Iterations = 0; 76 base.ClearState(); 77 } 78 79 57 80 [StorableHook(HookType.AfterDeserialization)] 58 private void AfterDeserialization() { } 81 private void AfterDeserialization() { 82 if (!Parameters.ContainsKey(PenalityMultiplierParameterName)) 83 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName, 84 "Lookup parameter for the penality multiplier.", "PenalityMultiplier")); 85 } 59 86 60 public override IOperation Apply() { 87 public override IOperation Apply() 88 { 89 Iterations++; 90 91 PenalityMultiplierParameter.ActualValue = new DoubleValue(QuadraticDiscreteDoubleValueModifier.Calculate(0, 0.05, 1.0, Iterations, 0, 2000)); 92 //GeneralizedExponentialDiscreteDoubleValueModifier 93 61 94 var problemData = RegressionProblemDataParameter.ActualValue; 62 95 var trees = SymbolicExpressionTreeParameter.ActualValue; … … 73 106 var interpreter = new IntervalInterpreter(); 74 107 foreach (var constraint in constraints) { 75 var violations = trees.Select(tree => ConstraintSatisfied(constraint, interpreter, variableRanges, tree ))108 var violations = trees.Select(tree => ConstraintSatisfied(constraint, interpreter, variableRanges, tree, out double error)) 76 109 .Count(satisfied => !satisfied); 77 110 newDataTable.Rows[constraint.Expression].Values.Add(violations); … … 81 114 } 82 115 83 public static bool ConstraintSatisfied(IntervalConstraint 84 IntervalInterpreter 116 public static bool ConstraintSatisfied(IntervalConstraint constraint, 117 IntervalInterpreter intervalInterpreter, 85 118 IReadOnlyDictionary<string, Interval> variableRanges, 86 ISymbolicExpressionTree solution) { 119 ISymbolicExpressionTree solution, 120 out double error) { 87 121 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) 88 122 throw new … … 121 155 } 122 156 123 var satisfied = constraint.Interval.Contains(resultInterval); 157 error = 0.0; 158 bool satisfied = true; 159 if(!constraint.Interval.Contains(resultInterval.LowerBound)) 160 { 161 satisfied = false; 162 error += Math.Abs(resultInterval.LowerBound - constraint.Interval.LowerBound); 163 } 164 165 if (!constraint.Interval.Contains(resultInterval.UpperBound)) 166 { 167 satisfied = false; 168 error += Math.Abs(resultInterval.UpperBound - constraint.Interval.UpperBound); 169 } 170 171 error *= constraint.Weight; 172 173 //var satisfied = constraint.Interval.Contains(resultInterval); 124 174 return satisfied; 125 175 } 126 176 127 177 public static bool ConstraintsSatisfied(IEnumerable<IntervalConstraint> constraints, 128 IReadOnlyDictionary<string, Interval> variableRanges, 129 ISymbolicExpressionTree solution) { 178 IReadOnlyDictionary<string, Interval> variableRanges, 179 ISymbolicExpressionTree solution, 180 out double error) { 130 181 var intervalInterpreter = new IntervalInterpreter(); 182 error = 0.0; 183 var satisfied = true; 131 184 foreach (var constraint in constraints) { 132 185 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) … … 135 188 nameof(IntervalConstraintsParser)); 136 189 137 var satisfied = ConstraintSatisfied(constraint, intervalInterpreter, variableRanges, solution); 138 if (!satisfied) return false; 190 satisfied = ConstraintSatisfied(constraint, intervalInterpreter, variableRanges, solution, out double e) && satisfied; 191 error += e; 192 //if (!satisfied) return false; 139 193 } 140 194 141 return true;195 return satisfied; 142 196 } 143 197 }
Note: See TracChangeset
for help on using the changeset viewer.