- Timestamp:
- 03/16/21 13:54:22 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 1 deleted
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/NMSEConstraintsEvaluator.cs
r17898 r17899 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.MultiObjective { 35 [Item(" Multi Soft Constraints Evaluator",36 "Calculates the NMSE and the constraints violations of a symbolic regression solution .")]35 [Item("NMSE Evaluator (multi-objective, with shape-constraints)", 36 "Calculates the NMSE and the constraints violations of a symbolic regression solution as objectives.")] 37 37 [StorableType("8E9D76B7-ED9C-43E7-9898-01FBD3633880")] 38 public class 39 SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 40 public const string DimensionsParameterName = "Dimensions"; 41 private const string BoundsEstimatorParameterName = "Bounds estimator"; 42 43 public IFixedValueParameter<IntValue> DimensionsParameter => 44 (IFixedValueParameter<IntValue>)Parameters[DimensionsParameterName]; 38 public class NMSEConstraintsEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 39 public const string NumObjectivesParameterName = "NumObjectives"; 40 private const string BoundsEstimatorParameterName = "BoundsEstimator"; 41 42 public IFixedValueParameter<IntValue> NumObjectivesParameter => 43 (IFixedValueParameter<IntValue>)Parameters[NumObjectivesParameterName]; 45 44 46 45 public IValueParameter<IBoundsEstimator> BoundsEstimatorParameter => 47 46 (IValueParameter<IBoundsEstimator>)Parameters[BoundsEstimatorParameterName]; 48 47 49 public int Dimensions { 50 get => DimensionsParameter.Value.Value; 51 set => DimensionsParameter.Value.Value = value; 48 [Storable] 49 private bool[] maximization; 50 51 public int NumObjectives { 52 get => NumObjectivesParameter.Value.Value; 53 set { 54 NumObjectivesParameter.Value.Value = value; 55 56 /* 57 * First objective is to minimize the NMSE 58 * All following objectives have to be minimized ==> Constraints 59 */ 60 this.maximization = new bool[value]; 61 } 52 62 } 53 63 … … 59 69 #region Constructors 60 70 61 public SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator() {62 Parameters.Add(new FixedValueParameter<IntValue>( DimensionsParameterName, new IntValue(2)));71 public NMSEConstraintsEvaluator() { 72 Parameters.Add(new FixedValueParameter<IntValue>(NumObjectivesParameterName, new IntValue(2))); 63 73 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator())); 74 maximization = new bool[2]; 64 75 } 65 76 66 77 [StorableConstructor] 67 protected SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator(StorableConstructorFlag _) : base(_) { } 68 69 protected SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator( 70 SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator original, Cloner cloner) : base(original, cloner) { } 78 protected NMSEConstraintsEvaluator(StorableConstructorFlag _) : base(_) { } 79 80 protected NMSEConstraintsEvaluator(NMSEConstraintsEvaluator original, Cloner cloner) : base(original, cloner) { 81 this.maximization = (bool[])original.maximization.Clone(); 82 } 71 83 72 84 #endregion 73 85 74 86 [StorableHook(HookType.AfterDeserialization)] 75 private void AfterDeserialization() { 76 if (!Parameters.ContainsKey(DimensionsParameterName)) 77 Parameters.Add(new FixedValueParameter<IntValue>(DimensionsParameterName, new IntValue(2))); 78 79 if (!Parameters.ContainsKey(BoundsEstimatorParameterName)) 80 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator())); 81 } 87 private void AfterDeserialization() { } 82 88 83 89 public override IDeepCloneable Clone(Cloner cloner) { 84 return new SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator(this, cloner);90 return new NMSEConstraintsEvaluator(this, cloner); 85 91 } 86 92 … … 123 129 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta, 124 130 out var errorState); 125 //Set alpha and beta to the scaling nodes from ia grammar 126 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode; 127 offsetParameter.Value = alpha; 128 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode; 129 scalingParameter.Value = beta; 131 if (errorState == OnlineCalculatorError.None) { 132 //Set alpha and beta to the scaling nodes from ia grammar 133 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode; 134 offsetParameter.Value = alpha; 135 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode; 136 scalingParameter.Value = beta; 137 } 130 138 } 131 139 } … … 190 198 } 191 199 192 /* 193 * First objective is to maximize the Pearson R² value 194 * All following objectives have to be minimized ==> Constraints 195 */ 196 197 public override IEnumerable<bool> Maximization { 198 get { 199 var objectives = new List<bool> { false }; // NMSE ==> min 200 var dim = Dimensions; 201 objectives.AddRange(Enumerable.Repeat(false, dim)); // Constraints ==> min 202 203 return objectives; 204 } 205 } 200 public override IEnumerable<bool> Maximization => maximization; 206 201 } 207 202 } -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSEConstraintsEvaluator.cs
r17898 r17899 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 34 [Item("NMSE Evaluator ( with shape-constraints)", "Calculates NMSE of a symbolic regression solution and checks constraints the fitness is a combination of NMSE and constraint violations.")]34 [Item("NMSE Evaluator (single-objective, with shape-constraints)", "Calculates NMSE of a symbolic regression solution and checks constraints the fitness is a combination of NMSE and constraint violations.")] 35 35 [StorableType("27473973-DD8D-4375-997D-942E2280AE8E")] 36 public class SymbolicRegressionSingleObjectiveConstraintEvaluator : SymbolicRegressionSingleObjectiveEvaluator {36 public class NMSEConstraintsEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 37 37 #region Parameter/Properties 38 38 … … 91 91 92 92 [StorableConstructor] 93 protected SymbolicRegressionSingleObjectiveConstraintEvaluator(StorableConstructorFlag _) : base(_) { }94 95 protected SymbolicRegressionSingleObjectiveConstraintEvaluator(96 SymbolicRegressionSingleObjectiveConstraintEvaluator original, Cloner cloner) : base(original, cloner) { }97 98 public SymbolicRegressionSingleObjectiveConstraintEvaluator() {93 protected NMSEConstraintsEvaluator(StorableConstructorFlag _) : base(_) { } 94 95 protected NMSEConstraintsEvaluator( 96 NMSEConstraintsEvaluator original, Cloner cloner) : base(original, cloner) { } 97 98 public NMSEConstraintsEvaluator() { 99 99 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName, 100 100 "Define whether optimization of numeric parameters is active or not (default: false).", new BoolValue(false))); … … 110 110 111 111 [StorableHook(HookType.AfterDeserialization)] 112 private void AfterDeserialization() { 113 if (!Parameters.ContainsKey(OptimizeParametersParameterName)) { 114 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName, 115 "Define whether optimization of numeric parameters is active or not (default: false).", new BoolValue(false))); 116 } 117 118 if (!Parameters.ContainsKey(ParameterOptimizationIterationsParameterName)) { 119 Parameters.Add(new FixedValueParameter<IntValue>(ParameterOptimizationIterationsParameterName, 120 "Define how many parameter optimization steps should be performed (default: 10).", new IntValue(10))); 121 } 122 123 if (!Parameters.ContainsKey(UseSoftConstraintsParameterName)) { 124 Parameters.Add(new FixedValueParameter<BoolValue>(UseSoftConstraintsParameterName, 125 "Define whether the constraints are penalized by soft or hard constraints (default: false).", new BoolValue(false))); 126 } 127 128 if (!Parameters.ContainsKey(BoundsEstimatorParameterName)) 129 Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, 130 "The estimator which is used to estimate output ranges of models (default: interval arithmetic).", new IntervalArithBoundsEstimator())); 131 132 if (!Parameters.ContainsKey(PenaltyFactorParameterName)) { 133 Parameters.Add(new FixedValueParameter<DoubleValue>(PenaltyFactorParameterName, 134 "Punishment factor for constraint violations for soft constraint handling (fitness = NMSE + penaltyFactor * avg(violations)) (default: 1.0)", new DoubleValue(1.0))); 135 } 136 } 112 private void AfterDeserialization() { } 137 113 138 114 public override IDeepCloneable Clone(Cloner cloner) { 139 return new SymbolicRegressionSingleObjectiveConstraintEvaluator(this, cloner);115 return new NMSEConstraintsEvaluator(this, cloner); 140 116 } 141 117 -
branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17898 r17899 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 32 32 [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")] 33 [Item("S ymbolic regression constraintanalyser", "Analyzes the number of shape-constraint violations of symbolic regression models.")]33 [Item("Shape-constraints analyser", "Analyzes the number of shape-constraint violations of symbolic regression models.")] 34 34 public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 35 35 private const string ProblemDataParameterName = "ProblemData"; … … 94 94 95 95 [StorableHook(HookType.AfterDeserialization)] 96 private void AfterDeserialization() { 97 if (Parameters.ContainsKey(InfeasibleSolutionsParameterName)) return; 98 Parameters.Add(new ResultParameter<DataTable>(InfeasibleSolutionsParameterName, 99 "The number of infeasible solutions.")); 100 101 InfeasibleSolutionsParameter.DefaultValue = new DataTable(InfeasibleSolutionsParameterName) { 102 VisualProperties = { 103 XAxisTitle = "Generations", 104 YAxisTitle = "Infeasible solutions" 105 } 106 }; 107 } 96 private void AfterDeserialization() { } 108 97 109 98 public override IOperation Apply() {
Note: See TracChangeset
for help on using the changeset viewer.