Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/14 19:03:36 (10 years ago)
Author:
mkommend
Message:

#1758: Merged r10173:10176 and r10540, r10541, r10543, r10545 and r11031 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis

  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r9456 r11144  
    221221    public string TargetVariable {
    222222      get { return TargetVariableParameter.Value.Value; }
     223      set {
     224        if (value == null) throw new ArgumentNullException("targetVariable", "The provided value for the targetVariable is null.");
     225        if (value == TargetVariable) return;
     226
     227
     228        var matchingParameterValue = TargetVariableParameter.ValidValues.FirstOrDefault(v => v.Value == value);
     229        if (matchingParameterValue == null) throw new ArgumentException("The provided value is not valid as the targetVariable.", "targetVariable");
     230        TargetVariableParameter.Value = matchingParameterValue;
     231      }
    223232    }
    224233
     
    408417    }
    409418    #endregion
     419
     420    protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     421      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     422      IClassificationProblemData classificationProblemData = problemData as IClassificationProblemData;
     423      if (classificationProblemData == null)
     424        throw new ArgumentException("The problem data is no classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     425
     426      var returnValue = base.IsProblemDataCompatible(classificationProblemData, out errorMessage);
     427      //check targetVariable
     428      if (classificationProblemData.InputVariables.All(var => var.Value != TargetVariable)) {
     429        errorMessage = string.Format("The target variable {0} is not present in the new problem data.", TargetVariable)
     430                       + Environment.NewLine + errorMessage;
     431        return false;
     432      }
     433
     434      var newClassValues = classificationProblemData.Dataset.GetDoubleValues(TargetVariable).Distinct().OrderBy(x => x);
     435      if (!newClassValues.SequenceEqual(ClassValues)) {
     436        errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data.");
     437        return false;
     438      }
     439
     440      return returnValue;
     441    }
     442
     443    public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {
     444      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     445      ClassificationProblemData classificationProblemData = problemData as ClassificationProblemData;
     446      if (classificationProblemData == null)
     447        throw new ArgumentException("The problem data is not a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     448
     449      base.AdjustProblemDataProperties(problemData);
     450      TargetVariable = classificationProblemData.TargetVariable;
     451      for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)
     452        ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
     453
     454      for (int i = 0; i < Classes; i++) {
     455        for (int j = 0; j < Classes; j++) {
     456          ClassificationPenaltiesParameter.Value[i, j] = classificationProblemData.GetClassificationPenalty(ClassValuesCache[i], ClassValuesCache[j]);
     457        }
     458      }
     459    }
    410460  }
    411461}
Note: See TracChangeset for help on using the changeset viewer.