Changeset 11872 for stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
- Timestamp:
- 02/03/15 14:15:26 (10 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11762-11763,11766
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r11170 r11872 36 36 protected const string ClassNamesParameterName = "ClassNames"; 37 37 protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties"; 38 protected const string PositiveClassParameterName = "PositiveClass"; 38 39 protected const int MaximumNumberOfClasses = 100; 39 40 protected const int InspectedRowsToDetermineTargets = 2000; … … 213 214 get { return (IFixedValueParameter<StringMatrix>)Parameters[ClassNamesParameterName]; } 214 215 } 216 public IConstrainedValueParameter<StringValue> PositiveClassParameter { 217 get { return (IConstrainedValueParameter<StringValue>)Parameters[PositiveClassParameterName]; } 218 } 215 219 public IFixedValueParameter<DoubleMatrix> ClassificationPenaltiesParameter { 216 220 get { return (IFixedValueParameter<DoubleMatrix>)Parameters[ClassificationPenaltiesParameterName]; } … … 262 266 get { return ClassNamesCache; } 263 267 } 268 269 public string PositiveClass { 270 get { return PositiveClassParameter.Value.Value; } 271 set { 272 var matchingValue = PositiveClassParameter.ValidValues.SingleOrDefault(x => x.Value == value); 273 if (matchingValue == null) throw new ArgumentException(string.Format("{0} cannot be set as positive class.", value)); 274 PositiveClassParameter.Value = matchingValue; 275 } 276 } 264 277 #endregion 265 278 … … 270 283 private void AfterDeserialization() { 271 284 RegisterParameterEvents(); 285 // BackwardsCompatibility3.4 286 #region Backwards compatible code, remove with 3.5 287 if (!Parameters.ContainsKey(PositiveClassParameterName)) { 288 var validValues = new ItemSet<StringValue>(ClassNames.Select(s => new StringValue(s).AsReadOnly())); 289 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, 290 "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)", validValues, validValues.First())); 291 } 292 #endregion 293 272 294 } 273 295 … … 307 329 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target)); 308 330 Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "")); 331 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 309 332 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 310 333 … … 340 363 ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s); 341 364 365 PositiveClassParameter.ValidValues.Clear(); 366 foreach (var className in ClassNames) { 367 PositiveClassParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 368 } 369 342 370 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes; 343 371 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes; … … 411 439 } 412 440 private void Parameter_ValueChanged(object sender, EventArgs e) { 441 var oldPositiveClass = PositiveClass; 442 var oldClassNames = classNamesCache; 443 var index = oldClassNames.IndexOf(oldPositiveClass); 444 413 445 classNamesCache = null; 414 446 ClassificationPenaltiesParameter.Value.RowNames = ClassNames.Select(name => "Actual " + name); 415 447 ClassificationPenaltiesParameter.Value.ColumnNames = ClassNames.Select(name => "Estimated " + name); 448 449 PositiveClassParameter.ValidValues.Clear(); 450 foreach (var className in ClassNames) { 451 PositiveClassParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 452 } 453 PositiveClassParameter.Value = PositiveClassParameter.ValidValues.ElementAt(index); 454 416 455 OnChanged(); 417 456 } … … 435 474 if (!newClassValues.SequenceEqual(ClassValues)) { 436 475 errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data."); 437 return false; 476 returnValue = false; 477 } 478 479 var newPositivieClassName = classificationProblemData.PositiveClass; 480 if (newPositivieClassName != PositiveClass) { 481 errorMessage = errorMessage + string.Format("The positive class differs in the provided classification problem data."); 482 returnValue = false; 438 483 } 439 484 … … 452 497 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i); 453 498 499 PositiveClass = classificationProblemData.PositiveClass; 500 454 501 for (int i = 0; i < Classes; i++) { 455 502 for (int j = 0; j < Classes; j++) {
Note: See TracChangeset
for help on using the changeset viewer.