Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/17/19 14:37:55 (6 years ago)
Author:
chaider
Message:

#2971 Several chanages regarding review comments

Location:
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator.cs

    r16781 r16800  
    6161
    6262      //var constraints = IntervalConstraintsParser.Parse(((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Value);
    63       var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.IsChecked);
     63      var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled);
    6464      var intervalInterpreter = new IntervalInterpreter();
    65       var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals;
     65      var variableRanges = ((RegressionProblemData) problemData).VariableRangesParameter.Value.VariableIntervals;
    6666
    6767
     
    9292
    9393    private static bool HasConstraintVioluations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
    94       Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) {
     94      IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution) {
    9595      foreach (var constraint in constraints) {
    9696        if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator.cs

    r16756 r16800  
    6464      var variableRanges = ((RegressionProblemData)problemData).VariableRangesParameter.Value.VariableIntervals;
    6565
    66 
    67       //foreach (var constraint in constraints) {
    68       //  if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
    69       //    throw new ArgumentException($"The given variable {constraint.Variable} in the constraint does not exists in the model.", nameof(IntervalConstraintsParser));
    70       //  if (!constraint.IsDerivation) {
    71       //    var res = intervalInterpreter.GetSymbolicExressionTreeInterval(solution, variableRanges);
    72       //    if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    73       //      constraint.InclusiveUpperBound)) {
    74       //      return 0;
    75       //    }
    76       //  } else {
    77       //    var tree = solution;
    78       //    for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
    79       //      tree = DerivativeCalculator.Derive(tree, constraint.Variable);
    80       //    }
    81       //    var res = intervalInterpreter.GetSymbolicExressionTreeInterval(tree, variableRanges);
    82       //    if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    83       //      constraint.InclusiveUpperBound)) {
    84       //      return 0;
    85       //    }
    86       //  }
    87       //}
    88       // TODO
    89       // m = new SymbolicRegressionModel(...)
    90       // m.Scale();
    91 
    92       // var e = m.GetEstimatedValues (TRAINING)
    93       // OnlinePearsonCalc.Calculate(e, TARGET_TRAIING)
    94 
    95       // scaledTree = model.Tree;
    96 
    97       // constraints mit scaledTree berechnen (auch die Ableitungen)
    98 
    9966      double r;
    10067      if (applyLinearScaling) {
     
    142109
    143110    private static bool CheckConstraintsViolations(IEnumerable<IntervalConstraint> constraints, IntervalInterpreter intervalInterpreter,
    144       Dictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {
     111      IDictionary<string, Interval> variableRanges, ISymbolicExpressionTree solution, out double r) {
    145112      foreach (var constraint in constraints) {
    146113        if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable))
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionConstraintAnalyzer.cs

    r16780 r16800  
    3737  public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeAnalyzer {
    3838    private const string ConstraintViolationsResultName = "Constraint Violations";
    39 
    4039    private const string ProblemDataParameterName = "ProblemData";
    4140    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    4241
    4342    #region parameter properties
     43
    4444    public ILookupParameter<RegressionProblemData> RegressionProblemDataParameter {
    45       get { return (ILookupParameter<RegressionProblemData>)Parameters[ProblemDataParameterName]; }
     45      get { return (ILookupParameter<RegressionProblemData>) Parameters[ProblemDataParameterName]; }
    4646    }
     47
    4748    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
    48       get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
     49      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>) Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
    4950    }
     51
    5052    #endregion
     53
    5154    #region properties
    5255
     
    5861      get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; }
    5962    }
     63
    6064    #endregion
    6165
    62     public virtual bool EnabledByDefault {
    63       get { return false; }
    64     }
     66    public override bool EnabledByDefault => false;
    6567
    6668    [StorableConstructor]
     
    6870    }
    6971
    70     protected SymbolicRegressionConstraintAnalyzer(SymbolicRegressionConstraintAnalyzer original, Cloner cloner)
    71       : base(original, cloner) {
     72    protected SymbolicRegressionConstraintAnalyzer(SymbolicRegressionConstraintAnalyzer original, Cloner cloner) : base(original, cloner) {
    7273    }
    7374
     
    8586    }
    8687
    87     public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicExpressionTree model,
    88       IRegressionProblemData problemData) {
    89       var constraints = ((RegressionProblemData)problemData).IntervalConstraintsParameter.Value.Constraints.Where(x => x.IsChecked);
     88    public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicExpressionTree model, IRegressionProblemData problemData) {
     89      var constraints = problemData.IntervalConstraints.Constraints.Where(x => x.Enabled);
    9090      var constraintViolations = new Dictionary<IntervalConstraint, bool>();
    91       var variableRanges = ((RegressionProblemData)problemData).VariableRanges.VariableIntervals;
    92 
     91      var variableRanges = problemData.VariableRanges.VariableIntervals;
    9392      foreach (var constraint in constraints) {
    9493        if (!constraintViolations.ContainsKey(constraint)) {
     
    10099    }
    101100
    102     public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicRegressionModel model,
    103       IRegressionProblemData problemData) {
     101    public static Dictionary<IntervalConstraint, bool> CheckConstraints(ISymbolicRegressionModel model, IRegressionProblemData problemData) {
    104102      return CheckConstraints(model.SymbolicExpressionTree, problemData);
    105103    }
    106104
    107     public static bool CheckConstraint(ISymbolicExpressionTree model, Dictionary<string, Interval> variableRanges,
    108       IntervalConstraint constraint) {
     105    public static bool CheckConstraint(ISymbolicExpressionTree model, IDictionary<string, Interval> variableRanges, IntervalConstraint constraint) {
    109106      var intervalInterpreter = new IntervalInterpreter();
    110       if (constraint.Variable != null) {
    111         if (!constraint.IsDerivation) {
    112           var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(model,
    113             variableRanges);
    114           if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    115             constraint.InclusiveUpperBound)) {
    116             return false;
    117           }
    118         } else {
    119           var dTree = model;
    120           for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
    121             dTree = DerivativeCalculator.Derive(dTree, constraint.Variable);
    122           }
    123           var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree,
    124             variableRanges);
    125           if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound,
    126             constraint.InclusiveUpperBound)) {
    127             return false;
    128           }
     107      if (!constraint.IsDerivation) {
     108        var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(model, variableRanges);
     109        if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, constraint.InclusiveUpperBound)) {
     110          return false;
     111        }
     112      } else {
     113        var dTree = model;
     114        for (var i = 0; i < constraint.NumberOfDerivation; ++i) {
     115          dTree = DerivativeCalculator.Derive(dTree, constraint.Variable);
     116        }
     117
     118        var res = intervalInterpreter.GetSymbolicExpressionTreeInterval(dTree, variableRanges);
     119        if (!constraint.Interval.Contains(res, constraint.InclusiveLowerBound, constraint.InclusiveUpperBound)) {
     120          return false;
    129121        }
    130122      }
     123
    131124      return true;
    132125    }
    133126
    134     static bool CheckConstraint(ISymbolicRegressionModel model, Dictionary<string, Interval> variableRanges, IntervalConstraint constraint) {
     127    static bool CheckConstraint(ISymbolicRegressionModel model, IDictionary<string, Interval> variableRanges, IntervalConstraint constraint) {
    135128      return CheckConstraint(model.SymbolicExpressionTree, variableRanges, constraint);
    136129    }
     
    140133      if (!results.ContainsKey(ConstraintViolationsResultName)) {
    141134        var newDataTable = new DataTable(ConstraintViolationsResultName);
    142         results.Add(new Result(ConstraintViolationsResultName, "Chart displaying the constraint violations.",
    143           newDataTable));
     135        results.Add(new Result(ConstraintViolationsResultName, "Chart displaying the constraint violations.", newDataTable));
    144136      }
    145       var dataTable = (DataTable)results[ConstraintViolationsResultName].Value;
     137
     138      var dataTable = (DataTable) results[ConstraintViolationsResultName].Value;
    146139      var problemData = RegressionProblemData;
    147140      var constraintViolations = new Dictionary<string, int>();
    148 
    149       var constraints = problemData.IntervalConstraintsParameter.Value.Constraints.Where(x => x.IsChecked);
    150 
     141      var constraints = problemData.IntervalConstraintsParameter.Value.Constraints.Where(x => x.Enabled);
    151142      if (dataTable.Rows.Count == 0) {
    152143        foreach (var constraint in constraints) {
     
    163154      foreach (var tree in this.SymbolicExpressionTree) {
    164155        var checkedConstraints = CheckConstraints(tree, problemData);
    165 
    166156        foreach (var kvp in checkedConstraints) {
    167           if (!kvp.Value)
    168             constraintViolations[kvp.Key.Expression]++;
     157          if (!kvp.Value) constraintViolations[kvp.Key.Expression]++;
    169158        }
    170159      }
     
    173162        dataTable.Rows[kvp.Key].Values.Add(kvp.Value);
    174163      }
     164
    175165      return base.Apply();
    176166    }
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r16761 r16800  
    2121
    2222using System;
     23using System.Collections;
     24using System.Collections.Generic;
    2325using System.Linq;
    2426using HEAL.Attic;
     
    5052
    5153    private const string IntervalEvaluationResultName = "Interval Evaluation";
    52     private const string EstimatedDerivationInterval = "Interval";
    5354
    5455    public new ISymbolicRegressionModel Model {
     
    151152        estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
    152153        Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
     154        Add(new Result(IntervalEvaluationResultName, "Results concerning the derivation of symbolic regression solution", GetIntervalEvaluations()));
    153155        CalculateResults();
    154156      }
     
    163165      var intervalEvaluation = new NamedIntervals();
    164166      var interpreter = new IntervalInterpreter();
    165       var variableRanges = (ProblemData as RegressionProblemData)?.VariableRangesParameter.Value.VariableIntervals;
     167      var variableRanges = ProblemData.VariableRanges.VariableIntervals;
    166168
    167169      if (variableRanges != null) {
    168         intervalEvaluation.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound));
    169         intervalEvaluation.Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));
     170        intervalEvaluation.VariableIntervals.Add($"Target {ProblemData.TargetVariable}", new Interval(variableRanges[ProblemData.TargetVariable].LowerBound, variableRanges[ProblemData.TargetVariable].UpperBound));
     171        intervalEvaluation.VariableIntervals.Add("Modell Interval", interpreter.GetSymbolicExpressionTreeInterval(Model.SymbolicExpressionTree, variableRanges));
    170172     
    171173        foreach (var derivate in variableRanges) {
     
    174176            var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derived, variableRanges);
    175177
    176             intervalEvaluation.Add(" \u2202f/\u2202" + derivate.Key,
     178            intervalEvaluation.VariableIntervals.Add(" \u2202f/\u2202" + derivate.Key,
    177179              new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound));
    178180          }
Note: See TracChangeset for help on using the changeset viewer.