- Timestamp:
- 03/23/21 15:24:58 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17902 r17911 99 99 #endregion 100 100 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]; 105 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 106 105 #endregion 106 107 #region properties 107 108 public IntervalCollection VariableRanges { 108 109 get => VariableRangesParameter.Value; 109 110 } 110 111 111 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter =>112 (IFixedValueParameter<ShapeConstraints>) Parameters[ShapeConstraintsParameterName];113 112 114 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; … … 126 125 } 127 126 } 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 138 132 139 133 … … 143 137 private void AfterDeserialization() { 144 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 145 var intervalCollection = CalculateDatasetIntervals(this.Dataset);139 var intervalCollection = Dataset.GetIntervals(); 146 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 147 141 } 148 if (Parameters.ContainsKey("IntervalConstraints")) {142 if (Parameters.ContainsKey("IntervalConstraints")) { 149 143 var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"]; 150 144 Parameters.Remove(param); … … 178 172 } 179 173 180 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 174 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 181 175 IEnumerable<ITransformation> transformations = null, 182 176 IntervalCollection variableRanges = null, … … 186 180 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First())); 187 181 if (variableRanges == null) { 188 variableRanges = CalculateDatasetIntervals(this.Dataset);182 variableRanges = Dataset.GetIntervals(); 189 183 } 190 184 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 185 191 186 if (shapeConstraints == null) { 192 187 shapeConstraints = new ShapeConstraints(); 193 } 188 } 194 189 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints)); 195 190 RegisterParameterEvents(); 196 191 } 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 variables201 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));202 intervalCollection.AddInterval(variable, variableInterval);203 }204 205 return intervalCollection;206 }207 208 192 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) { 212 197 OnChanged(); 213 198 }
Note: See TracChangeset
for help on using the changeset viewer.