Changeset 11872


Ignore:
Timestamp:
02/03/15 14:15:26 (3 years ago)
Author:
mkommend
Message:

#2278: Merged r11762, r11763, r11764 and r11766 into stable.

Location:
stable
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Optimizationmergedeligible
      /trunk/sources/HeuristicLab.Optimizationmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Optimization10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Optimization5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Optimization6917-7005
      /branches/Classification-Extensions/HeuristicLab.Optimization11687-11761
      /branches/CloningRefactoring/HeuristicLab.Optimization4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Optimization5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Optimization5815-6180
      /branches/DataAnalysis/HeuristicLab.Optimization4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Optimization10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Optimization6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Optimization5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Optimization6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Optimization10202-10483
      /branches/NET40/sources/HeuristicLab.Optimization5138-5162
      /branches/ParallelEngine/HeuristicLab.Optimization5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimization7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Optimization6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Optimization6828
      /branches/RuntimeOptimizer/HeuristicLab.Optimization8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization7787-8333
      /branches/SlaveShutdown/HeuristicLab.Optimization8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Optimization10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Optimization5370-5682
      /branches/Trunk/HeuristicLab.Optimization6829-6865
      /branches/UnloadJobs/HeuristicLab.Optimization9168-9215
      /branches/VNS/HeuristicLab.Optimization5594-5752
      /branches/histogram/HeuristicLab.Optimization5959-6341
  • stable/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r11170 r11872  
    227227    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    228228      values.Add("Execution Time", new TimeSpanValue(ExecutionTime));
    229       CollectResultsRecursively("", Results, values);
    230     }
    231 
    232     private void CollectResultsRecursively(string path, ResultCollection results, IDictionary<string, IItem> values) {
    233       foreach (IResult result in results) {
    234         values.Add(path + result.Name, result.Value);
    235         ResultCollection childCollection = result.Value as ResultCollection;
    236         if (childCollection != null) {
    237           CollectResultsRecursively(path + result.Name + ".", childCollection, values);
    238         }
    239       }
     229      Results.CollectResultValues(values);
    240230    }
    241231
  • stable/HeuristicLab.Optimization/3.3/ResultCollection.cs

    r11170 r11872  
    4444      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
    4545    }
     46
     47    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
     48      CollectResultValues(values, string.Empty);
     49    }
     50
     51    public virtual void CollectResultValues(IDictionary<string, IItem> values, string rootPath) {
     52      foreach (IResult result in this) {
     53        var children = GetCollectedResults(result);
     54        string path = string.Empty;
     55        if (!string.IsNullOrWhiteSpace(rootPath))
     56          path = rootPath + ".";
     57        foreach (var c in children) {
     58          if (string.IsNullOrEmpty(c.Key))
     59            values.Add(path + result.Name, c.Value);
     60          else values.Add(path + result.Name + "." + c.Key, c.Value);
     61        }
     62      }
     63    }
     64
     65    protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedResults(IResult result) {
     66      if (result.Value == null) yield break;
     67      yield return new KeyValuePair<string, IItem>(string.Empty, result.Value);
     68
     69      var resultCollection = result.Value as ResultCollection;
     70      if (resultCollection != null) {
     71        var children = new Dictionary<string, IItem>();
     72        resultCollection.CollectResultValues(children);
     73        foreach (var child in children) yield return child;
     74      }
     75    }
     76
    4677  }
    4778}
  • stable/HeuristicLab.Problems.DataAnalysis

  • stable/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r11159 r11872  
    118118    </Compile>
    119119    <Compile Include="Implementation\Classification\ClassificationEnsembleSolution.cs" />
     120    <Compile Include="Implementation\Classification\ClassificationPerformanceMeasures.cs" />
    120121    <Compile Include="Implementation\Classification\ClassificationProblemData.cs" />
    121122    <Compile Include="Implementation\Classification\ClassificationProblem.cs" />
     
    172173    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
    173174    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
     175    <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" />
    174176    <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" />
    175177    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" />
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationPerformanceMeasures.cs

    r11764 r11872  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
     
    5152    protected ClassificationPerformanceMeasuresResultCollection(bool deserializing)
    5253      : base(deserializing) {
     54    }
     55
     56    protected ClassificationPerformanceMeasuresResultCollection(ClassificationPerformanceMeasuresResultCollection original, Cloner cloner)
     57      : base(original, cloner) { }
     58    public override IDeepCloneable Clone(Cloner cloner) {
     59      return new ClassificationPerformanceMeasuresResultCollection(this, cloner);
    5360    }
    5461
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r11170 r11872  
    3636    protected const string ClassNamesParameterName = "ClassNames";
    3737    protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties";
     38    protected const string PositiveClassParameterName = "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> PositiveClassParameter {
     217      get { return (IConstrainedValueParameter<StringValue>)Parameters[PositiveClassParameterName]; }
     218    }
    215219    public IFixedValueParameter<DoubleMatrix> ClassificationPenaltiesParameter {
    216220      get { return (IFixedValueParameter<DoubleMatrix>)Parameters[ClassificationPenaltiesParameterName]; }
     
    262266      get { return ClassNamesCache; }
    263267    }
     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    }
    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(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
    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>(PositiveClassParameterName, "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      PositiveClassParameter.ValidValues.Clear();
     366      foreach (var className in ClassNames) {
     367        PositiveClassParameter.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 = PositiveClass;
     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      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
    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.PositiveClass;
     480      if (newPositivieClassName != PositiveClass) {
     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      PositiveClass = classificationProblemData.PositiveClass;
     500
    454501      for (int i = 0; i < Classes; i++) {
    455502        for (int j = 0; j < Classes; j++) {
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r11170 r11872  
    3434    private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)";
    3535    private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)";
     36    private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures";
    3637
    3738    public new IClassificationModel Model {
     
    6263      protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; }
    6364    }
     65    public ClassificationPerformanceMeasuresResultCollection ClassificationPerformanceMeasures {
     66      get { return ((ClassificationPerformanceMeasuresResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); }
     67      protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; }
     68    }
    6469    #endregion
    6570
     
    7580      Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue()));
    7681      Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
     82      Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
     83                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
     84                            new ClassificationPerformanceMeasuresResultCollection()));
    7785    }
    7886
     
    8391      if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName))
    8492        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
     93      if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) {
     94        Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
     95                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
     96                              new ClassificationPerformanceMeasuresResultCollection()));
     97        CalculateClassificationResults();
     98      }
    8599    }
    86100
     
    88102      double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values
    89103      double[] originalTrainingClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray();
     104
    90105      double[] estimatedTestClassValues = EstimatedTestClassValues.ToArray(); // cache values
    91106      double[] originalTestClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToArray();
     107
     108      var positiveClassName = ProblemData.PositiveClass;
     109      double positiveClassValue = ProblemData.GetClassValue(positiveClassName);
     110      ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue);
     111      ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue);
    92112
    93113      OnlineCalculatorError errorState;
     
    107127      TrainingNormalizedGiniCoefficient = trainingNormalizedGini;
    108128      TestNormalizedGiniCoefficient = testNormalizedGini;
     129
     130      trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues);
     131      if (trainingPerformanceCalculator.ErrorState == OnlineCalculatorError.None)
     132        ClassificationPerformanceMeasures.SetTrainingResults(trainingPerformanceCalculator);
     133
     134      testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues);
     135      if (testPerformanceCalculator.ErrorState == OnlineCalculatorError.None)
     136        ClassificationPerformanceMeasures.SetTestResults(testPerformanceCalculator);
    109137    }
    110138
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationProblemData.cs

    r11170 r11872  
    2626
    2727    IEnumerable<string> ClassNames { get; }
     28    string PositiveClass { get; set; }
    2829    IEnumerable<double> ClassValues { get; }
    2930    int Classes { get; }
Note: See TracChangeset for help on using the changeset viewer.