Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17899 for branches


Ignore:
Timestamp:
03/16/21 13:54:22 (4 years ago)
Author:
gkronber
Message:

#3076 refactoring for branch reintegration

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  
    3333
    3434namespace 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.")]
    3737  [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];
    4544
    4645    public IValueParameter<IBoundsEstimator> BoundsEstimatorParameter =>
    4746      (IValueParameter<IBoundsEstimator>)Parameters[BoundsEstimatorParameterName];
    4847
    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      }
    5262    }
    5363
     
    5969    #region Constructors
    6070
    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)));
    6373      Parameters.Add(new ValueParameter<IBoundsEstimator>(BoundsEstimatorParameterName, new IntervalArithBoundsEstimator()));
     74      maximization = new bool[2];
    6475    }
    6576
    6677    [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    }
    7183
    7284    #endregion
    7385
    7486    [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() { }
    8288
    8389    public override IDeepCloneable Clone(Cloner cloner) {
    84       return new SymbolicRegressionMultiObjectiveMultiSoftConstraintEvaluator(this, cloner);
     90      return new NMSEConstraintsEvaluator(this, cloner);
    8591    }
    8692
     
    123129          OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
    124130            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          }
    130138        }
    131139      }
     
    190198    }
    191199
    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;
    206201  }
    207202}
  • branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSEConstraintsEvaluator.cs

    r17898 r17899  
    3232
    3333namespace 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.")]
    3535  [StorableType("27473973-DD8D-4375-997D-942E2280AE8E")]
    36   public class SymbolicRegressionSingleObjectiveConstraintEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
     36  public class NMSEConstraintsEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3737    #region Parameter/Properties
    3838
     
    9191
    9292    [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() {
    9999      Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName,
    100100        "Define whether optimization of numeric parameters is active or not (default: false).", new BoolValue(false)));
     
    110110
    111111    [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() { }
    137113
    138114    public override IDeepCloneable Clone(Cloner cloner) {
    139       return new SymbolicRegressionSingleObjectiveConstraintEvaluator(this, cloner);
     115      return new NMSEConstraintsEvaluator(this, cloner);
    140116    }
    141117
  • branches/3076_IA_evaluators_analyzers_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs

    r17898 r17899  
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3232  [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")]
    33   [Item("Symbolic regression constraint analyser", "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.")]
    3434  public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer {
    3535    private const string ProblemDataParameterName = "ProblemData";
     
    9494
    9595    [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() { }
    10897
    10998    public override IOperation Apply() {
Note: See TracChangeset for help on using the changeset viewer.