Free cookie consent management tool by TermsFeed Policy Generator

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

#3073 code improvements after reintegration of branch

Location:
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.