Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17892 for branches


Ignore:
Timestamp:
03/12/21 16:42:21 (4 years ago)
Author:
gkronber
Message:

#3076: refactoring to prepare for trunk reintegration

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  
    176176    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveConstraintEvaluator.cs" />
    177177    <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" />
    178     <Compile Include="SymbolicRegressionSplittingAnalyzer.cs" />
    179178    <Compile Include="SymbolicRegressionConstraintAnalyzer.cs" />
    180179    <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" />
  • branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator.cs

    r17882 r17892  
    2222#endregion
    2323
    24 using System;
    2524using System.Collections.Generic;
    2625using System.Linq;
     
    3736  [StorableType("8E9D76B7-ED9C-43E7-9898-01FBD3633880")]
    3837  public class
    39     SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator
    40   {
     38    SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    4139    public const string DimensionsParameterName = "Dimensions";
    4240    private const string BoundsEstimatorParameterName = "Bounds estimator";
    4341
    4442    public IFixedValueParameter<IntValue> DimensionsParameter =>
    45       (IFixedValueParameter<IntValue>) Parameters[DimensionsParameterName];
     43      (IFixedValueParameter<IntValue>)Parameters[DimensionsParameterName];
    4644
    4745    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    }
    4952
    5053    public IBoundsEstimator BoundsEstimator {
     
    5760    public SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator() {
    5861      Parameters.Add(new FixedValueParameter<IntValue>(DimensionsParameterName, new IntValue(2)));
    59       Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IABoundsEstimator()));
     62      Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator()));
    6063    }
    6164
     
    7477
    7578      if (!Parameters.ContainsKey(BoundsEstimatorParameterName))
    76         Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IABoundsEstimator()));
     79        Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator()));
    7780    }
    7881
     
    121124            if (node.Symbol.Name == "Offset") {
    122125              node.RemoveSubtree(1);
    123               var alphaNode = new ConstantTreeNode(new Constant()) {Value = alpha};
     126              var alphaNode = new ConstantTreeNode(new Constant()) { Value = alpha };
    124127              node.AddSubtree(alphaNode);
    125128            } else if (node.Symbol.Name == "Scaling") {
    126129              node.RemoveSubtree(1);
    127               var betaNode = new ConstantTreeNode(new Constant()) {Value = beta};
     130              var betaNode = new ConstantTreeNode(new Constant()) { Value = beta };
    128131              node.AddSubtree(betaNode);
    129132            }
     
    165168      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    166169      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);
    168171      var intervalCollection = problemData.VariableRanges;
    169172
     
    177180        nmse = 1.0;
    178181
    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)) {
    183186          objectives.Add(double.MaxValue);
    184187        } else {
    185           objectives.Add(result);
     188          objectives.Add(violation);
    186189        }
    187190      }
    188      
     191
    189192      return objectives.ToArray();
    190193    }
     
    197200    public override IEnumerable<bool> Maximization {
    198201      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
    201205
    202206        return objectives;
  • branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintEvaluator.cs

    r17878 r17892  
    11using System;
    2 using System.CodeDom;
    32using System.Collections.Generic;
    43using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    74using HEAL.Attic;
    85using HeuristicLab.Common;
     
    9693        "Define whether the constraints are penalized by soft or hard constraints.", new BoolValue(false)));
    9794      Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName,
    98         "Select the Boundsestimator.", new IABoundsEstimator()));
     95        "Select the Boundsestimator.", new IntervalArithBoundsEstimator()));
    9996      Parameters.Add(new FixedValueParameter<DoubleValue>(MaximumPenaltyFactorParamterName,
    10097        "Specify how hard constraints violations should be punished", new DoubleValue(1.5)));
     
    120117      if (!Parameters.ContainsKey(BoundsEstimatorParameterName))
    121118        Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName,
    122           "Select the Boundsestimator.", new IABoundsEstimator()));
     119          "Select the Boundsestimator.", new IntervalArithBoundsEstimator()));
    123120
    124121      if (!Parameters.ContainsKey(MaximumPenaltyFactorParamterName)) {
     
    197194      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    198195      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    199       var constraints = problemData.IntervalConstraints.EnabledConstraints;
     196      var constraints = problemData.ShapeConstraints.EnabledConstraints;
    200197      var intervalCollection = problemData.VariableRanges;
    201198
     
    208205      }
    209206
    210       var constraintResults = IntervalUtil.IntervalConstraintsViolation(constraints, estimator, intervalCollection, solution);
     207      var constraintResults = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, solution);
    211208
    212209      if (constraintResults.Any(x => double.IsNaN(x) || double.IsInfinity(x))) {
     
    217214      if (useSoftConstraints) {
    218215        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));
    220217
    221218        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  
    9696        changed = true;
    9797      }
    98 
    99       if (!Operators.OfType<SymbolicRegressionSplittingAnalyzer>().Any()) {
    100         Operators.Add(new SymbolicRegressionSplittingAnalyzer());
    101         changed = true;
    102       }
    10398      if (changed) {
    10499        ParameterizeOperators();
     
    124119      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
    125120      Operators.Add(new SymbolicRegressionConstraintAnalyzer());
    126       Operators.Add(new SymbolicRegressionSplittingAnalyzer());
    127121      Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" });
    128122      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;
     1using System.Linq;
    62using HEAL.Attic;
    73using HeuristicLab.Analysis;
    84using HeuristicLab.Common;
    95using HeuristicLab.Core;
    10 using HeuristicLab.Data;
    116using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    127using HeuristicLab.Optimization;
    13 using HeuristicLab.Optimization.Operators;
    148using HeuristicLab.Parameters;
    159
     
    3731    public static int Iterations { get; set; } = 0;
    3832
    39     public IBoundsEstimator BoundsEstimator { get; set; } = new IABoundsEstimator();
     33    public IBoundsEstimator BoundsEstimator { get; set; } = new IntervalArithBoundsEstimator();
    4034
    4135    [StorableConstructor]
     
    10599
    106100      var results = ResultCollectionParameter.ActualValue;
    107       var constraints = problemData.IntervalConstraints.EnabledConstraints;
     101      var constraints = problemData.ShapeConstraints.EnabledConstraints;
    108102      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
    109103      var intervalCollection = problemData.VariableRanges;
    110104      var newDataTable = ConstraintViolationParameter.ActualValue;
    111       var solutions = this.SymbolicExpressionTree.ToArray();
     105      var solutions = SymbolicExpressionTree.ToArray();
    112106
    113107      if (newDataTable.Rows.Count == 0)
    114108        foreach (var constraint in constraints)
    115           newDataTable.Rows.Add(new DataRow(constraint.Expression));
     109          newDataTable.Rows.Add(new DataRow(constraint.ToString()));
    116110
    117111      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);
    119113
    120         newDataTable.Rows[constraint.Expression].Values.Add(violations);
     114        newDataTable.Rows[constraint.ToString()].Values.Add(violations);
    121115      }
    122116
     
    127121      constraintUnsatisfiedSolutionsDataTable.Rows[ConstraintUnsatisfiedSolutionsParameterName]
    128122        .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)));
    130124
    131125      return base.Apply();
  • branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSplittingAnalyzer.cs

    r17821 r17892  
    155155        var problemData = RegressionProblemDataParameter.ActualValue;
    156156        var trees = SymbolicExpressionTreeParameter.ActualValue;
    157         var constraints = problemData.IntervalConstraints.EnabledConstraints;
     157        var constraints = problemData.ShapeConstraints.EnabledConstraints;
    158158        var intervalCollection = problemData.VariableRanges;
    159         var estimator = new IABoundsEstimator();
    160         var splittingEstimator = new IABoundsEstimator {UseIntervalSplitting = true, SplittingIterations = 12};
     159        var estimator = new IntervalArithBoundsEstimator();
     160        var splittingEstimator = new IntervalArithBoundsEstimator {UseIntervalSplitting = true, SplittingIterations = 12};
    161161
    162162        foreach (var solution in trees) {
Note: See TracChangeset for help on using the changeset viewer.