Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6612


Ignore:
Timestamp:
07/29/11 13:09:35 (13 years ago)
Author:
mkommend
Message:

#1592: Implemented view for regression solutions contained in a RegressionEnsembleSolution.

Location:
trunk/sources
Files:
4 added
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6596 r6612  
    110110  </ItemGroup>
    111111  <ItemGroup>
     112    <Compile Include="Regression\RegressionEnsembleSolutionModelView.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="Regression\RegressionEnsembleSolutionModelView.Designer.cs">
     116      <DependentUpon>RegressionEnsembleSolutionModelView.cs</DependentUpon>
     117    </Compile>
    112118    <Compile Include="Solution Views\ClassificationSolutionView.cs">
    113119      <SubType>UserControl</SubType>
     
    164170      <DependentUpon>DiscriminantFunctionClassificationSolutionView.cs</DependentUpon>
    165171    </Compile>
    166     <Compile Include="Interfaces\IDataAnalysisSolutionEvaluationView.cs" />
    167172    <Compile Include="Interfaces\IDiscriminantFunctionClassificationSolutionEvaluationView.cs" />
    168173    <Compile Include="Interfaces\IClusteringSolutionEvaluationView.cs" />
     
    182187    <Compile Include="Interfaces\IRegressionSolutionEvaluationView.cs" />
    183188    <Compile Include="MenuItems\CreateEnsembleMenuItem.cs" />
     189    <Compile Include="Solution Views\RegressionEnsembleSolutionView.cs">
     190      <SubType>UserControl</SubType>
     191    </Compile>
     192    <Compile Include="Solution Views\RegressionEnsembleSolutionView.Designer.cs">
     193      <DependentUpon>RegressionEnsembleSolutionView.cs</DependentUpon>
     194    </Compile>
    184195    <Compile Include="Solution Views\RegressionSolutionView.cs">
    185196      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Interfaces/IClassificationSolutionEvaluationView.cs

    r5829 r6612  
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Views {
    24   public interface IClassificationSolutionEvaluationView : IDataAnalysisSolutionEvaluationView {
     24  public interface IClassificationSolutionEvaluationView {
    2525    new IClassificationSolution Content { get; set; }
    2626  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Interfaces/IClusteringSolutionEvaluationView.cs

    r5829 r6612  
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Views {
    24   public interface IClusteringSolutionEvaluationView : IDataAnalysisSolutionEvaluationView {
     24  public interface IClusteringSolutionEvaluationView {
    2525    new IClusteringSolution Content { get; set; }
    2626  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Interfaces/IDiscriminantFunctionClassificationSolutionEvaluationView.cs

    r5829 r6612  
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Views {
    24   public interface IDiscriminantFunctionClassificationSolutionEvaluationView : IDataAnalysisSolutionEvaluationView {
     24  public interface IDiscriminantFunctionClassificationSolutionEvaluationView {
    2525    new IDiscriminantFunctionClassificationSolution Content { get; set; }
    2626  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Interfaces/IRegressionSolutionEvaluationView.cs

    r5829 r6612  
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Views {
    24   public interface IRegressionSolutionEvaluationView : IDataAnalysisSolutionEvaluationView {
     24  public interface IRegressionSolutionEvaluationView {
    2525    new IRegressionSolution Content { get; set; }
    2626  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/CreateEnsembleMenuItem.cs

    r6582 r6612  
    7575            var ensemble = new RegressionEnsembleSolution(Enumerable.Empty<IRegressionModel>(), problemData);
    7676            ensemble.Name = group.Key + " ensemble";
    77             ensemble.AddModelsAndPartitions(group.OfType<IRegressionSolution>());
     77            ensemble.AddRegressionSolutions(group.OfType<IRegressionSolution>());
    7878            MainFormManager.MainForm.ShowContent(ensemble);
    7979          } else if (group.All(s => s is IClassificationSolution)) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationSolutionView.cs

    r6597 r6612  
    3434      var classificationSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(IClassificationSolutionEvaluationView), true);
    3535      foreach (Type viewType in classificationSolutionEvaluationViewTypes)
    36         AddViewListViewItem(viewType);
     36        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    3737    }
    3838
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClusteringSolutionView.cs

    r6596 r6612  
    3434      var clusteringSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(IClusteringSolutionEvaluationView), true);
    3535      foreach (Type viewType in clusteringSolutionEvaluationViewTypes)
    36         AddViewListViewItem(viewType);
     36        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    3737    }
    3838
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs

    r6596 r6612  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
     25using System.Linq;
    2426using System.Windows.Forms;
    25 using HeuristicLab.Common.Resources;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Optimization.Views;
     
    4647
    4748      //cache old viewTypes;
    48       var viewTypes = new List<Type>();
     49      var viewTypes = new List<Tuple<Type, Image>>();
    4950      foreach (ListViewItem item in ItemsListView.Items) {
    5051        var viewType = item.Tag as Type;
    51         if (viewType != null) viewTypes.Add(viewType);
     52        if (viewType != null) viewTypes.Add(Tuple.Create(viewType, imageList.Images[item.ImageIndex]));
    5253      }
    5354
     
    5556
    5657      //readd viewTypes
    57       foreach (Type viewType in viewTypes)
    58         AddViewListViewItem(viewType);
     58      foreach (var tuple in viewTypes)
     59        AddViewListViewItem(tuple.Item1, tuple.Item2);
    5960
    6061      //recover selection
     
    8586    }
    8687
    87     protected void AddViewListViewItem(Type viewType) {
    88       if (!typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(viewType))
    89         throw new ArgumentException("Given type " + viewType + " is not a IDataAnalysisSolutionEvaluationView.");
    90 
     88    protected void AddViewListViewItem(Type viewType, Image image) {
    9189      ListViewItem listViewItem = new ListViewItem();
    9290      listViewItem.Text = ViewAttribute.GetViewName(viewType);
    93       itemsListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
     91      itemsListView.SmallImageList.Images.Add(image);
    9492      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    9593      listViewItem.Tag = viewType;
     
    10098
    10199    protected void RemoveViewListViewItem(Type viewType) {
    102       List<ListViewItem> itemsToRemove = new List<ListViewItem>(); ;
    103       foreach (ListViewItem item in itemsListView.Items)
    104         if (item.Tag as Type == typeof(IDataAnalysisSolutionEvaluationView))
    105           itemsToRemove.Add(item);
     100      List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
    106101
    107102      foreach (ListViewItem item in itemsToRemove)
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DiscriminantFunctionClassificationSolutionView.cs

    r6597 r6612  
    3434      var classificationSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(IClassificationSolutionEvaluationView), true);
    3535      foreach (Type viewType in classificationSolutionEvaluationViewTypes)
    36         AddViewListViewItem(viewType);
     36        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    3737      RemoveViewListViewItem(typeof(ClassificationSolutionEstimatedClassValuesView));
    3838
    3939      var regressionSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(IDiscriminantFunctionClassificationSolutionEvaluationView), true);
    4040      foreach (Type viewType in regressionSolutionEvaluationViewTypes)
    41         AddViewListViewItem(viewType);
     41        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    4242    }
    4343
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs

    r6597 r6612  
    3434      var regressionSolutionEvaluationViewTypes = ApplicationManager.Manager.GetTypes(typeof(IRegressionSolutionEvaluationView), true);
    3535      foreach (Type viewType in regressionSolutionEvaluationViewTypes)
    36         AddViewListViewItem(viewType);
     36        AddViewListViewItem(viewType, HeuristicLab.Common.Resources.VSImageLibrary.Graph);
    3737    }
    3838
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r6603 r6612  
    7474      models.Add(model);
    7575    }
     76    public void Remove(IRegressionModel model) {
     77      models.Remove(model);
     78    }
    7679
    7780    public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6592 r6612  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    4041    }
    4142
     43    private readonly ItemCollection<IRegressionSolution> regressionSolutions;
     44    public IItemCollection<IRegressionSolution> RegressionSolutions {
     45      get { return regressionSolutions; }
     46    }
     47
    4248    [Storable]
    4349    private Dictionary<IRegressionModel, IntRange> trainingPartitions;
     
    4652
    4753    [StorableConstructor]
    48     private RegressionEnsembleSolution(bool deserializing) : base(deserializing) { }
     54    private RegressionEnsembleSolution(bool deserializing)
     55      : base(deserializing) {
     56      regressionSolutions = new ItemCollection<IRegressionSolution>();
     57    }
     58    [StorableHook(HookType.AfterDeserialization)]
     59    private void AfterDeserialization() {
     60      foreach (var model in Model.Models) {
     61        IRegressionProblemData problemData = (IRegressionProblemData)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        regressionSolutions.Add(model.CreateRegressionSolution(problemData));
     68      }
     69      RegisterRegressionSolutionsEventHandler();
     70    }
     71
    4972    private RegressionEnsembleSolution(RegressionEnsembleSolution original, Cloner cloner)
    5073      : base(original, cloner) {
     
    5780        testPartitions[cloner.Clone(pair.Key)] = cloner.Clone(pair.Value);
    5881      }
    59       RecalculateResults();
     82
     83      regressionSolutions = cloner.Clone(original.regressionSolutions);
     84      RegisterRegressionSolutionsEventHandler();
    6085    }
    6186
    6287    public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData)
    63       : base(new RegressionEnsembleModel(models), new RegressionEnsembleProblemData(problemData)) {
    64       trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
    65       testPartitions = new Dictionary<IRegressionModel, IntRange>();
    66       AddModelsAndPartitions(models,
    67         from m in models select (IntRange)problemData.TrainingPartition.Clone(),
    68         from m in models select (IntRange)problemData.TestPartition.Clone());
    69       RecalculateResults();
    70     }
     88      : this(models, problemData,
     89             models.Select(m => (IntRange)problemData.TrainingPartition.Clone()),
     90             models.Select(m => (IntRange)problemData.TestPartition.Clone())
     91      ) { }
    7192
    7293    public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions)
    73       : base(new RegressionEnsembleModel(models), new RegressionEnsembleProblemData(problemData)) {
     94      : base(new RegressionEnsembleModel(Enumerable.Empty<IRegressionModel>()), new RegressionEnsembleProblemData(problemData)) {
    7495      this.trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
    7596      this.testPartitions = new Dictionary<IRegressionModel, IntRange>();
    76       AddModelsAndPartitions(models, trainingPartitions, testPartitions);
    77       RecalculateResults();
     97      this.regressionSolutions = new ItemCollection<IRegressionSolution>();
     98
     99      List<IRegressionSolution> solutions = new List<IRegressionSolution>();
     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 = (IRegressionProblemData)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.CreateRegressionSolution(p));
     112      }
     113      if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
     114        throw new ArgumentException();
     115      }
     116
     117      RegisterRegressionSolutionsEventHandler();
     118      regressionSolutions.AddRange(solutions);
    78119    }
    79120
     
    81122      return new RegressionEnsembleSolution(this, cloner);
    82123    }
     124    private void RegisterRegressionSolutionsEventHandler() {
     125      regressionSolutions.ItemsAdded += new CollectionItemsChangedEventHandler<IRegressionSolution>(regressionSolutions_ItemsAdded);
     126      regressionSolutions.ItemsRemoved += new CollectionItemsChangedEventHandler<IRegressionSolution>(regressionSolutions_ItemsRemoved);
     127      regressionSolutions.CollectionReset += new CollectionItemsChangedEventHandler<IRegressionSolution>(regressionSolutions_CollectionReset);
     128    }
    83129
    84130    protected override void RecalculateResults() {
     
    86132    }
    87133
     134    #region Evaluation
    88135    public override IEnumerable<double> EstimatedTrainingValues {
    89136      get {
     
    154201      return estimatedValues.DefaultIfEmpty(double.NaN).Average();
    155202    }
    156 
    157 
    158     public void AddModelsAndPartitions(IEnumerable<IRegressionSolution> solutions) {
    159       foreach (var solution in solutions) {
    160         var ensembleSolution = solution as RegressionEnsembleSolution;
    161         if (ensembleSolution != null) {
    162           var data = from m in ensembleSolution.Model.Models
    163                      let train = ensembleSolution.trainingPartitions[m]
    164                      let test = ensembleSolution.testPartitions[m]
    165                      select new { m, train, test };
    166 
    167           foreach (var d in data) {
    168             Model.Add(d.m);
    169             trainingPartitions[d.m] = (IntRange)d.train.Clone();
    170             testPartitions[d.m] = (IntRange)d.test.Clone();
    171           }
    172         } else {
    173           Model.Add(solution.Model);
    174           trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone();
    175           testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone();
    176         }
    177       }
    178 
     203    #endregion
     204
     205    public void AddRegressionSolutions(IEnumerable<IRegressionSolution> solutions) {
     206      regressionSolutions.AddRange(solutions);
     207    }
     208    public void RemoveRegressionSolutions(IEnumerable<IRegressionSolution> solutions) {
     209      regressionSolutions.RemoveRange(solutions);
     210    }
     211
     212    private void regressionSolutions_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRegressionSolution> e) {
     213      foreach (var solution in e.Items) AddRegressionSolution(solution);
    179214      RecalculateResults();
    180215    }
    181 
    182     private void AddModelsAndPartitions(IEnumerable<IRegressionModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) {
    183       var modelEnumerator = models.GetEnumerator();
    184       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    185       var testPartitionEnumerator = testPartitions.GetEnumerator();
    186 
    187       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    188         this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
    189         this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
    190       }
    191       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    192         throw new ArgumentException();
    193       }
     216    private void regressionSolutions_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRegressionSolution> e) {
     217      foreach (var solution in e.Items) RemoveRegressionSolution(solution);
     218      RecalculateResults();
     219    }
     220    private void regressionSolutions_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRegressionSolution> e) {
     221      foreach (var solution in e.OldItems) RemoveRegressionSolution(solution);
     222      foreach (var solution in e.Items) AddRegressionSolution(solution);
     223      RecalculateResults();
     224    }
     225
     226    private void AddRegressionSolution(IRegressionSolution solution) {
     227      if (Model.Models.Contains(solution.Model)) throw new ArgumentException();
     228      Model.Add(solution.Model);
     229      trainingPartitions[solution.Model] = solution.ProblemData.TrainingPartition;
     230      testPartitions[solution.Model] = solution.ProblemData.TestPartition;
     231    }
     232
     233    private void RemoveRegressionSolution(IRegressionSolution solution) {
     234      if (!Model.Models.Contains(solution.Model)) throw new ArgumentException();
     235      Model.Remove(solution.Model);
     236      trainingPartitions.Remove(solution.Model);
     237      testPartitions.Remove(solution.Model);
    194238    }
    195239  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleModel.cs

    r6520 r6612  
    2424  public interface IRegressionEnsembleModel : IRegressionModel {
    2525    void Add(IRegressionModel model);
     26    void Remove(IRegressionModel model);
    2627    IEnumerable<IRegressionModel> Models { get; }
    2728    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleSolution.cs

    r6233 r6612  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Core;
    2324namespace HeuristicLab.Problems.DataAnalysis {
    2425  public interface IRegressionEnsembleSolution : IRegressionSolution {
    2526    new IRegressionEnsembleModel Model { get; }
     27    IItemCollection<IRegressionSolution> RegressionSolutions { get; }
    2628    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
    2729  }
Note: See TracChangeset for help on using the changeset viewer.