Changeset 18006 for branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Timestamp:
- 07/13/21 10:55:09 (3 years ago)
- Location:
- branches/3087_Ceres_Integration
- Files:
-
- 4 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3087_Ceres_Integration
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17579 r18006 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string IntervalConstraintsParameterName = "IntervalConstraints";38 37 public string Filename { get; set; } 39 38 … … 78 77 defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1); 79 78 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"; 81 80 defaultAllowedInputVariables = new List<string>() { "x" }; 82 81 defaultTargetVariable = "y"; … … 98 97 #endregion 99 98 100 public IConstrainedValueParameter<StringValue> TargetVariableParameter { 101 get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 102 } 99 #region parameter properties 100 public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; 101 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 102 #endregion 103 103 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 104 #region properties 106 105 public IntervalCollection VariableRanges { 107 106 get => VariableRangesParameter.Value; 108 107 } 109 110 108 111 109 public string TargetVariable { … … 120 118 } 121 119 } 120 public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable); 121 public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices); 122 public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices); 123 #endregion 122 124 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 }132 125 133 126 … … 137 130 private void AfterDeserialization() { 138 131 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 139 var intervalCollection = CalculateDatasetIntervals(this.Dataset);140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));132 var variableRanges = Dataset.GetVariableRanges(); 133 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 141 134 } 135 142 136 RegisterParameterEvents(); 143 137 } … … 163 157 } 164 158 165 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 159 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 160 IEnumerable<ITransformation> transformations = null, 161 IntervalCollection variableRanges = null) 166 162 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 167 163 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 168 164 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)); 171 RegisterParameterEvents(); 165 if (variableRanges == null) { 166 variableRanges = Dataset.GetVariableRanges(); 167 } 168 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 172 169 } 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; 170 private void RegisterParameterEvents() { 171 TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged); 172 // VariableRanges are fixed parameters 182 173 } 183 184 private void RegisterParameterEvents() { 185 TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged); 186 } 187 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 174 private void Parameter_ValueChanged(object sender, EventArgs e) { 188 175 OnChanged(); 189 176 }
Note: See TracChangeset
for help on using the changeset viewer.