- Timestamp:
- 03/12/21 16:42:21 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r17879 r17892 176 176 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintEvaluator.cs" /> 177 177 <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" /> 178 <Compile Include="SymbolicRegressionSplittingAnalyzer.cs" />179 178 <Compile Include="SymbolicRegressionConstraintAnalyzer.cs" /> 180 179 <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" /> -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator.cs
r17882 r17892 22 22 #endregion 23 23 24 using System;25 24 using System.Collections.Generic; 26 25 using System.Linq; … … 37 36 [StorableType("8E9D76B7-ED9C-43E7-9898-01FBD3633880")] 38 37 public class 39 SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator 40 { 38 SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 41 39 public const string DimensionsParameterName = "Dimensions"; 42 40 private const string BoundsEstimatorParameterName = "Bounds estimator"; 43 41 44 42 public IFixedValueParameter<IntValue> DimensionsParameter => 45 (IFixedValueParameter<IntValue>) 43 (IFixedValueParameter<IntValue>)Parameters[DimensionsParameterName]; 46 44 47 45 public IValueParameter<IBoundsEstimator> BoundsEstimatorParameter => 48 (IValueParameter<IBoundsEstimator>) Parameters[BoundsEstimatorParameterName]; 46 (IValueParameter<IBoundsEstimator>)Parameters[BoundsEstimatorParameterName]; 47 48 public int Dimensions { 49 get => DimensionsParameter.Value.Value; 50 set => DimensionsParameter.Value.Value = value; 51 } 49 52 50 53 public IBoundsEstimator BoundsEstimator { … … 57 60 public SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator() { 58 61 Parameters.Add(new FixedValueParameter<IntValue>(DimensionsParameterName, new IntValue(2))); 59 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new I ABoundsEstimator()));62 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator())); 60 63 } 61 64 … … 74 77 75 78 if (!Parameters.ContainsKey(BoundsEstimatorParameterName)) 76 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new I ABoundsEstimator()));79 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator())); 77 80 } 78 81 … … 121 124 if (node.Symbol.Name == "Offset") { 122 125 node.RemoveSubtree(1); 123 var alphaNode = new ConstantTreeNode(new Constant()) { Value = alpha};126 var alphaNode = new ConstantTreeNode(new Constant()) { Value = alpha }; 124 127 node.AddSubtree(alphaNode); 125 128 } else if (node.Symbol.Name == "Scaling") { 126 129 node.RemoveSubtree(1); 127 var betaNode = new ConstantTreeNode(new Constant()) { Value = beta};130 var betaNode = new ConstantTreeNode(new Constant()) { Value = beta }; 128 131 node.AddSubtree(betaNode); 129 132 } … … 165 168 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 166 169 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 167 var constraints = problemData. IntervalConstraints.Constraints.Where(c => c.Enabled);170 var constraints = problemData.ShapeConstraints.Where(c => c.Enabled); 168 171 var intervalCollection = problemData.VariableRanges; 169 172 … … 177 180 nmse = 1.0; 178 181 179 var objectives = new List<double> { nmse};180 var results = IntervalUtil.IntervalConstraintsViolation(constraints, estimator, intervalCollection, solution);181 foreach (var result in results) {182 if (double.IsNaN( result) || double.IsInfinity(result)) {182 var objectives = new List<double> { nmse }; 183 var violations = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, solution); 184 foreach (var violation in violations) { 185 if (double.IsNaN(violation) || double.IsInfinity(violation)) { 183 186 objectives.Add(double.MaxValue); 184 187 } else { 185 objectives.Add( result);188 objectives.Add(violation); 186 189 } 187 190 } 188 191 189 192 return objectives.ToArray(); 190 193 } … … 197 200 public override IEnumerable<bool> Maximization { 198 201 get { 199 var objectives = new List<bool> {false}; //First NMSE ==> min 200 objectives.AddRange(Enumerable.Repeat(false, DimensionsParameter.Value.Value)); //Constraints ==> min 202 var objectives = new List<bool> { false }; // NMSE ==> min 203 var dim = Dimensions; 204 objectives.AddRange(Enumerable.Repeat(false, dim)); // Constraints ==> min 201 205 202 206 return objectives; -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintEvaluator.cs
r17878 r17892 1 1 using System; 2 using System.CodeDom;3 2 using System.Collections.Generic; 4 3 using System.Linq; 5 using System.Text;6 using System.Threading.Tasks;7 4 using HEAL.Attic; 8 5 using HeuristicLab.Common; … … 96 93 "Define whether the constraints are penalized by soft or hard constraints.", new BoolValue(false))); 97 94 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, 98 "Select the Boundsestimator.", new I ABoundsEstimator()));95 "Select the Boundsestimator.", new IntervalArithBoundsEstimator())); 99 96 Parameters.Add(new FixedValueParameter<DoubleValue>(MaximumPenaltyFactorParamterName, 100 97 "Specify how hard constraints violations should be punished", new DoubleValue(1.5))); … … 120 117 if (!Parameters.ContainsKey(BoundsEstimatorParameterName)) 121 118 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, 122 "Select the Boundsestimator.", new I ABoundsEstimator()));119 "Select the Boundsestimator.", new IntervalArithBoundsEstimator())); 123 120 124 121 if (!Parameters.ContainsKey(MaximumPenaltyFactorParamterName)) { … … 197 194 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 198 195 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 199 var constraints = problemData. IntervalConstraints.EnabledConstraints;196 var constraints = problemData.ShapeConstraints.EnabledConstraints; 200 197 var intervalCollection = problemData.VariableRanges; 201 198 … … 208 205 } 209 206 210 var constraintResults = IntervalUtil. IntervalConstraintsViolation(constraints, estimator, intervalCollection, solution);207 var constraintResults = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, solution); 211 208 212 209 if (constraintResults.Any(x => double.IsNaN(x) || double.IsInfinity(x))) { … … 217 214 if (useSoftConstraints) { 218 215 if (maximumPenaltyFactor < 0.0) 219 throw new ArgumentException("The parameter 'Maximum Penalty Factor' has to be greater or equal 0.0!");216 throw new ArgumentException("The parameter has to be greater or equal 0.0!", nameof(maximumPenaltyFactor)); 220 217 221 218 var zip = constraints.Zip(constraintResults, (c, e) => new { Constraint = c, Error = e }); -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r17821 r17892 96 96 changed = true; 97 97 } 98 99 if (!Operators.OfType<SymbolicRegressionSplittingAnalyzer>().Any()) {100 Operators.Add(new SymbolicRegressionSplittingAnalyzer());101 changed = true;102 }103 98 if (changed) { 104 99 ParameterizeOperators(); … … 124 119 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 125 120 Operators.Add(new SymbolicRegressionConstraintAnalyzer()); 126 Operators.Add(new SymbolicRegressionSplittingAnalyzer());127 121 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" }); 128 122 ParameterizeOperators(); -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17821 r17892 1 using System; 2 using System.Collections.Generic; 3 using System.Collections.ObjectModel; 4 using System.Linq; 5 using System.Threading; 1 using System.Linq; 6 2 using HEAL.Attic; 7 3 using HeuristicLab.Analysis; 8 4 using HeuristicLab.Common; 9 5 using HeuristicLab.Core; 10 using HeuristicLab.Data;11 6 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 12 7 using HeuristicLab.Optimization; 13 using HeuristicLab.Optimization.Operators;14 8 using HeuristicLab.Parameters; 15 9 … … 37 31 public static int Iterations { get; set; } = 0; 38 32 39 public IBoundsEstimator BoundsEstimator { get; set; } = new I ABoundsEstimator();33 public IBoundsEstimator BoundsEstimator { get; set; } = new IntervalArithBoundsEstimator(); 40 34 41 35 [StorableConstructor] … … 105 99 106 100 var results = ResultCollectionParameter.ActualValue; 107 var constraints = problemData. IntervalConstraints.EnabledConstraints;101 var constraints = problemData.ShapeConstraints.EnabledConstraints; 108 102 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 109 103 var intervalCollection = problemData.VariableRanges; 110 104 var newDataTable = ConstraintViolationParameter.ActualValue; 111 var solutions = this.SymbolicExpressionTree.ToArray();105 var solutions = SymbolicExpressionTree.ToArray(); 112 106 113 107 if (newDataTable.Rows.Count == 0) 114 108 foreach (var constraint in constraints) 115 newDataTable.Rows.Add(new DataRow(constraint. Expression));109 newDataTable.Rows.Add(new DataRow(constraint.ToString())); 116 110 117 111 foreach (var constraint in constraints) { 118 var violations = trees.Count(tree => IntervalUtil. IntervalConstraintViolation(constraint, BoundsEstimator, intervalCollection, tree) > 0.0);112 var violations = trees.Count(tree => IntervalUtil.GetConstraintViolation(constraint, BoundsEstimator, intervalCollection, tree) > 0.0); 119 113 120 newDataTable.Rows[constraint. Expression].Values.Add(violations);114 newDataTable.Rows[constraint.ToString()].Values.Add(violations); 121 115 } 122 116 … … 127 121 constraintUnsatisfiedSolutionsDataTable.Rows[ConstraintUnsatisfiedSolutionsParameterName] 128 122 .Values 129 .Add(solutions.Count(s => IntervalUtil. IntervalConstraintsViolation(constraints, BoundsEstimator, intervalCollection, s).Any(x => x != 0.0)));123 .Add(solutions.Count(s => IntervalUtil.GetConstraintViolations(constraints, BoundsEstimator, intervalCollection, s).Any(x => x != 0.0))); 130 124 131 125 return base.Apply(); -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSplittingAnalyzer.cs
r17821 r17892 155 155 var problemData = RegressionProblemDataParameter.ActualValue; 156 156 var trees = SymbolicExpressionTreeParameter.ActualValue; 157 var constraints = problemData. IntervalConstraints.EnabledConstraints;157 var constraints = problemData.ShapeConstraints.EnabledConstraints; 158 158 var intervalCollection = problemData.VariableRanges; 159 var estimator = new I ABoundsEstimator();160 var splittingEstimator = new I ABoundsEstimator {UseIntervalSplitting = true, SplittingIterations = 12};159 var estimator = new IntervalArithBoundsEstimator(); 160 var splittingEstimator = new IntervalArithBoundsEstimator {UseIntervalSplitting = true, SplittingIterations = 12}; 161 161 162 162 foreach (var solution in trees) {
Note: See TracChangeset
for help on using the changeset viewer.