Changeset 17766 for branches/3076_IA_evaluators_analyzers
- Timestamp:
- 09/29/20 10:17:19 (4 years ago)
- Location:
- branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 2 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
r17744 r17766 211 211 <Compile Include="SymbolicRegressionSolution.cs" /> 212 212 <Compile Include="SymbolicRegressionSolutionImpactValuesCalculator.cs" /> 213 <None Include=".editorconfig" /> 213 214 <None Include="HeuristicLab.snk" /> 214 215 <None Include="Plugin.cs.frame" /> -
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs
r17764 r17766 17 17 [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")] 18 18 public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer { 19 private const string ConstraintViolationsResultName 20 private const string ProblemDataParameterName 19 private const string ConstraintViolationsResultName = "Constraint Violations"; 20 private const string ProblemDataParameterName = "ProblemData"; 21 21 private const string ConstraintViolationParameterName = "ConstraintViolations"; 22 22 private const string PenalityMultiplierParameterName = "ConstraintsPenalityMultiplier"; 23 23 private const string PenalityMultiplierResultParameterName = "PenalityMultiplierResultParameter"; 24 24 private const string StepSizeParameterName = "Step Size"; 25 private const string MaximumStepsParameterName = "Maximum Steps"; 26 private const string StartPenalityParameterName = "Start Penality"; 25 27 26 28 #region parameter properties 27 29 28 30 public ILookupParameter<IRegressionProblemData> RegressionProblemDataParameter => 29 (ILookupParameter<IRegressionProblemData>) 31 (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; 30 32 31 33 public IResultParameter<DataTable> ConstraintViolationParameter => 32 (IResultParameter<DataTable>) 34 (IResultParameter<DataTable>)Parameters[ConstraintViolationParameterName]; 33 35 34 36 public ILookupParameter<DoubleValue> PenalityMultiplierParameter => 35 37 (ILookupParameter<DoubleValue>)Parameters[PenalityMultiplierParameterName]; 38 36 39 public IValueParameter<IntValue> StepSizeParameter => 37 40 (IValueParameter<IntValue>)Parameters[StepSizeParameterName]; 38 41 42 public IValueParameter<IntValue> MaximumStepsParameter => 43 (IValueParameter<IntValue>)Parameters[MaximumStepsParameterName]; 44 39 45 public IResultParameter<DataTable> PenalityMultiplierResultParameter => 40 46 (IResultParameter<DataTable>)Parameters[PenalityMultiplierResultParameterName]; 47 public IValueParameter<DoubleValue> StartPenalityParameter => 48 (IValueParameter<DoubleValue>)Parameters[StartPenalityParameterName]; 41 49 42 50 #endregion … … 66 74 Parameters.Add(new ValueParameter<IntValue>(StepSizeParameterName, 67 75 "Defines the step size for the increasing penality multiplier.", new IntValue(1))); 76 Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName, 77 "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000))); 78 Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName, 79 "The start value for the penality multiplier.", new DoubleValue(0.5))); 80 81 82 68 83 69 84 ConstraintViolationParameter.DefaultValue = new DataTable(ConstraintViolationParameterName) { 70 VisualProperties = 85 VisualProperties = 71 86 { 72 87 XAxisTitle = "Generations", … … 75 90 }; 76 91 77 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) 78 { 92 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) { 79 93 VisualProperties = 80 94 { … … 85 99 } 86 100 87 public override void InitializeState() 88 { 101 public override void InitializeState() { 89 102 Iterations = 0; 90 103 base.InitializeState(); 91 104 } 92 105 93 public override void ClearState() 94 { 106 public override void ClearState() { 95 107 Iterations = 0; 96 108 base.ClearState(); … … 104 116 "Lookup parameter for the penality multiplier.", "PenalityMultiplier")); 105 117 106 if (!Parameters.ContainsKey(PenalityMultiplierResultParameterName)) 107 { 118 if (!Parameters.ContainsKey(PenalityMultiplierResultParameterName)) { 108 119 Parameters.Add(new ResultParameter<DataTable>(PenalityMultiplierResultParameterName, 109 120 "Shows the behavior of the penality multiplier.")); 110 121 111 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) 112 { 122 PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) { 113 123 VisualProperties = 114 124 { … … 123 133 "Defines the step size for the increasing penality multiplier.", new IntValue(1))); 124 134 125 } 126 127 public override IOperation Apply() 128 { 135 if (!Parameters.ContainsKey(MaximumStepsParameterName)) 136 Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName, 137 "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000))); 138 139 140 141 if (!Parameters.ContainsKey(StartPenalityParameterName)) 142 Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName, 143 "The start value for the penality multiplier.", new DoubleValue(0.5))); 144 } 145 146 public override IOperation Apply() { 129 147 Iterations++; 130 148 var rowName = "GeneralizedExponentialDiscreteDoubleValueModifier"; 131 149 var stepSize = StepSizeParameter?.Value?.Value ?? 1; 132 var penalityMultiplier = new DoubleValue(LinearDiscreteDoubleValueModifier.Apply(0, 0.1, 1.0, (int)(Iterations / stepSize) * stepSize, 0, 1000)); 150 var startValue = StartPenalityParameter?.Value?.Value ?? 0.5; 151 var maximumSteps = MaximumStepsParameter?.Value?.Value ?? 1000; 152 var penalityMultiplier = new DoubleValue(LinearDiscreteDoubleValueModifier.Apply(0, startValue, 1.0, (int)(Iterations / stepSize) * stepSize, 0, maximumSteps)); 133 153 PenalityMultiplierParameter.ActualValue = penalityMultiplier; 134 154 //GeneralizedExponentialDiscreteDoubleValueModifier … … 137 157 138 158 var problemData = RegressionProblemDataParameter.ActualValue; 139 var trees 140 141 var results 142 var constraints 159 var trees = SymbolicExpressionTreeParameter.ActualValue; 160 161 var results = ResultCollectionParameter.ActualValue; 162 var constraints = problemData.IntervalConstraints.EnabledConstraints; 143 163 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 144 var newDataTable 164 var newDataTable = ConstraintViolationParameter.ActualValue; 145 165 146 166 if (newDataTable.Rows.Count == 0) … … 177 197 // create new variable ranges for defined regions 178 198 IDictionary<string, Interval> regionRanges = new Dictionary<string, Interval>(); 179 foreach (var kvp in variableRanges) 180 { 181 if (kvp.Key != constraint.Target && constraint.Regions.TryGetValue(kvp.Key, out Interval val)) 182 { 183 regionRanges.Add(kvp.Key, val); 184 } 185 else 186 { 199 foreach (var kvp in variableRanges) { 200 var value = constraint.Regions.Where(r => r.VariableName == kvp.Key).FirstOrDefault(); 201 if (kvp.Key != constraint.Target && value != null) { 202 regionRanges.Add(kvp.Key, value.Interval); 203 } else { 187 204 regionRanges.Add(kvp); 188 205 } … … 192 209 if (!constraint.IsDerivative) { 193 210 resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges)); 194 } 195 else { 211 } else { 196 212 var tree = solution; 197 213 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { … … 206 222 error = 0.0; 207 223 bool satisfied = true; 208 if(!constraint.Interval.Contains(resultInterval.LowerBound)) 209 { 224 if (!constraint.Interval.Contains(resultInterval.LowerBound)) { 210 225 satisfied = false; 211 226 error += Math.Abs(resultInterval.LowerBound - constraint.Interval.LowerBound); 212 227 } 213 228 214 if (!constraint.Interval.Contains(resultInterval.UpperBound)) 215 { 229 if (!constraint.Interval.Contains(resultInterval.UpperBound)) { 216 230 satisfied = false; 217 231 error += Math.Abs(resultInterval.UpperBound - constraint.Interval.UpperBound);
Note: See TracChangeset
for help on using the changeset viewer.