Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4536


Ignore:
Timestamp:
09/28/10 17:58:53 (14 years ago)
Author:
mkommend
Message:

Added provisional version of the cross validation (ticket #1199).

Location:
branches/HeuristicLab.Classification
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/HeuristicLab.Algorithms.DataAnalysis.Views.csproj

    r4472 r4536  
    102102  </PropertyGroup>
    103103  <ItemGroup>
     104    <Reference Include="HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3">
     105      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.dll</HintPath>
     106    </Reference>
     107    <Reference Include="HeuristicLab.Collections-3.3">
     108      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath>
     109    </Reference>
     110    <Reference Include="HeuristicLab.Common-3.3">
     111      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
     112    </Reference>
     113    <Reference Include="HeuristicLab.Core-3.3">
     114      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
     115    </Reference>
     116    <Reference Include="HeuristicLab.Core.Views-3.3">
     117      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core.Views-3.3.dll</HintPath>
     118    </Reference>
     119    <Reference Include="HeuristicLab.Data-3.3">
     120      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data-3.3.dll</HintPath>
     121    </Reference>
     122    <Reference Include="HeuristicLab.Data.Views-3.3">
     123      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data.Views-3.3.dll</HintPath>
     124    </Reference>
     125    <Reference Include="HeuristicLab.MainForm-3.3">
     126      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm-3.3.dll</HintPath>
     127    </Reference>
     128    <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3">
     129      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
     130    </Reference>
     131    <Reference Include="HeuristicLab.Optimization-3.3">
     132      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath>
     133    </Reference>
    104134    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    105135      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    106136    </Reference>
     137    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.3">
     138      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.DataAnalysis-3.3.dll</HintPath>
     139    </Reference>
    107140    <Reference Include="System" />
    108141    <Reference Include="System.Core" />
     142    <Reference Include="System.Drawing" />
     143    <Reference Include="System.Windows.Forms" />
    109144    <Reference Include="System.Xml.Linq" />
    110145    <Reference Include="System.Data.DataSetExtensions" />
     
    113148  </ItemGroup>
    114149  <ItemGroup>
     150    <Compile Include="CrossValidationView.cs">
     151      <SubType>UserControl</SubType>
     152    </Compile>
     153    <Compile Include="CrossValidationView.Designer.cs">
     154      <DependentUpon>CrossValidationView.cs</DependentUpon>
     155    </Compile>
    115156    <Compile Include="HeuristicLabAlgorithmsDataAnalysisViewsPlugin.cs" />
    116157    <Compile Include="Properties\AssemblyInfo.cs" />
     158    <Compile Include="AlgorithmResultsCollectionView.cs">
     159      <SubType>UserControl</SubType>
     160    </Compile>
     161    <Compile Include="AlgorithmResultsCollectionView.Designer.cs">
     162      <DependentUpon>AlgorithmResultsCollectionView.cs</DependentUpon>
     163    </Compile>
    117164  </ItemGroup>
    118165  <ItemGroup>
     
    120167    <None Include="HeuristicLabAlgorithmsDataAnalysisViewsPlugin.cs.frame" />
    121168    <None Include="Properties\AssemblyInfo.frame" />
     169  </ItemGroup>
     170  <ItemGroup>
     171    <EmbeddedResource Include="CrossValidationView.resx">
     172      <DependentUpon>CrossValidationView.cs</DependentUpon>
     173    </EmbeddedResource>
     174  </ItemGroup>
     175  <ItemGroup>
     176    <ProjectReference Include="..\..\HeuristicLab.Algorithms.DataAnalysis\3.3\HeuristicLab.Algorithms.DataAnalysis-3.3.csproj">
     177      <Project>{A8D5676D-9662-437A-B44D-ECB4046CDE12}</Project>
     178      <Name>HeuristicLab.Algorithms.DataAnalysis-3.3</Name>
     179    </ProjectReference>
    122180  </ItemGroup>
    123181  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/CrossValidation.cs

    r4472 r4536  
    2121
    2222using System;
     23using System.Drawing;
     24using System.Linq;
    2325using HeuristicLab.Collections;
    2426using HeuristicLab.Common;
     
    4446      Runs = new RunCollection();
    4547
    46       algorithmTemplate = null;
     48      algorithm = null;
    4749      clonedAlgorithms = new ItemCollection<IAlgorithm>();
    4850      RegisterClonedAlgorithmEvents();
     
    5658
    5759    #region properties
    58     private IAlgorithm algorithmTemplate;
    59     public IAlgorithm AlgorithmTemplate {
    60       get { return algorithmTemplate; }
     60    private IAlgorithm algorithm;
     61    public IAlgorithm Algorithm {
     62      get { return algorithm; }
    6163      set {
    62         if (algorithmTemplate != value) {
     64        if (algorithm != value) {
    6365          if (value != null && value.Problem != null && !(value.Problem is IDataAnalysisProblem))
    6466            throw new ArgumentException("Only algorithms with a DataAnalysisProblem could be used for the cross validation.");
    65           if (algorithmTemplate != null) DeregisterAlgorithmTemplateEvents();
    66           algorithmTemplate = value;
    67           if (algorithmTemplate != null) RegisterAlgorithmTemplateEvents();
    68           OnAlgorithmTemplateChanged();
     67          if (algorithm != null) DeregisterAlgorithmEvents();
     68          algorithm = value;
     69          algorithm.Prepare(true);
     70          if (algorithm != null) RegisterAlgorithmEvents();
     71          OnAlgorithmChanged();
    6972        }
    7073      }
    7174    }
     75    private IDataAnalysisProblem cachedProblem;
    7276    public IDataAnalysisProblem Problem {
    7377      get {
    74         if (algorithmTemplate == null)
     78        if (algorithm == null)
    7579          return null;
    76         return (IDataAnalysisProblem)algorithmTemplate.Problem;
    77       }
    78     }
     80        return (IDataAnalysisProblem)algorithm.Problem;
     81      }
     82      set {
     83        if (algorithm == null) throw new ArgumentNullException("Could not set a problem before an algorithm was set.");
     84        algorithm.Problem = value;
     85        cachedProblem = value;
     86      }
     87    }
     88
    7989    private ItemCollection<IAlgorithm> clonedAlgorithms;
    8090    private ReadOnlyItemCollection<IAlgorithm> readOnlyClonedAlgorithms;
     
    92102    private IntValue samplesStart;
    93103    public IntValue SamplesStart {
    94       get { return SamplesStart; }
     104      get { return samplesStart; }
    95105    }
    96106    private IntValue samplesEnd;
    97107    public IntValue SamplesEnd {
    98       get { return SamplesEnd; }
     108      get { return samplesEnd; }
    99109    }
    100110    private IntValue numberOfWorkers;
     
    126136      }
    127137    }
     138    public override Image ItemImage {
     139      get {
     140        if (ExecutionState == ExecutionState.Prepared) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
     141        else if (ExecutionState == ExecutionState.Started) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
     142        else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePaused;
     143        else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
     144        else return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event;
     145      }
     146    }
     147
    128148    private TimeSpan executionTime;
    129149    public TimeSpan ExecutionTime {
    130       get { return executionTime; }
     150      get {
     151        if (ExecutionState != ExecutionState.Stopped)
     152          return executionTime + TimeSpan.FromMilliseconds(clonedAlgorithms.Select(x => x.ExecutionTime.TotalMilliseconds).Sum());
     153        else
     154          return executionTime;
     155      }
    131156      private set {
    132157        executionTime = value;
     
    137162
    138163    public void Prepare() {
     164      clonedAlgorithms.Clear();
    139165      OnPrepared();
    140166    }
     
    144170    }
    145171    public void Start() {
     172      for (int i = 0; i < Folds.Value; i++) {
     173        IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone();
     174        clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
     175        clonedAlgorithms.Add(clonedAlgorithm);
     176      }
     177      for (int i = 0; i < NumberOfWorkers.Value && i < clonedAlgorithms.Count; i++)
     178        clonedAlgorithms.ElementAt(i).Start();
    146179      OnStarted();
    147180    }
     
    154187
    155188    #region events
    156     public event EventHandler AlgorithmTemplateChanged;
    157     private void OnAlgorithmTemplateChanged() {
    158       Prepare();
    159       EventHandler handler = AlgorithmTemplateChanged;
    160       if (handler != null) handler(this, EventArgs.Empty);
    161     }
    162     private void RegisterAlgorithmTemplateEvents() {
    163       algorithmTemplate.ProblemChanged += new EventHandler(algorithmTemplate_ProblemChanged);
    164     }
    165     private void DeregisterAlgorithmTemplateEvents() {
    166       algorithmTemplate.ProblemChanged -= new EventHandler(algorithmTemplate_ProblemChanged);
    167     }
    168     private void algorithmTemplate_ProblemChanged(object sender, EventArgs e) {
     189    public event EventHandler AlgorithmChanged;
     190    private void OnAlgorithmChanged() {
     191      EventHandler handler = AlgorithmChanged;
     192      if (handler != null) handler(this, EventArgs.Empty);
     193      OnProblemChanged();
     194    }
     195    private void RegisterAlgorithmEvents() {
     196      algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged);
     197    }
     198    private void DeregisterAlgorithmEvents() {
     199      algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged);
     200    }
     201    private void Algorithm_ProblemChanged(object sender, EventArgs e) {
     202      if (algorithm.Problem != null && !(algorithm.Problem is IDataAnalysisProblem)) {
     203        algorithm.Problem = cachedProblem;
     204        throw new ArgumentException("A cross validation algorithm can only contain DataAnalysisProblems.");
     205      }
     206      cachedProblem = (IDataAnalysisProblem)algorithm.Problem;
    169207      SamplesStart.Value = 0;
    170       SamplesEnd.Value = Problem.DataAnalysisProblemData.Dataset.Rows;
     208      if (algorithm.Problem != null)
     209        SamplesEnd.Value = Problem.DataAnalysisProblemData.Dataset.Rows;
     210      else
     211        SamplesEnd.Value = 0;
     212      OnProblemChanged();
     213    }
     214    public event EventHandler ProblemChanged;
     215    private void OnProblemChanged() {
     216      EventHandler handler = ProblemChanged;
     217      if (handler != null) handler(this, EventArgs.Empty);
    171218    }
    172219
     
    191238    }
    192239    private void RegisterClonedAlgorithmEvents(IAlgorithm algorithm) {
     240      algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     241      algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
    193242      algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);
    194243      algorithm.Paused += new EventHandler(Algorithm_Paused);
     
    196245    }
    197246    private void DeregisterClonedAlgorithmEvents(IAlgorithm algorithm) {
     247      algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     248      algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
    198249      algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);
    199250      algorithm.Paused -= new EventHandler(Algorithm_Paused);
    200251      algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
    201252    }
     253    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     254      OnExceptionOccurred(e.Value);
     255    }
     256    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
     257      OnExecutionTimeChanged();
     258    }
    202259    private void Algorithm_Runs_Added(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    203260      throw new NotImplementedException("TODO added finished run to actual results if the cross validation is running");
     
    209266      throw new NotImplementedException("TODO stop the cross validation if all algorithms are stopped. and start remaining prepared algs");
    210267    }
     268
    211269    public event EventHandler ExecutionStateChanged;
    212270    private void OnExecutionStateChanged() {
  • branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/HeuristicLab.Algorithms.DataAnalysis-3.3.csproj

    r4472 r4536  
    108108      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
    109109    </Reference>
     110    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.2.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
    110111    <Reference Include="HeuristicLab.Core-3.3">
    111112      <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
     
    146147    </Reference>
    147148    <Reference Include="System.Data" />
     149    <Reference Include="System.Drawing" />
    148150    <Reference Include="System.Xml" />
    149151  </ItemGroup>
  • branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/SingleObjectiveClassificationProblem.cs

    r4366 r4536  
    3030  [Item("Classification Problem", "Represents a classfication problem.")]
    3131  [StorableClass]
    32   public abstract class SingleObjectiveClassificationProblem<T, U> : SingleObjectiveProblem<T, U>
     32  public abstract class SingleObjectiveClassificationProblem<T, U> : SingleObjectiveProblem<T, U>, IDataAnalysisProblem
    3333    where T : class, ISingleObjectiveEvaluator
    3434    where U : class, ISolutionCreator {
     
    4141      get { return ClassificationProblemDataParameter.Value; }
    4242      set { ClassificationProblemDataParameter.Value = value; }
     43    }
     44
     45    DataAnalysisProblemData IDataAnalysisProblem.DataAnalysisProblemData {
     46      get { return ClassificationProblemData; }
    4347    }
    4448
Note: See TracChangeset for help on using the changeset viewer.