Changeset 17918 for branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Timestamp:
- 03/29/21 09:54:58 (4 years ago)
- Location:
- branches/3105_PythonFormatter
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3105_PythonFormatter
- Property svn:mergeinfo changed
/trunk (added) merged: 17845,17856,17858-17859,17861,17867,17871-17873,17888-17889,17902-17903,17906-17914
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17579 r17918 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string IntervalConstraintsParameterName = "IntervalConstraints";37 protected const string ShapeConstraintsParameterName = "ShapeConstraints"; 38 38 public string Filename { get; set; } 39 39 … … 94 94 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 95 95 problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection())); 96 problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints())); 96 97 emptyProblemData = problemData; 97 98 } 98 99 #endregion 99 100 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]; 104 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 105 #endregion 106 107 #region properties 106 108 public IntervalCollection VariableRanges { 107 109 get => VariableRangesParameter.Value; 108 110 } 111 112 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; 109 114 110 115 … … 120 125 } 121 126 } 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 132 132 133 133 … … 137 137 private void AfterDeserialization() { 138 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 139 var intervalCollection = CalculateDatasetIntervals(this.Dataset);139 var intervalCollection = Dataset.GetIntervals(); 140 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 141 141 } 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 142 151 RegisterParameterEvents(); 143 152 } … … 163 172 } 164 173 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) 166 178 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 167 179 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 168 180 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)); 171 190 RegisterParameterEvents(); 172 191 } 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 variables177 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));178 intervalCollection.AddInterval(variable, variableInterval);179 }180 181 return intervalCollection;182 }183 184 192 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) { 188 197 OnChanged(); 189 198 }
Note: See TracChangeset
for help on using the changeset viewer.