Changeset 6520


Ignore:
Timestamp:
07/06/11 21:13:34 (8 years ago)
Author:
gkronber
Message:

#1450 implemented menu item to merge all data analysis solutions in a run collection into ensemble solutions and fixed a few bugs related to ensemble solutions.

Location:
trunk/sources
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs

    r6239 r6520  
    7878          dataGridView.ColumnCount = 1;
    7979        } else {
    80           dataGridView.ColumnCount = Content.ProblemData.Classes;
    81           dataGridView.RowCount = Content.ProblemData.Classes;
     80          dataGridView.ColumnCount = Content.ProblemData.Classes + 1;
     81          dataGridView.RowCount = Content.ProblemData.Classes + 1;
    8282
    8383          int i = 0;
     
    8787            i++;
    8888          }
     89          dataGridView.Columns[i].HeaderText = "Actual not classified";
     90          dataGridView.Rows[i].HeaderCell.Value = "Predicted not classified";
     91
    8992          dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
    9093          dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
     
    100103        if (Content == null) return;
    101104
    102         double[,] confusionMatrix = new double[Content.ProblemData.Classes, Content.ProblemData.Classes];
     105        double[,] confusionMatrix = new double[Content.ProblemData.Classes + 1, Content.ProblemData.Classes + 1];
    103106        IEnumerable<int> rows;
    104107
     
    109112        } else if (cmbSamples.SelectedItem.ToString() == TestSamples) {
    110113          rows = Content.ProblemData.TestIndizes;
    111           predictedValues = Content.EstimatedTestClassValues.ToArray();         
     114          predictedValues = Content.EstimatedTestClassValues.ToArray();
    112115        } else throw new InvalidOperationException();
    113116
     
    124127          double targetValue = targetValues[i];
    125128          double predictedValue = predictedValues[i];
    126           int targetIndex = classValueIndexMapping[targetValue];
    127           int predictedIndex = classValueIndexMapping[predictedValue];
     129          int targetIndex;
     130          int predictedIndex;
     131          if (!classValueIndexMapping.TryGetValue(targetValue, out targetIndex)) {
     132            targetIndex = Content.ProblemData.Classes;
     133          }
     134          if (!classValueIndexMapping.TryGetValue(predictedValue, out predictedIndex)) {
     135            predictedIndex = Content.ProblemData.Classes;
     136          }
    128137
    129138          confusionMatrix[predictedIndex, targetIndex] += 1;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6238 r6520  
    181181    </Compile>
    182182    <Compile Include="Interfaces\IRegressionSolutionEvaluationView.cs" />
     183    <Compile Include="MenuItems\CreateEnsembleMenuItem.cs" />
    183184    <Compile Include="RegressionSolutionView.cs">
    184185      <SubType>UserControl</SubType>
     
    269270      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    270271      <Name>HeuristicLab.Optimization-3.3</Name>
     272    </ProjectReference>
     273    <ProjectReference Include="..\..\HeuristicLab.Optimizer\3.3\HeuristicLab.Optimizer-3.3.csproj">
     274      <Project>{C664305E-497C-4533-A140-967DEDB05C19}</Project>
     275      <Name>HeuristicLab.Optimizer-3.3</Name>
    271276    </ProjectReference>
    272277    <ProjectReference Include="..\..\HeuristicLab.Parameters.Views\3.3\HeuristicLab.Parameters.Views-3.3.csproj">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLabProblemsDataAnalysisViewsPlugin.cs.frame

    r5869 r6520  
    3939  [PluginDependency("HeuristicLab.Optimization","3.3")]
    4040  [PluginDependency("HeuristicLab.Optimization.Views","3.3")]
     41  [PluginDependency("HeuristicLab.Optimizer", "3.3")]
    4142  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
    4243  [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r6302 r6520  
    198198      // strip range is [start .. end] inclusive, but we evaluate [start..end[ (end is exclusive)
    199199      // the strip should be by one longer (starting at start - 0.5 and ending at end + 0.5)
    200       stripLine.StripWidth = end - start; 
     200      stripLine.StripWidth = end - start;
    201201      stripLine.IntervalOffset = start - 0.5; // start slightly to the left of the first point to clearly indicate the first point in the partition
    202202      this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r6239 r6520  
    5858
    5959    #region IClassificationEnsembleModel Members
     60    public void Add(IClassificationModel model) {
     61      models.Add(model);
     62    }
    6063
    6164    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r6239 r6520  
    3737    public override IEnumerable<int> TrainingIndizes {
    3838      get {
    39         return Enumerable.Range(TrainingPartition.Start, TestPartition.End - TestPartition.Start);
     39        return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start);
    4040      }
    4141    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6302 r6520  
    7979      this.trainingPartitions = new Dictionary<IClassificationModel, IntRange>();
    8080      this.testPartitions = new Dictionary<IClassificationModel, IntRange>();
    81       var modelEnumerator = models.GetEnumerator();
    82       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    83       var testPartitionEnumerator = testPartitions.GetEnumerator();
    84       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    85         this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
    86         this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
    87       }
    88       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    89         throw new ArgumentException();
    90       }
     81      AddModelsAndParitions(models,
     82        trainingPartitions,
     83        testPartitions);
    9184      RecalculateResults();
    9285    }
     
    169162      .First();
    170163    }
     164
     165    public void AddModelsAndParitions(IEnumerable<IClassificationSolution> solutions) {
     166      foreach (var solution in solutions) {
     167        var ensembleSolution = solution as ClassificationEnsembleSolution;
     168        if (ensembleSolution != null) {
     169          var data = from m in ensembleSolution.Model.Models
     170                     let train = ensembleSolution.trainingPartitions[m]
     171                     let test = ensembleSolution.testPartitions[m]
     172                     select new { m, train, test };
     173
     174          foreach (var d in data) {
     175            Model.Add(d.m);
     176            trainingPartitions[d.m] = (IntRange)d.train.Clone();
     177            testPartitions[d.m] = (IntRange)d.test.Clone();
     178          }
     179        } else {
     180          Model.Add(solution.Model);
     181          trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone();
     182          testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone();
     183        }
     184      }
     185
     186      RecalculateResults();
     187    }
     188
     189    private void AddModelsAndParitions(IEnumerable<IClassificationModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) {
     190      var modelEnumerator = models.GetEnumerator();
     191      var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
     192      var testPartitionEnumerator = testPartitions.GetEnumerator();
     193
     194      while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
     195        this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
     196        this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
     197      }
     198      if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
     199        throw new ArgumentException();
     200      }
     201    }
    171202  }
    172203}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r5809 r6520  
    5858    #region IRegressionEnsembleModel Members
    5959
     60    public void Add(IRegressionModel model) {
     61      models.Add(model);
     62    }
     63
    6064    public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) {
    6165      var estimatedValuesEnumerators = (from model in models
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6302 r6520  
    6464      trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
    6565      testPartitions = new Dictionary<IRegressionModel, IntRange>();
    66       foreach (var model in models) {
    67         trainingPartitions[model] = (IntRange)problemData.TrainingPartition.Clone();
    68         testPartitions[model] = (IntRange)problemData.TestPartition.Clone();
    69       }
     66      AddModelsAndParitions(models,
     67        from m in models select (IntRange)problemData.TrainingPartition.Clone(),
     68        from m in models select (IntRange)problemData.TestPartition.Clone());
    7069      RecalculateResults();
    7170    }
     
    7574      this.trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
    7675      this.testPartitions = new Dictionary<IRegressionModel, IntRange>();
    77       var modelEnumerator = models.GetEnumerator();
    78       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    79       var testPartitionEnumerator = testPartitions.GetEnumerator();
    80       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    81         this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
    82         this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
    83       }
    84       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    85         throw new ArgumentException();
    86       }
     76      AddModelsAndParitions(models, trainingPartitions, testPartitions);
    8777      RecalculateResults();
    8878    }
     
    160150      return estimatedValues.DefaultIfEmpty(double.NaN).Average();
    161151    }
     152
     153
     154    public void AddModelsAndParitions(IEnumerable<IRegressionSolution> solutions) {
     155      foreach (var solution in solutions) {
     156        var ensembleSolution = solution as RegressionEnsembleSolution;
     157        if (ensembleSolution != null) {
     158          var data = from m in ensembleSolution.Model.Models
     159                     let train = ensembleSolution.trainingPartitions[m]
     160                     let test = ensembleSolution.testPartitions[m]
     161                     select new { m, train, test };
     162
     163          foreach (var d in data) {
     164            Model.Add(d.m);
     165            trainingPartitions[d.m] = (IntRange)d.train.Clone();
     166            testPartitions[d.m] = (IntRange)d.test.Clone();
     167          }
     168        } else {
     169          Model.Add(solution.Model);
     170          trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone();
     171          testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone();
     172        }
     173      }
     174
     175      RecalculateResults();
     176    }
     177
     178    private void AddModelsAndParitions(IEnumerable<IRegressionModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) {
     179      var modelEnumerator = models.GetEnumerator();
     180      var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
     181      var testPartitionEnumerator = testPartitions.GetEnumerator();
     182
     183      while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
     184        this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
     185        this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
     186      }
     187      if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
     188        throw new ArgumentException();
     189      }
     190    }
    162191  }
    163192}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleModel.cs

    r5809 r6520  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IClassificationEnsembleModel : IClassificationModel {
     25    void Add(IClassificationModel model);
    2526    IEnumerable<IClassificationModel> Models { get; }
    2627    IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleModel.cs

    r5809 r6520  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IRegressionEnsembleModel : IRegressionModel {
     25    void Add(IRegressionModel model);
    2526    IEnumerable<IRegressionModel> Models { get; }
    2627    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
Note: See TracChangeset for help on using the changeset viewer.