Changeset 18192 for branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
- Timestamp:
- 01/13/22 16:28:29 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
r18191 r18192 29 29 using HeuristicLab.Optimization; 30 30 using HeuristicLab.Parameters; 31 using HeuristicLab.PluginInfrastructure;32 31 using HeuristicLab.Problems.Instances; 33 32 using HeuristicLab.Problems.Instances.DataAnalysis; … … 40 39 41 40 #region Constants 42 private const string TreeEvaluatorParameterName = "TreeEvaluator";43 41 private const string ProblemDataParameterName = "ProblemData"; 44 42 private const string StructureTemplateParameterName = "Structure Template"; … … 60 58 61 59 #region Parameters 62 public IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator> TreeEvaluatorParameter => (IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[TreeEvaluatorParameterName];63 60 public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; 64 61 public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName]; … … 80 77 } 81 78 } 82 83 public SymbolicRegressionSingleObjectiveEvaluator TreeEvaluator => TreeEvaluatorParameter.Value;84 79 85 80 public StructureTemplate StructureTemplate => StructureTemplateParameter.Value; … … 117 112 118 113 var structureTemplate = new StructureTemplate(); 119 120 var evaluators = new ItemSet<SymbolicRegressionSingleObjectiveEvaluator>(121 ApplicationManager.Manager.GetInstances<SymbolicRegressionSingleObjectiveEvaluator>()122 .Where(x => x.Maximization == Maximization));123 124 Parameters.Add(new ConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator>(125 TreeEvaluatorParameterName,126 evaluators,127 evaluators.First()));128 114 129 115 Parameters.Add(new ValueParameter<IRegressionProblemData>( … … 202 188 ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged; 203 189 ApplyLinearScalingParameter.Value.ValueChanged += (o, e) => StructureTemplate.ApplyLinearScaling = ApplyLinearScaling; 204 OptimizeParametersParameter.Value.ValueChanged += (o, e) => {205 if (OptimizeParameters) ApplyLinearScaling = true;206 };190 //OptimizeParametersParameter.Value.ValueChanged += (o, e) => { 191 // if (OptimizeParameters) ApplyLinearScaling = true; 192 //}; 207 193 208 194 } … … 267 253 throw new ArgumentException("No structure template defined!"); 268 254 255 //create tree where all functions have been resolved (integrated) 269 256 var tree = BuildTree(templateTree, individual); 270 271 // NMSEConstraintsEvaluator sets linear scaling terms itself 272 if (ApplyLinearScaling && !(TreeEvaluator is NMSESingleObjectiveConstraintsEvaluator)) { 257 individual[SymbolicExpressionTreeName] = tree; 258 259 if (OptimizeParameters) { 260 ParameterOptimization.OptimizeTreeParameters(ProblemData, tree, interpreter: Interpreter); 261 } else if (ApplyLinearScaling) { 273 262 LinearScaling.AdjustLinearScalingParams(ProblemData, tree, Interpreter); 274 263 } 275 264 276 individual[SymbolicExpressionTreeName] = tree; 277 278 return TreeEvaluator.Evaluate( 279 tree, ProblemData, 280 ProblemData.TrainingIndices, 281 Interpreter, 282 StructureTemplate.ApplyLinearScaling, 283 EstimationLimits.Lower, 284 EstimationLimits.Upper); 265 //calculate NMSE 266 var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(tree, ProblemData.Dataset, ProblemData.TrainingIndices); 267 var boundedEstimatedValues = estimatedValues.LimitToRange(EstimationLimits.Lower, EstimationLimits.Upper); 268 var targetValues = ProblemData.TargetVariableTrainingValues; 269 var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState); 270 if (errorState != OnlineCalculatorError.None) 271 nmse = 1.0; 272 273 //evaluate constraints 274 var constraints = Enumerable.Empty<ShapeConstraint>(); 275 if (ProblemData is ShapeConstrainedRegressionProblemData scProbData) 276 constraints = scProbData.ShapeConstraints.EnabledConstraints; 277 if (constraints.Any()) { 278 var boundsEstimator = new IntervalArithBoundsEstimator(); 279 var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, boundsEstimator, ProblemData.VariableRanges, tree); 280 281 // infinite/NaN constraints 282 if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x))) 283 nmse = 1.0; 284 285 if (constraintViolations.Any(x => x > 0.0)) 286 nmse = 1.0; 287 } 288 289 return nmse; 285 290 } 286 291
Note: See TracChangeset
for help on using the changeset viewer.