Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11606


Ignore:
Timestamp:
12/01/14 14:45:57 (10 years ago)
Author:
mkommend
Message:

#2278: Added the possibility to specify a positive class in ClassificationProblemData.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r11171 r11606  
    3636    protected const string ClassNamesParameterName = "ClassNames";
    3737    protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties";
     38    protected const string PositiveClassNameParameterName = "PositiveClass";
    3839    protected const int MaximumNumberOfClasses = 100;
    3940    protected const int InspectedRowsToDetermineTargets = 2000;
     
    213214      get { return (IFixedValueParameter<StringMatrix>)Parameters[ClassNamesParameterName]; }
    214215    }
     216    public IConstrainedValueParameter<StringValue> PositiveClassNameParameter {
     217      get { return (IConstrainedValueParameter<StringValue>)Parameters[PositiveClassNameParameterName]; }
     218    }
    215219    public IFixedValueParameter<DoubleMatrix> ClassificationPenaltiesParameter {
    216220      get { return (IFixedValueParameter<DoubleMatrix>)Parameters[ClassificationPenaltiesParameterName]; }
     
    262266      get { return ClassNamesCache; }
    263267    }
     268
     269    public string PositiveClassName {
     270      get { return PositiveClassNameParameter.Value.Value; }
     271      set {
     272        var matchingValue = PositiveClassNameParameter.ValidValues.SingleOrDefault(x => x.Value == value);
     273        if (matchingValue == null) throw new ArgumentException(string.Format("{0} cannot be set as positive class.", value));
     274        PositiveClassNameParameter.Value = matchingValue;
     275      }
     276    }
    264277    #endregion
    265278
     
    270283    private void AfterDeserialization() {
    271284      RegisterParameterEvents();
     285      // BackwardsCompatibility3.4
     286      #region Backwards compatible code, remove with 3.5
     287      if (!Parameters.ContainsKey(PositiveClassNameParameterName)) {
     288        var validValues = new ItemSet<StringValue>(ClassNames.Select(s => new StringValue(s).AsReadOnly()));
     289        Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassNameParameterName,
     290          "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)", validValues, validValues.First()));
     291      }
     292      #endregion
     293
    272294    }
    273295
     
    307329      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target));
    308330      Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, ""));
     331      Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassNameParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)"));
    309332      Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, ""));
    310333
     
    340363      ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s);
    341364
     365      PositiveClassNameParameter.ValidValues.Clear();
     366      foreach (var className in ClassNames) {
     367        PositiveClassNameParameter.ValidValues.Add(new StringValue(className).AsReadOnly());
     368      }
     369
    342370      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes;
    343371      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes;
     
    411439    }
    412440    private void Parameter_ValueChanged(object sender, EventArgs e) {
     441      var oldPositiveClass = PositiveClassName;
     442      var oldClassNames = classNamesCache;
     443      var index = oldClassNames.IndexOf(oldPositiveClass);
     444
    413445      classNamesCache = null;
    414446      ClassificationPenaltiesParameter.Value.RowNames = ClassNames.Select(name => "Actual " + name);
    415447      ClassificationPenaltiesParameter.Value.ColumnNames = ClassNames.Select(name => "Estimated " + name);
     448
     449      PositiveClassNameParameter.ValidValues.Clear();
     450      foreach (var className in ClassNames) {
     451        PositiveClassNameParameter.ValidValues.Add(new StringValue(className).AsReadOnly());
     452      }
     453      PositiveClassNameParameter.Value = PositiveClassNameParameter.ValidValues.ElementAt(index);
     454
    416455      OnChanged();
    417456    }
     
    435474      if (!newClassValues.SequenceEqual(ClassValues)) {
    436475        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.PositiveClassName;
     480      if (newPositivieClassName != PositiveClassName) {
     481        errorMessage = errorMessage + string.Format("The positive class differs in the provided classification problem data.");
     482        returnValue = false;
    438483      }
    439484
     
    452497        ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
    453498
     499      PositiveClassName = classificationProblemData.PositiveClassName;
     500
    454501      for (int i = 0; i < Classes; i++) {
    455502        for (int j = 0; j < Classes; j++) {
Note: See TracChangeset for help on using the changeset viewer.