Changeset 17958


Ignore:
Timestamp:
04/22/21 14:59:58 (2 weeks ago)
Author:
gkronber
Message:

#3073: refactoring ShapeConstrainedRegressionProblem as discussed with MKo and CHa

Location:
trunk
Files:
9 added
2 deleted
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r17931 r17958  
    119119  </ItemGroup>
    120120  <ItemGroup>
    121     <Compile Include="MultiObjective\NMSEConstraintsEvaluator.cs" />
     121    <Compile Include="Interfaces\IMultiObjectiveConstaintsEvaluator.cs" />
     122    <Compile Include="MultiObjective\NMSEMultiObjectiveConstraintsEvaluator.cs" />
    122123    <Compile Include="MultiObjective\PearsonRSquaredNestedTreeSizeEvaluator.cs" />
    123124    <Compile Include="MultiObjective\PearsonRSquaredNumberOfVariablesEvaluator.cs" />
    124125    <Compile Include="MultiObjective\PearsonRSquaredAverageSimilarityEvaluator.cs" />
    125126    <Compile Include="MultiObjective\PearsonRSquaredTreeComplexityEvaluator.cs" />
     127    <Compile Include="MultiObjective\ShapeConstrainedRegressionMultiObjectiveProblem.cs" />
    126128    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
    127129    <Compile Include="Plugin.cs" />
    128130    <Compile Include="ShapeConstraintsAnalyzer.cs" />
    129131    <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" />
    130     <Compile Include="SingleObjective\Evaluators\NMSEConstraintsEvaluator.cs" />
     132    <Compile Include="SingleObjective\Evaluators\NMSESingleObjectiveConstraintsEvaluator.cs" />
    131133    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" />
     134    <Compile Include="SingleObjective\ShapeConstrainedRegressionSingleObjectiveProblem.cs" />
    132135    <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" />
    133136    <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" />
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r17180 r17958  
    6060    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionMultiObjectiveProblem(this, cloner); }
    6161
    62     public SymbolicRegressionMultiObjectiveProblem()
    63       : base(new RegressionProblemData(), new SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
     62    public SymbolicRegressionMultiObjectiveProblem() : this(new RegressionProblemData(), new SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) { }
     63    public SymbolicRegressionMultiObjectiveProblem(IRegressionProblemData problemData, ISymbolicRegressionMultiObjectiveEvaluator evaluator, ISymbolicDataAnalysisSolutionCreator solutionCreator)
     64      : base(problemData, evaluator, solutionCreator) {
    6465      Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
    6566
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ShapeConstraintsAnalyzer.cs

    r17906 r17958  
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3232  [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")]
    33   [Item("ShapeConstraintsAnalyzer", "Analyzes the number of shape-constraint violations of symbolic regression models.")]
     33  [Item("ShapeConstraintsAnalyzer", "Analyzes the number of shape constraint violations of symbolic regression models.")]
    3434  public class ShapeConstraintsAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer {
    3535    private const string ProblemDataParameterName = "ProblemData";
     
    9797
    9898    public override IOperation Apply() {
    99       var problemData = RegressionProblemData;
     99      var problemData = (IShapeConstrainedRegressionProblemData)RegressionProblemData;
    100100      var trees = SymbolicExpressionTree.ToArray();
    101101
     
    115115      }
    116116
    117       var constraintUnsatisfiedSolutionsDataTable = InfeasibleSolutions;
    118       if (constraintUnsatisfiedSolutionsDataTable.Rows.Count == 0)
    119         constraintUnsatisfiedSolutionsDataTable.Rows.Add(new DataRow(InfeasibleSolutionsParameterName));
     117      var infeasibleSolutionsDataTable = InfeasibleSolutions;
     118      if (infeasibleSolutionsDataTable.Rows.Count == 0)
     119        infeasibleSolutionsDataTable.Rows.Add(new DataRow(InfeasibleSolutionsParameterName));
    120120
    121       constraintUnsatisfiedSolutionsDataTable.Rows[InfeasibleSolutionsParameterName]
     121      infeasibleSolutionsDataTable.Rows[InfeasibleSolutionsParameterName]
    122122        .Values
    123123        .Add(trees.Count(t => IntervalUtil.GetConstraintViolations(constraints, estimator, variableRanges, t).Any(x => x > 0.0)));
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r17903 r17958  
    5656    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionSingleObjectiveProblem(this, cloner); }
    5757
    58     public SymbolicRegressionSingleObjectiveProblem()
    59       : base(new RegressionProblemData(), new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
     58    public SymbolicRegressionSingleObjectiveProblem() : this(new RegressionProblemData(), new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
     59    }
     60    public SymbolicRegressionSingleObjectiveProblem(IRegressionProblemData problemData, ISymbolicRegressionSingleObjectiveEvaluator evaluator, ISymbolicDataAnalysisSolutionCreator solutionCreator) :
     61      base(problemData, evaluator, solutionCreator) {
     62
    6063      Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
    6164
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/LinearScalingGrammar.cs

    r17945 r17958  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3131  [StorableType("5A2300A0-D0FC-4F2D-B910-F86384FE9052")]
    32   [Item("IntervalArithmeticGrammar", "Represents a grammar for interval arithmetic which includes linear scaling parts implicitly.")]
    33   public class IntervalArithmeticGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
    34     public IntervalArithmeticGrammar() : base(ItemAttribute.GetName(typeof(IntervalArithmeticGrammar)),
    35       ItemAttribute.GetDescription(typeof(IntervalArithmeticGrammar))) {
     32  [Item("LinearScalingGrammar", "Represents a grammar which includes linear scaling parts implicitly.")]
     33  public class LinearScalingGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
     34    public LinearScalingGrammar() : base(ItemAttribute.GetName(typeof(LinearScalingGrammar)),
     35      ItemAttribute.GetDescription(typeof(LinearScalingGrammar))) {
    3636      Initialize();
    3737    }
    3838
    3939    [StorableConstructor]
    40     public IntervalArithmeticGrammar(StorableConstructorFlag _) : base(_) { }
     40    public LinearScalingGrammar(StorableConstructorFlag _) : base(_) { }
    4141
    42     protected IntervalArithmeticGrammar(IntervalArithmeticGrammar original, Cloner cloner) : base(original, cloner) { }
    43     public IntervalArithmeticGrammar(string name, string description) : base(name, description) { }
     42    protected LinearScalingGrammar(LinearScalingGrammar original, Cloner cloner) : base(original, cloner) { }
     43    public LinearScalingGrammar(string name, string description) : base(name, description) { }
    4444
    4545    public override IDeepCloneable Clone(Cloner cloner) {
    46       return new IntervalArithmeticGrammar(this, cloner);
     46      return new LinearScalingGrammar(this, cloner);
    4747    }
    4848
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17931 r17958  
    159159    <Compile Include="Formatters\SymbolicDataAnalysisExpressionCSharpFormatter.cs" />
    160160    <Compile Include="Grammars\DataAnalysisGrammar.cs" />
    161     <Compile Include="Grammars\IntervalArithmeticGrammar.cs" />
     161    <Compile Include="Grammars\LinearScalingGrammar.cs" />
    162162    <Compile Include="Hashing\HashExtensions.cs" />
    163163    <Compile Include="Hashing\HashUtil.cs" />
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17931 r17958  
    143143    <Compile Include="Implementation\Interval\Interval.cs" />
    144144    <Compile Include="Implementation\Interval\IntervalCollection.cs" />
     145    <Compile Include="Implementation\Interval\IShapeConstrainedRegressionProblem.cs" />
     146    <Compile Include="Implementation\Interval\IShapeConstrainedRegressionProblemData.cs" />
    145147    <Compile Include="Implementation\Interval\ShapeConstraint.cs" />
     148    <Compile Include="Implementation\Interval\ShapeConstrainedRegressionProblemData.cs" />
     149    <Compile Include="Implementation\Interval\ShapeConstrainedRegressionProblem.cs" />
    146150    <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" />
    147151    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17911 r17958  
    3535    protected const string TargetVariableParameterName = "TargetVariable";
    3636    protected const string VariableRangesParameterName = "VariableRanges";
    37     protected const string ShapeConstraintsParameterName = "ShapeConstraints";
    3837    public string Filename { get; set; }
    3938
     
    7877      defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1);
    7978      defaultDataset.Name = "Fourth-order Polynomial Function Benchmark Dataset";
    80       defaultDataset.Description = "f(x) = x^4 + x^3 + x^2 + x^1";
     79      defaultDataset.Description = "f(x) = x^4 + x^3 + x^2 + x";
    8180      defaultAllowedInputVariables = new List<string>() { "x" };
    8281      defaultTargetVariable = "y";
     
    9493      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
    9594      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
    96       problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints()));
    9795      emptyProblemData = problemData;
    9896    }
     
    10199    #region parameter properties
    102100    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
    103     public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName];
    104101    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
    105102    #endregion
     
    109106      get => VariableRangesParameter.Value;
    110107    }
    111 
    112 
    113     public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value;
    114 
    115108
    116109    public string TargetVariable {
     
    140133        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    141134      }
    142       if (Parameters.ContainsKey("IntervalConstraints")) {
    143         var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"];
    144         Parameters.Remove(param);
    145         Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, param.Value));
    146       }
    147       if (!Parameters.ContainsKey(ShapeConstraintsParameterName)) {
    148         Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, new ShapeConstraints()));
    149       }
    150135
    151136      RegisterParameterEvents();
     
    174159    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
    175160      IEnumerable<ITransformation> transformations = null,
    176       IntervalCollection variableRanges = null,
    177       ShapeConstraints shapeConstraints = null)
     161      IntervalCollection variableRanges = null)
    178162      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    179163      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
     
    183167      }
    184168      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
    185 
    186       if (shapeConstraints == null) {
    187         shapeConstraints = new ShapeConstraints();
    188       }
    189       Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints));
    190       RegisterParameterEvents();
    191169    }
    192170    private void RegisterParameterEvents() {
    193171      TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged);
    194       // VariableRanges and ShapeConstraints are fixed parameters
     172      // VariableRanges are fixed parameters
    195173    }
    196174    private void Parameter_ValueChanged(object sender, EventArgs e) {
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ShapeConstraints.cs

    r17902 r17958  
    7777    public event EventHandler Changed;
    7878
     79
    7980    private void RaiseChanged() {
    8081      var handlers = Changed;
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17902 r17958  
    2929  public interface IRegressionProblemData : IDataAnalysisProblemData {
    3030    string TargetVariable { get; set; }
    31 
    3231    IntervalCollection VariableRanges { get; }
    33     ShapeConstraints ShapeConstraints { get; }
    34 
    3532    IEnumerable<double> TargetVariableValues { get; }
    3633    IEnumerable<double> TargetVariableTrainingValues { get; }
  • trunk/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r17948 r17958  
    470470    <Compile Include="HeuristicLab-3.3\Samples\OSESGriewankSampleTest.cs" />
    471471    <Compile Include="HeuristicLab-3.3\Samples\GAGroupingProblemSampleTest.cs" />
     472    <Compile Include="HeuristicLab-3.3\Samples\ShapeConstrainedRegressionSampleTest.cs" />
    472473    <Compile Include="HeuristicLab-3.3\Samples\VnsOpSampleTest.cs" />
    473474    <Compile Include="HeuristicLab-3.3\Samples\EsGriewankSampleTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.