Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6613 for trunk/sources


Ignore:
Timestamp:
07/29/11 14:14:27 (13 years ago)
Author:
mkommend
Message:

#1592: Implemented view for classification solutions contained in a ClassificationEnsembleSolution.

Location:
trunk/sources
Files:
7 edited
4 copied

Legend:

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

    r6612 r6613  
    2020#endregion
    2121namespace HeuristicLab.Problems.DataAnalysis.Views {
    22   partial class RegressionEnsembleSolutionModelView {
     22  partial class ClassificationEnsembleSolutionModelView {
    2323    /// <summary>
    2424    /// Required designer variable.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionModelView.cs

    r6612 r6613  
    4949
    5050  [View("Ensemble Solutions")]
    51   [Content(typeof(IItemCollection<IRegressionSolution>), false)]
    52   internal sealed partial class RegressionEnsembleSolutionModelView : ItemCollectionView<IRegressionSolution> {
    53     public RegressionEnsembleSolutionModelView() {
     51  [Content(typeof(IItemCollection<IClassificationSolution>), false)]
     52  internal sealed partial class ClassificationEnsembleSolutionModelView : ItemCollectionView<IClassificationSolution> {
     53    public ClassificationEnsembleSolutionModelView() {
    5454      InitializeComponent();
    5555    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6612 r6613  
    110110  </ItemGroup>
    111111  <ItemGroup>
     112    <Compile Include="Classification\ClassificationEnsembleSolutionModelView.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="Classification\ClassificationEnsembleSolutionModelView.Designer.cs">
     116      <DependentUpon>ClassificationEnsembleSolutionModelView.cs</DependentUpon>
     117    </Compile>
    112118    <Compile Include="Regression\RegressionEnsembleSolutionModelView.cs">
    113119      <SubType>UserControl</SubType>
     
    163169    <Compile Include="Solution Views\ClusteringSolutionView.Designer.cs">
    164170      <DependentUpon>ClusteringSolutionView.cs</DependentUpon>
     171    </Compile>
     172    <Compile Include="Solution Views\ClassificationEnsembleSolutionView.cs">
     173      <SubType>UserControl</SubType>
     174    </Compile>
     175    <Compile Include="Solution Views\ClassificationEnsembleSolutionView.Designer.cs">
     176      <DependentUpon>ClassificationEnsembleSolutionView.cs</DependentUpon>
    165177    </Compile>
    166178    <Compile Include="Solution Views\DiscriminantFunctionClassificationSolutionView.cs">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/CreateEnsembleMenuItem.cs

    r6612 r6613  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    24 using System.Collections.Generic;
    2525using System.Windows.Forms;
     26using HeuristicLab.Core;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Optimization;
    2829using HeuristicLab.Optimizer;
    29 using HeuristicLab.Core;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.MenuItems {
     
    8585            var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData);
    8686            ensemble.Name = group.Key + " ensemble";
    87             ensemble.AddModelsAndPartitions(group.OfType<IClassificationSolution>());
     87            ensemble.AddClassificationSolutions(group.OfType<IClassificationSolution>());
    8888            MainFormManager.MainForm.ShowContent(ensemble);
    8989          }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationEnsembleSolutionView.Designer.cs

    r6612 r6613  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Views {
    23   partial class RegressionEnsembleSolutionView {
     23  partial class ClassificationEnsembleSolutionView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationEnsembleSolutionView.cs

    r6612 r6613  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Views {
    28   [View("RegressionEnsembleSolution View")]
    29   [Content(typeof(RegressionEnsembleSolution), true)]
    30   public partial class RegressionEnsembleSolutionView : RegressionSolutionView {
    31     public RegressionEnsembleSolutionView() {
     28  [View("ClassificationEnsembleSolution View")]
     29  [Content(typeof(ClassificationEnsembleSolution), true)]
     30  public partial class ClassificationEnsembleSolutionView : ClassificationSolutionView {
     31    public ClassificationEnsembleSolutionView() {
    3232      InitializeComponent();
    33       AddViewListViewItem(typeof(RegressionEnsembleSolutionModelView), HeuristicLab.Common.Resources.VSImageLibrary.Function);
     33      AddViewListViewItem(typeof(ClassificationEnsembleSolutionModelView), HeuristicLab.Common.Resources.VSImageLibrary.Function);
    3434    }
    3535
    36     public new RegressionEnsembleSolution Content {
    37       get { return (RegressionEnsembleSolution)base.Content; }
     36    public new ClassificationEnsembleSolution Content {
     37      get { return (ClassificationEnsembleSolution)base.Content; }
    3838      set { base.Content = value; }
    3939    }
    4040
    4141    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
    42       if (Content != null && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag == typeof(RegressionEnsembleSolutionModelView)) {
     42      if (Content != null && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag == typeof(ClassificationEnsembleSolutionModelView)) {
    4343        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
    44         var view = MainFormManager.MainForm.ShowContent(Content.RegressionSolutions, viewType);
     44        var view = MainFormManager.MainForm.ShowContent(Content.ClassificationSolutions, viewType);
    4545        view.ReadOnly = false;
    4646        view.Locked = Locked;
     
    5050
    5151    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
    52       if (Content != null && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag == typeof(RegressionEnsembleSolutionModelView)) {
     52      if (Content != null && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag == typeof(ClassificationEnsembleSolutionModelView)) {
    5353        detailsGroupBox.Enabled = true;
    5454        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
    5555        viewHost.ViewType = viewType;
    56         viewHost.Content = Content.RegressionSolutions;
     56        viewHost.Content = Content.ClassificationSolutions;
    5757        viewHost.ReadOnly = false;
    5858        viewHost.Locked = Locked;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r6604 r6613  
    6161      models.Add(model);
    6262    }
     63    public void Remove(IClassificationModel model) {
     64      models.Remove(model);
     65    }
    6366
    6467    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6592 r6613  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    3637  // [Creatable("Data Analysis")]
    3738  public sealed class ClassificationEnsembleSolution : ClassificationSolution, IClassificationEnsembleSolution {
    38 
    3939    public new IClassificationEnsembleModel Model {
    40       set { base.Model = value; }
    4140      get { return (IClassificationEnsembleModel)base.Model; }
     41    }
     42
     43    private readonly ItemCollection<IClassificationSolution> classificationSolutions;
     44    public IItemCollection<IClassificationSolution> ClassificationSolutions {
     45      get { return classificationSolutions; }
    4246    }
    4347
     
    4751    private Dictionary<IClassificationModel, IntRange> testPartitions;
    4852
    49 
    5053    [StorableConstructor]
    51     private ClassificationEnsembleSolution(bool deserializing) : base(deserializing) { }
     54    private ClassificationEnsembleSolution(bool deserializing)
     55      : base(deserializing) {
     56      classificationSolutions = new ItemCollection<IClassificationSolution>();
     57    }
     58    [StorableHook(HookType.AfterDeserialization)]
     59    private void AfterDeserialization() {
     60      foreach (var model in Model.Models) {
     61        IClassificationProblemData problemData = (IClassificationProblemData)ProblemData.Clone();
     62        problemData.TrainingPartition.Start = trainingPartitions[model].Start;
     63        problemData.TrainingPartition.End = trainingPartitions[model].End;
     64        problemData.TestPartition.Start = testPartitions[model].Start;
     65        problemData.TestPartition.End = testPartitions[model].End;
     66
     67        classificationSolutions.Add(model.CreateClassificationSolution(problemData));
     68      }
     69      RegisterClassificationSolutionsEventHandler();
     70    }
     71
    5272    private ClassificationEnsembleSolution(ClassificationEnsembleSolution original, Cloner cloner)
    5373      : base(original, cloner) {
     
    6080        testPartitions[cloner.Clone(pair.Key)] = cloner.Clone(pair.Value);
    6181      }
    62       RecalculateResults();
    63     }
     82
     83      classificationSolutions = cloner.Clone(original.classificationSolutions);
     84      RegisterClassificationSolutionsEventHandler();
     85    }
     86
    6487    public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData)
    65       : base(new ClassificationEnsembleModel(models), new ClassificationEnsembleProblemData(problemData)) {
    66       this.name = ItemName;
    67       this.description = ItemDescription;
    68       trainingPartitions = new Dictionary<IClassificationModel, IntRange>();
    69       testPartitions = new Dictionary<IClassificationModel, IntRange>();
    70       foreach (var model in models) {
    71         trainingPartitions[model] = (IntRange)problemData.TrainingPartition.Clone();
    72         testPartitions[model] = (IntRange)problemData.TestPartition.Clone();
    73       }
    74       RecalculateResults();
    75     }
     88      : this(models, problemData,
     89             models.Select(m => (IntRange)problemData.TrainingPartition.Clone()),
     90             models.Select(m => (IntRange)problemData.TestPartition.Clone())
     91      ) { }
    7692
    7793    public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions)
    78       : base(new ClassificationEnsembleModel(models), new ClassificationEnsembleProblemData(problemData)) {
     94      : base(new ClassificationEnsembleModel(Enumerable.Empty<IClassificationModel>()), new ClassificationEnsembleProblemData(problemData)) {
    7995      this.trainingPartitions = new Dictionary<IClassificationModel, IntRange>();
    8096      this.testPartitions = new Dictionary<IClassificationModel, IntRange>();
    81       AddModelsAndPartitions(models,
    82         trainingPartitions,
    83         testPartitions);
    84       RecalculateResults();
     97      this.classificationSolutions = new ItemCollection<IClassificationSolution>();
     98
     99      List<IClassificationSolution> solutions = new List<IClassificationSolution>();
     100      var modelEnumerator = models.GetEnumerator();
     101      var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
     102      var testPartitionEnumerator = testPartitions.GetEnumerator();
     103
     104      while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
     105        var p = (IClassificationProblemData)problemData.Clone();
     106        p.TrainingPartition.Start = trainingPartitionEnumerator.Current.Start;
     107        p.TrainingPartition.End = trainingPartitionEnumerator.Current.End;
     108        p.TestPartition.Start = testPartitionEnumerator.Current.Start;
     109        p.TestPartition.End = testPartitionEnumerator.Current.End;
     110
     111        solutions.Add(modelEnumerator.Current.CreateClassificationSolution(p));
     112      }
     113      if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
     114        throw new ArgumentException();
     115      }
     116
     117      RegisterClassificationSolutionsEventHandler();
     118      classificationSolutions.AddRange(solutions);
    85119    }
    86120
     
    88122      return new ClassificationEnsembleSolution(this, cloner);
    89123    }
     124    private void RegisterClassificationSolutionsEventHandler() {
     125      classificationSolutions.ItemsAdded += new CollectionItemsChangedEventHandler<IClassificationSolution>(classificationSolutions_ItemsAdded);
     126      classificationSolutions.ItemsRemoved += new CollectionItemsChangedEventHandler<IClassificationSolution>(classificationSolutions_ItemsRemoved);
     127      classificationSolutions.CollectionReset += new CollectionItemsChangedEventHandler<IClassificationSolution>(classificationSolutions_CollectionReset);
     128    }
    90129
    91130    protected override void RecalculateResults() {
     
    93132    }
    94133
     134    #region Evaluation
    95135    public override IEnumerable<double> EstimatedTrainingClassValues {
    96136      get {
     
    166206      .First();
    167207    }
    168 
    169     public void AddModelsAndPartitions(IEnumerable<IClassificationSolution> solutions) {
    170       foreach (var solution in solutions) {
    171         var ensembleSolution = solution as ClassificationEnsembleSolution;
    172         if (ensembleSolution != null) {
    173           var data = from m in ensembleSolution.Model.Models
    174                      let train = ensembleSolution.trainingPartitions[m]
    175                      let test = ensembleSolution.testPartitions[m]
    176                      select new { m, train, test };
    177 
    178           foreach (var d in data) {
    179             Model.Add(d.m);
    180             trainingPartitions[d.m] = (IntRange)d.train.Clone();
    181             testPartitions[d.m] = (IntRange)d.test.Clone();
    182           }
    183         } else {
    184           Model.Add(solution.Model);
    185           trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone();
    186           testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone();
    187         }
    188       }
    189 
     208    #endregion
     209
     210    public void AddClassificationSolutions(IEnumerable<IClassificationSolution> solutions) {
     211      classificationSolutions.AddRange(solutions);
     212    }
     213    public void RemoveClassificationSolutions(IEnumerable<IClassificationSolution> solutions) {
     214      classificationSolutions.RemoveRange(solutions);
     215    }
     216
     217    private void classificationSolutions_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IClassificationSolution> e) {
     218      foreach (var solution in e.Items) AddClassificationSolution(solution);
    190219      RecalculateResults();
    191220    }
    192 
    193     private void AddModelsAndPartitions(IEnumerable<IClassificationModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) {
    194       var modelEnumerator = models.GetEnumerator();
    195       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    196       var testPartitionEnumerator = testPartitions.GetEnumerator();
    197 
    198       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    199         this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
    200         this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
    201       }
    202       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    203         throw new ArgumentException();
    204       }
     221    private void classificationSolutions_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IClassificationSolution> e) {
     222      foreach (var solution in e.Items) RemoveClassificationSolution(solution);
     223      RecalculateResults();
     224    }
     225    private void classificationSolutions_CollectionReset(object sender, CollectionItemsChangedEventArgs<IClassificationSolution> e) {
     226      foreach (var solution in e.OldItems) RemoveClassificationSolution(solution);
     227      foreach (var solution in e.Items) AddClassificationSolution(solution);
     228      RecalculateResults();
     229    }
     230
     231    private void AddClassificationSolution(IClassificationSolution solution) {
     232      if (Model.Models.Contains(solution.Model)) throw new ArgumentException();
     233      Model.Add(solution.Model);
     234      trainingPartitions[solution.Model] = solution.ProblemData.TrainingPartition;
     235      testPartitions[solution.Model] = solution.ProblemData.TestPartition;
     236    }
     237
     238    private void RemoveClassificationSolution(IClassificationSolution solution) {
     239      if (!Model.Models.Contains(solution.Model)) throw new ArgumentException();
     240      Model.Remove(solution.Model);
     241      trainingPartitions.Remove(solution.Model);
     242      testPartitions.Remove(solution.Model);
    205243    }
    206244  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6612 r6613  
    204204
    205205    public void AddRegressionSolutions(IEnumerable<IRegressionSolution> solutions) {
     206      solutions.OfType<RegressionEnsembleSolution>().SelectMany(ensemble => ensemble.RegressionSolutions);
    206207      regressionSolutions.AddRange(solutions);
    207208    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleModel.cs

    r6520 r6613  
    2424  public interface IClassificationEnsembleModel : IClassificationModel {
    2525    void Add(IClassificationModel model);
     26    void Remove(IClassificationModel model);
    2627    IEnumerable<IClassificationModel> Models { get; }
    2728    IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleSolution.cs

    r6239 r6613  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Core;
    2324namespace HeuristicLab.Problems.DataAnalysis {
    2425  public interface IClassificationEnsembleSolution : IClassificationSolution {
    2526    new IClassificationEnsembleModel Model { get; }
     27    IItemCollection<IClassificationSolution> ClassificationSolutions { get; }
    2628    IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows);
    2729  }
Note: See TracChangeset for help on using the changeset viewer.