Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/21 09:54:58 (4 years ago)
Author:
mkommend
Message:

#3105: Merge trunk changes into branch.

Location:
branches/3105_PythonFormatter
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3105_PythonFormatter

  • branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis

  • branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17579 r17918  
    3535    protected const string TargetVariableParameterName = "TargetVariable";
    3636    protected const string VariableRangesParameterName = "VariableRanges";
    37     protected const string IntervalConstraintsParameterName = "IntervalConstraints";
     37    protected const string ShapeConstraintsParameterName = "ShapeConstraints";
    3838    public string Filename { get; set; }
    3939
     
    9494      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
    9595      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
     96      problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints()));
    9697      emptyProblemData = problemData;
    9798    }
    9899    #endregion
    99100
    100     public IConstrainedValueParameter<StringValue> TargetVariableParameter {
    101       get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
    102     }
    103 
     101    #region parameter properties
     102    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
     103    public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName];
    104104    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
    105 
     105    #endregion
     106
     107    #region properties
    106108    public IntervalCollection VariableRanges {
    107109      get => VariableRangesParameter.Value;
    108110    }
     111
     112
     113    public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value;
    109114
    110115
     
    120125      }
    121126    }
    122 
    123     public IEnumerable<double> TargetVariableValues {
    124       get { return Dataset.GetDoubleValues(TargetVariable); }
    125     }
    126     public IEnumerable<double> TargetVariableTrainingValues {
    127       get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); }
    128     }
    129     public IEnumerable<double> TargetVariableTestValues {
    130       get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); }
    131     }
     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
    132132
    133133
     
    137137    private void AfterDeserialization() {
    138138      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
    139         var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     139        var intervalCollection = Dataset.GetIntervals();
    140140        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    141141      }
     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      }
     150
    142151      RegisterParameterEvents();
    143152    }
     
    163172    }
    164173
    165     public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     174    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     175      IEnumerable<ITransformation> transformations = null,
     176      IntervalCollection variableRanges = null,
     177      ShapeConstraints shapeConstraints = null)
    166178      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    167179      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    168180      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    169       var intervalCollection = CalculateDatasetIntervals(this.Dataset);
    170       Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
     181      if (variableRanges == null) {
     182        variableRanges = Dataset.GetIntervals();
     183      }
     184      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));
    171190      RegisterParameterEvents();
    172191    }
    173 
    174     private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
    175       IntervalCollection intervalCollection = new IntervalCollection();
    176       foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
    177         var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    178         intervalCollection.AddInterval(variable, variableInterval);
    179       }
    180 
    181       return intervalCollection;
    182     }
    183 
    184192    private void RegisterParameterEvents() {
    185       TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged);
    186     }
    187     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) {
    188197      OnChanged();
    189198    }
Note: See TracChangeset for help on using the changeset viewer.