Changeset 17821 for branches/3076_IA_evaluators_analyzers
- Timestamp:
- 01/19/21 10:22:50 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 1 added
- 5 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r17795 r17821 176 176 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 177 177 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintEvaluator.cs" /> 178 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintScalingNmseEvaluator.cs" />179 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintConstOptNmseEvaluator.cs" />180 178 <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" /> 179 <Compile Include="SymbolicRegressionSplittingAnalyzer.cs" /> 181 180 <Compile Include="SymbolicRegressionConstraintAnalyzer.cs" /> 182 <Compile Include="SymbolicRegressionMetaModelAnalyzer.cs" />183 <Compile Include="SymbolicRegressionMultiObjectiveMetaModelAnalyzer.cs" />184 181 <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" /> 185 182 <Compile Include="SymbolicRegressionPruningAnalyzer.cs" /> … … 209 206 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" /> 210 207 <Compile Include="SymbolicRegressionPruningOperator.cs" /> 211 <Compile Include="SymbolicRegressionSingleObjectiveMetaModelAnalyzer.cs" />212 208 <Compile Include="SymbolicRegressionSolution.cs" /> 213 209 <Compile Include="SymbolicRegressionSolutionImpactValuesCalculator.cs" /> -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiHardConstraintEvaluator.cs
r17733 r17821 11 11 [StorableType("9397A63D-0C6B-4733-BD1A-59AAE9A9F006")] 12 12 public class SymbolicRegressionMultiObjectiveMultiHardConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 13 private const string BoundsEstimatorParameterName = "Bounds estimator"; 14 public IValueParameter<IBoundsEstimator> BoundsEstimatorParameter => 15 (IValueParameter<IBoundsEstimator>)Parameters[BoundsEstimatorParameterName]; 16 17 public IBoundsEstimator BoundsEstimator { 18 get => BoundsEstimatorParameter.Value; 19 set => BoundsEstimatorParameter.Value = value; 20 } 21 13 22 #region Constructors 14 23 … … 47 56 48 57 var qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, 49 rows, applyLinearScaling, DecimalPlaces );58 rows, applyLinearScaling, DecimalPlaces, BoundsEstimator); 50 59 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 60 return base.InstrumentedApply(); … … 62 71 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 63 72 problemData, rows, 64 ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces );73 ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces, BoundsEstimator); 65 74 66 75 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 75 84 double upperEstimationLimit, 76 85 IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, 77 int decimalPlaces ) {86 int decimalPlaces, IBoundsEstimator estimator) { 78 87 OnlineCalculatorError errorState; 79 88 var estimatedValues = … … 91 100 92 101 var constraints = problemData.IntervalConstraints.Constraints.Where(c => c.Enabled); 93 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();102 var intervalCollection = problemData.VariableRanges; 94 103 95 104 var objectives = new List<double> {nmse}; //Add r² to resultlist 96 105 var constraintObjectives = constraints.Select(constraint => 97 ConstraintExceeded(constraint, new IntervalInterpreter(),98 variableRanges, solution)); 106 IntervalUtil.IntervalConstraintViolation(constraint, estimator, intervalCollection, solution) > 0 ? 0.0 : 1.0); 107 99 108 objectives.AddRange(constraintObjectives); //Add hardconstraints for each constraint 100 109 … … 102 111 } 103 112 104 private static double ConstraintExceeded(IntervalConstraint constraint, IntervalInterpreter intervalInterpreter,105 IReadOnlyDictionary<string, Interval> variableRanges,106 ISymbolicExpressionTree solution) {107 return SymbolicRegressionConstraintAnalyzer.ConstraintSatisfied(constraint, new IntervalInterpreter(),108 variableRanges, solution, out double error) ? 0 : 1;109 }110 113 111 114 /* -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r17611 r17821 96 96 changed = true; 97 97 } 98 99 if (!Operators.OfType<SymbolicRegressionSplittingAnalyzer>().Any()) { 100 Operators.Add(new SymbolicRegressionSplittingAnalyzer()); 101 changed = true; 102 } 98 103 if (changed) { 99 104 ParameterizeOperators(); … … 119 124 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 120 125 Operators.Add(new SymbolicRegressionConstraintAnalyzer()); 126 Operators.Add(new SymbolicRegressionSplittingAnalyzer()); 121 127 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" }); 122 128 ParameterizeOperators(); -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17792 r17821 17 17 [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")] 18 18 public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 19 private const string ConstraintViolationsResultName = "Constraint Violations";20 19 private const string ProblemDataParameterName = "ProblemData"; 21 20 private const string ConstraintViolationParameterName = "ConstraintViolations"; 22 private const string PenalityMultiplierParameterName = "ConstraintsPenalityMultiplier";23 private const string PenalityMultiplierResultParameterName = "PenalityMultiplierResultParameter";24 private const string StepSizeParameterName = "Step Size";25 private const string MaximumStepsParameterName = "Maximum Steps";26 private const string StartPenalityParameterName = "Start Penality";27 21 private const string ConstraintUnsatisfiedSolutionsParameterName = "Constraint Unsatisfied Solutions"; 28 22 … … 34 28 public IResultParameter<DataTable> ConstraintViolationParameter => 35 29 (IResultParameter<DataTable>) Parameters[ConstraintViolationParameterName]; 36 37 public ILookupParameter<DoubleValue> PenalityMultiplierParameter =>38 (ILookupParameter<DoubleValue>) Parameters[PenalityMultiplierParameterName];39 40 public IValueParameter<IntValue> StepSizeParameter =>41 (IValueParameter<IntValue>) Parameters[StepSizeParameterName];42 43 public IValueParameter<IntValue> MaximumStepsParameter =>44 (IValueParameter<IntValue>) Parameters[MaximumStepsParameterName];45 46 public IResultParameter<DataTable> PenalityMultiplierResultParameter =>47 (IResultParameter<DataTable>) Parameters[PenalityMultiplierResultParameterName];48 49 public IValueParameter<DoubleValue> StartPenalityParameter =>50 (IValueParameter<DoubleValue>) Parameters[StartPenalityParameterName];51 30 52 31 public IResultParameter<DataTable> ConstraintUnsatisfiedSolutionsParameter => … … 75 54 Parameters.Add(new ResultParameter<DataTable>(ConstraintViolationParameterName, 76 55 "Shows the number of constraint violations!")); 77 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName,78 "Lookup parameter for the penality multiplier.", "PenalityMultiplier"));79 Parameters.Add(new ResultParameter<DataTable>(PenalityMultiplierResultParameterName,80 "Shows the behavior of the penality multiplier."));81 Parameters.Add(new ValueParameter<IntValue>(StepSizeParameterName,82 "Defines the step size for the increasing penality multiplier.", new IntValue(1)));83 Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName,84 "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000)));85 Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName,86 "The start value for the penality multiplier.", new DoubleValue(0.5)));87 56 Parameters.Add(new ResultParameter<DataTable>(ConstraintUnsatisfiedSolutionsParameterName, 88 57 "Shows the number of solutions with unsatisfied constraints.")); … … 93 62 XAxisTitle = "Generations", 94 63 YAxisTitle = "Constraint Violations" 95 }96 };97 98 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) {99 VisualProperties = {100 XAxisTitle = "Generations",101 YAxisTitle = "Penality Multiplier"102 64 } 103 65 }; … … 124 86 [StorableHook(HookType.AfterDeserialization)] 125 87 private void AfterDeserialization() { 126 if ( !Parameters.ContainsKey(PenalityMultiplierParameterName))127 Parameters.Add(new LookupParameter<DoubleValue>(PenalityMultiplierParameterName,128 "Lookup parameter for the penality multiplier.", "PenalityMultiplier"));88 if (Parameters.ContainsKey(ConstraintUnsatisfiedSolutionsParameterName)) return; 89 Parameters.Add(new ResultParameter<DataTable>(ConstraintUnsatisfiedSolutionsParameterName, 90 "Shows the number of solutions with unsatisfied constraints.")); 129 91 130 if (!Parameters.ContainsKey(PenalityMultiplierResultParameterName)) { 131 Parameters.Add(new ResultParameter<DataTable>(PenalityMultiplierResultParameterName, 132 "Shows the behavior of the penality multiplier.")); 133 134 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) { 135 VisualProperties = { 136 XAxisTitle = "Generations", 137 YAxisTitle = "Penality Multiplier" 138 } 139 }; 140 } 141 142 if (!Parameters.ContainsKey(StepSizeParameterName)) 143 Parameters.Add(new ValueParameter<IntValue>(StepSizeParameterName, 144 "Defines the step size for the increasing penality multiplier.", new IntValue(1))); 145 146 if (!Parameters.ContainsKey(MaximumStepsParameterName)) 147 Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName, 148 "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000))); 149 150 151 if (!Parameters.ContainsKey(StartPenalityParameterName)) 152 Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName, 153 "The start value for the penality multiplier.", new DoubleValue(0.5))); 154 155 156 if(!Parameters.ContainsKey(ConstraintUnsatisfiedSolutionsParameterName)) { 157 Parameters.Add(new ResultParameter<DataTable>(ConstraintUnsatisfiedSolutionsParameterName, 158 "Shows the number of solutions with unsatisfied constraints.")); 159 160 ConstraintUnsatisfiedSolutionsParameter.DefaultValue = new DataTable(ConstraintUnsatisfiedSolutionsParameterName) { 161 VisualProperties = { 162 XAxisTitle = "Generations", 163 YAxisTitle = "Constraint Unsatisfied Solutions" 164 } 165 }; 166 } 92 ConstraintUnsatisfiedSolutionsParameter.DefaultValue = new DataTable(ConstraintUnsatisfiedSolutionsParameterName) { 93 VisualProperties = { 94 XAxisTitle = "Generations", 95 YAxisTitle = "Constraint Unsatisfied Solutions" 96 } 97 }; 167 98 } 168 99 169 100 public override IOperation Apply() { 170 101 Iterations++; 171 var rowName = "GeneralizedExponentialDiscreteDoubleValueModifier";172 var stepSize = StepSizeParameter?.Value?.Value ?? 1;173 var startValue = StartPenalityParameter?.Value?.Value ?? 0.5;174 var maximumSteps = MaximumStepsParameter?.Value?.Value ?? 1000;175 var penalityMultiplier = new DoubleValue(LinearDiscreteDoubleValueModifier.Apply(0, startValue, 1.0,176 (int) (Iterations / stepSize) * stepSize, 0, maximumSteps));177 PenalityMultiplierParameter.ActualValue = penalityMultiplier;178 //GeneralizedExponentialDiscreteDoubleValueModifier179 //QuadraticDiscreteDoubleValueModifier180 //LinearDiscreteDoubleValueModifier181 102 182 103 var problemData = RegressionProblemDataParameter.ActualValue; … … 194 115 newDataTable.Rows.Add(new DataRow(constraint.Expression)); 195 116 196 var interpreter = new IntervalInterpreter();197 117 foreach (var constraint in constraints) { 198 var violations = trees.Select(tree => 199 ConstraintSatisfied(constraint, interpreter, variableRanges, tree, out double error)) 200 .Count(satisfied => !satisfied); 118 var violations = trees.Count(tree => IntervalUtil.IntervalConstraintViolation(constraint, BoundsEstimator, intervalCollection, tree) > 0.0); 119 201 120 newDataTable.Rows[constraint.Expression].Values.Add(violations); 202 121 } 203 204 var penalityDataTable = PenalityMultiplierResultParameter.ActualValue;205 if (penalityDataTable.Rows.Count == 0)206 penalityDataTable.Rows.Add(new DataRow(rowName));207 penalityDataTable.Rows[rowName].Values.Add(penalityMultiplier.Value);208 122 209 123 var constraintUnsatisfiedSolutionsDataTable = ConstraintUnsatisfiedSolutionsParameter.ActualValue; … … 213 127 constraintUnsatisfiedSolutionsDataTable.Rows[ConstraintUnsatisfiedSolutionsParameterName] 214 128 .Values 215 .Add( 216 solutions 217 .Where(s => IntervalUtil.IntervalConstraintsViolation(constraints, BoundsEstimator, intervalCollection, s).Any(x => x != 0.0)) 218 .Count()); 129 .Add(solutions.Count(s => IntervalUtil.IntervalConstraintsViolation(constraints, BoundsEstimator, intervalCollection, s).Any(x => x != 0.0))); 219 130 220 131 return base.Apply(); 221 132 } 222 133 223 public static bool ConstraintSatisfied(IntervalConstraint constraint, 224 IntervalInterpreter intervalInterpreter, 225 IReadOnlyDictionary<string, Interval> variableRanges, 226 ISymbolicExpressionTree solution, 227 out double error) { 228 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) 229 throw new 230 ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", 231 nameof(IntervalConstraintsParser)); 232 233 Interval resultInterval; 234 235 //Create new variable ranges for defined regions 236 var regionRanges = new IntervalCollection(); 237 foreach (var kvp in variableRanges) { 238 if (kvp.Key != constraint.Target && 239 constraint.Regions.GetReadonlyDictionary().TryGetValue(kvp.Key, out Interval val)) { 240 regionRanges.AddInterval(kvp.Key, val); 241 } else { 242 regionRanges.AddInterval(kvp.Key, kvp.Value); 243 } 244 } 245 246 // calculate result interval 247 if (!constraint.IsDerivative) { 248 resultInterval = 249 intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, 250 regionRanges.GetReadonlyDictionary()); 251 } else { 252 var tree = solution; 253 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 254 if (!IntervalInterpreter.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) 255 throw new ArgumentException("Cube, Root, Power Symbols are not supported."); 256 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 257 } 258 259 resultInterval = 260 intervalInterpreter.GetSymbolicExpressionTreeInterval(tree, 261 regionRanges.GetReadonlyDictionary()); 262 } 263 264 error = 0.0; 265 bool satisfied = true; 266 if (!constraint.Interval.Contains(resultInterval.LowerBound)) { 267 satisfied = false; 268 error += Math.Abs(resultInterval.LowerBound - constraint.Interval.LowerBound); 269 } 270 271 if (!constraint.Interval.Contains(resultInterval.UpperBound)) { 272 satisfied = false; 273 error += Math.Abs(resultInterval.UpperBound - constraint.Interval.UpperBound); 274 } 275 276 error *= constraint.Weight; 277 278 //var satisfied = constraint.Interval.Contains(resultInterval); 279 return satisfied; 280 } 281 282 public static bool ConstraintsSatisfied(IEnumerable<IntervalConstraint> constraints, 283 IReadOnlyDictionary<string, Interval> variableRanges, 284 ISymbolicExpressionTree solution, 285 out double error) { 286 var intervalInterpreter = new IntervalInterpreter(); 287 error = 0.0; 288 var satisfied = true; 289 foreach (var constraint in constraints) { 290 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) 291 throw new 292 ArgumentException( 293 $"The given variable {constraint.Variable} in the constraint does not exists in the model.", 294 nameof(IntervalConstraintsParser)); 295 296 satisfied = ConstraintSatisfied(constraint, intervalInterpreter, variableRanges, solution, out double e) && 297 satisfied; 298 error += e; 299 //if (!satisfied) return false; 300 } 301 302 return satisfied; 303 } 134 304 135 } 305 136 }
Note: See TracChangeset
for help on using the changeset viewer.