Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17911


Ignore:
Timestamp:
03/23/21 15:24:58 (4 years ago)
Author:
gkronber
Message:

#3073 code improvements after reintegration of branch

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r17579 r17911  
    109109          Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", value));
    110110        }
    111 
    112111      }
    113112    }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs

    r17910 r17911  
    232232            for (var i = 1; i < currentInstr.nArguments; i++) {
    233233              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    234               result = Interval.AnalyticalQuotient(result, argumentInterval);
     234              result = Interval.AnalyticQuotient(result, argumentInterval);
    235235            }
    236236
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17902 r17911  
    146146        throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges));
    147147
    148       //Check if all variables used in the tree are present in the dataset
     148      // Check if all variables used in the tree are present in the dataset
    149149      foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName)
    150150                                   .Distinct())
     
    191191            break;
    192192          }
    193         //Elementary arithmetic rules
    194193        case OpCodes.Add: {
    195194            result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
     
    293292            for (var i = 1; i < currentInstr.nArguments; i++) {
    294293              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals);
    295               result = Interval.AnalyticalQuotient(result, argumentInterval);
     294              result = Interval.AnalyticQuotient(result, argumentInterval);
    296295            }
    297296
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r17180 r17911  
    9696    }
    9797
     98    public static IntervalCollection GetIntervals(this IDataset dataset) {
     99      IntervalCollection intervalCollection = new IntervalCollection();
     100      foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
     101        var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
     102        intervalCollection.AddInterval(variable, variableInterval);
     103      }
     104
     105      return intervalCollection;
     106    }
     107
    98108    public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues(
    99109      this IDataset ds, IEnumerable<string> factorVariables, IEnumerable<int> rows) {
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17902 r17911  
    271271    }
    272272
    273     public static Interval AnalyticalQuotient(Interval a, Interval b) {
     273    public static Interval AnalyticQuotient(Interval a, Interval b) {
    274274      var dividend = a;
    275275      var divisor = Add(Square(b), new Interval(1.0, 1.0));
     
    306306    public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); }
    307307    public static Interval Absolute(double a) { return Absolute(new Interval(a)); }
    308     public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticalQuotient(a, new Interval(b)); }
    309     public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticalQuotient(new Interval(a), b); }
    310     public static Interval AnalyticQuotient(double a, double b) { return AnalyticalQuotient(new Interval(a), new Interval(b)); }
     308    public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticQuotient(a, new Interval(b)); }
     309    public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticQuotient(new Interval(a), b); }
     310    public static Interval AnalyticQuotient(double a, double b) { return AnalyticQuotient(new Interval(a), new Interval(b)); }
    311311    #endregion
    312312  }
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs

    r17906 r17911  
    7676    private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?";
    7777    public static ShapeConstraint ParseFunctionRangeConstraint(string expr) {
    78       if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])", nameof(expr));
     78      if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])");
    7979      var start = "f".Length;
    8080      var end = expr.Length;
     
    131131          return new ShapeConstraint(interval, weight);
    132132      } else
    133         throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr));
     133        throw new ArgumentException($"The target constraint {expr} is not valid.");
    134134    }
    135135    public static ShapeConstraint ParseDerivationConstraint(string expr) {
     
    161161        if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") {
    162162          if (enumeratorNumDeriv == "" || denominatorNumDeriv == "")
    163             throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}.", nameof(expr));
     163            throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}.");
    164164          if (enumeratorNumDeriv != denominatorNumDeriv)
    165             throw new ArgumentException($"Derivation number is not equal on both sides in {expr}.", nameof(expr));
     165            throw new ArgumentException($"Derivation number is not equal on both sides in {expr}.");
    166166        }
    167167
     
    193193          return new ShapeConstraint(variable, numberOfDerivation, interval, weight);
    194194      } else
    195         throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr));
     195        throw new ArgumentException($"The derivation constraint {expr} is not valid.");
    196196    }
    197197
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17902 r17911  
    9999    #endregion
    100100
    101     public IConstrainedValueParameter<StringValue> TargetVariableParameter {
    102       get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
    103     }
    104 
     101    #region parameter properties
     102    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
     103    public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName];
    105104    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
    106 
     105    #endregion
     106
     107    #region properties
    107108    public IntervalCollection VariableRanges {
    108109      get => VariableRangesParameter.Value;
    109110    }
    110111
    111     public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter =>
    112       (IFixedValueParameter<ShapeConstraints>) Parameters[ShapeConstraintsParameterName];
    113112
    114113    public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value;
     
    126125      }
    127126    }
    128 
    129     public IEnumerable<double> TargetVariableValues {
    130       get { return Dataset.GetDoubleValues(TargetVariable); }
    131     }
    132     public IEnumerable<double> TargetVariableTrainingValues {
    133       get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); }
    134     }
    135     public IEnumerable<double> TargetVariableTestValues {
    136       get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); }
    137     }
     127    public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable);
     128    public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices);
     129    public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices);
     130    #endregion
     131
    138132
    139133
     
    143137    private void AfterDeserialization() {
    144138      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
    145         var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     139        var intervalCollection = Dataset.GetIntervals();
    146140        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    147141      }
    148       if(Parameters.ContainsKey("IntervalConstraints")) {
     142      if (Parameters.ContainsKey("IntervalConstraints")) {
    149143        var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"];
    150144        Parameters.Remove(param);
     
    178172    }
    179173
    180     public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 
     174    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
    181175      IEnumerable<ITransformation> transformations = null,
    182176      IntervalCollection variableRanges = null,
     
    186180      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    187181      if (variableRanges == null) {
    188         variableRanges = CalculateDatasetIntervals(this.Dataset);
     182        variableRanges = Dataset.GetIntervals();
    189183      }
    190184      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
     185
    191186      if (shapeConstraints == null) {
    192187        shapeConstraints = new ShapeConstraints();
    193       } 
     188      }
    194189      Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints));
    195190      RegisterParameterEvents();
    196191    }
    197 
    198     private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
    199       IntervalCollection intervalCollection = new IntervalCollection();
    200       foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
    201         var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    202         intervalCollection.AddInterval(variable, variableInterval);
    203       }
    204 
    205       return intervalCollection;
    206     }
    207 
    208192    private void RegisterParameterEvents() {
    209       TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged);
    210     }
    211     private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
     193      TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged);
     194      // VariableRanges and ShapeConstraints are fixed parameters
     195    }
     196    private void Parameter_ValueChanged(object sender, EventArgs e) {
    212197      OnChanged();
    213198    }
Note: See TracChangeset for help on using the changeset viewer.