Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18192


Ignore:
Timestamp:
01/13/22 16:28:29 (2 years ago)
Author:
mkommend
Message:

#3136:

  • Extracted parameter optimization into dedicated helper utility.
  • Implemented evaluation in the structured SymReg problem directly.
Location:
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r18146 r18192  
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    4848    <Prefer32Bit>false</Prefer32Bit>
     49    <LangVersion>default</LangVersion>
    4950  </PropertyGroup>
    5051  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5758    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    5859    <Prefer32Bit>false</Prefer32Bit>
     60    <LangVersion>default</LangVersion>
    5961  </PropertyGroup>
    6062  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
     
    6769    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    6870    <Prefer32Bit>false</Prefer32Bit>
     71    <LangVersion>default</LangVersion>
    6972  </PropertyGroup>
    7073  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
     
    7780    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    7881    <Prefer32Bit>false</Prefer32Bit>
     82    <LangVersion>default</LangVersion>
    7983  </PropertyGroup>
    8084  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    8791    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    8892    <Prefer32Bit>false</Prefer32Bit>
     93    <LangVersion>default</LangVersion>
    8994  </PropertyGroup>
    9095  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     
    97102    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    98103    <Prefer32Bit>false</Prefer32Bit>
     104    <LangVersion>default</LangVersion>
    99105  </PropertyGroup>
    100106  <ItemGroup>
     
    127133    <Compile Include="MultiObjective\ShapeConstrainedRegressionMultiObjectiveProblem.cs" />
    128134    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
     135    <Compile Include="ParameterOptimization.cs" />
    129136    <Compile Include="Plugin.cs" />
    130137    <Compile Include="ShapeConstraintsAnalyzer.cs" />
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18191 r18192  
    2929using HeuristicLab.Optimization;
    3030using HeuristicLab.Parameters;
    31 using HeuristicLab.PluginInfrastructure;
    3231using HeuristicLab.Problems.Instances;
    3332using HeuristicLab.Problems.Instances.DataAnalysis;
     
    4039
    4140    #region Constants
    42     private const string TreeEvaluatorParameterName = "TreeEvaluator";
    4341    private const string ProblemDataParameterName = "ProblemData";
    4442    private const string StructureTemplateParameterName = "Structure Template";
     
    6058
    6159    #region Parameters
    62     public IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator> TreeEvaluatorParameter => (IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[TreeEvaluatorParameterName];
    6360    public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName];
    6461    public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName];
     
    8077      }
    8178    }
    82 
    83     public SymbolicRegressionSingleObjectiveEvaluator TreeEvaluator => TreeEvaluatorParameter.Value;
    8479
    8580    public StructureTemplate StructureTemplate => StructureTemplateParameter.Value;
     
    117112
    118113      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()));
    128114
    129115      Parameters.Add(new ValueParameter<IRegressionProblemData>(
     
    202188      ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged;
    203189      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      //};
    207193
    208194    }
     
    267253        throw new ArgumentException("No structure template defined!");
    268254
     255      //create tree where all functions have been resolved (integrated)
    269256      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) {
    273262        LinearScaling.AdjustLinearScalingParams(ProblemData, tree, Interpreter);
    274263      }
    275264
    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;
    285290    }
    286291
Note: See TracChangeset for help on using the changeset viewer.