Changeset 5816


Ignore:
Timestamp:
03/23/11 12:54:57 (11 years ago)
Author:
gkronber
Message:

#1450 Added preliminary implementation for solution ensemble support.

Location:
branches/DataAnalysis SolutionEnsembles
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r5809 r5816  
    355355      foreach (IResult result in ExtractAndAggregateResults<PercentValue>(resultCollections))
    356356        results.Add(result.Name, result.Value);
    357 
     357      foreach (IResult result in ExtractAndAggregateRegressionSolutions(resultCollections)) {
     358        results.Add(result.Name, result.Value);
     359      }
     360      //foreach (IResult result in ExtractAndAggregateClassificationSolutions(resultCollections)) {
     361      //  results.Add(result.Name, result.Value);
     362      //}
    358363      results.Add("Execution Time", new TimeSpanValue(this.ExecutionTime));
    359364      results.Add("CrossValidation Folds", new RunCollection(runs));
    360365    }
     366
     367    private IEnumerable<IResult> ExtractAndAggregateRegressionSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     368      Dictionary<string, List<IRegressionSolution>> resultSolutions = new Dictionary<string, List<IRegressionSolution>>();
     369      foreach (var result in resultCollections) {
     370        var regressionSolution = result.Value as IRegressionSolution;
     371        if (regressionSolution != null) {
     372          if (resultSolutions.ContainsKey(result.Key)) {
     373            resultSolutions[result.Key].Add(regressionSolution);
     374          } else {
     375            resultSolutions.Add(result.Key, new List<IRegressionSolution>() { regressionSolution });
     376          }
     377        }
     378      }
     379      List<IResult> aggregatedResults = new List<IResult>();
     380      foreach (KeyValuePair<string, List<IRegressionSolution>> solutions in resultSolutions) {
     381        var problemDataClone = (IRegressionProblemData)Problem.ProblemData.Clone();
     382        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     383        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     384        var ensembleSolution = new RegressionEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone,
     385          solutions.Value.Select(x => x.ProblemData.TrainingPartition),
     386          solutions.Value.Select(x => x.ProblemData.TestPartition)); ;
     387
     388        aggregatedResults.Add(new Result(solutions.Key, ensembleSolution));
     389      }
     390      return aggregatedResults;
     391    }
     392
     393    //private IEnumerable<IResult> ExtractAndAggregateClassificationSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     394    //  Dictionary<string, List<IClassificationSolution>> resultSolutions = new Dictionary<string, List<IClassificationSolution>>();
     395    //  foreach (var result in resultCollections) {
     396    //    var classificationSolution = result.Value as IClassificationSolution;
     397    //    if (classificationSolution != null) {
     398    //      if (resultSolutions.ContainsKey(result.Key)) {
     399    //        resultSolutions[result.Key].Add(classificationSolution);
     400    //      } else {
     401    //        resultSolutions.Add(result.Key, new List<IClassificationSolution>() { classificationSolution });
     402    //      }
     403    //    }
     404    //  }
     405    //  List<IResult> aggregatedResults = new List<IResult>();
     406    //  foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
     407    //    var ensembleModel = new ClassificationEnsembleModel(solutions.Value.Select(x => x.Model));
     408    //    var problemDataClone = (IClassificationProblemData)Problem.ProblemData.Clone();
     409
     410    //    problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     411    //    problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     412    //    aggregatedResults.Add(new Result(solutions.Key, new ClassificationSolution(ensembleModel, problemDataClone)));
     413    //  }
     414    //  return aggregatedResults;
     415    //}
    361416
    362417    private static IEnumerable<IResult> ExtractAndAggregateResults<T>(IEnumerable<KeyValuePair<string, IItem>> results)
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r5809 r5816  
    109109  <ItemGroup>
    110110    <Compile Include="DoubleLimit.cs" />
     111    <Compile Include="Implementation\Classification\ClassificationEnsembleModel.cs">
     112      <SubType>Code</SubType>
     113    </Compile>
    111114    <Compile Include="Implementation\Classification\ClassificationProblemData.cs" />
    112115    <Compile Include="Implementation\Classification\ClassificationProblem.cs" />
     
    115118    <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" />
    116119    <Compile Include="Implementation\Clustering\ClusteringSolution.cs" />
    117     <Compile Include="Implementation\Classification\ClassificationEnsembleModel.cs" />
     120    <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs">
     121      <SubType>Code</SubType>
     122    </Compile>
     123    <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" />
     124    <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs">
     125      <SubType>Code</SubType>
     126    </Compile>
     127    <Compile Include="Interfaces\Classification\IClassificationEnsembleSolution.cs" />
    118128    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
    119     <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs" />
    120     <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs" />
     129    <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs">
     130      <SubType>Code</SubType>
     131    </Compile>
     132    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    121133    <Compile Include="OnlineEvaluators\OnlineLinearScalingParameterCalculator.cs" />
    122     <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs" />
    123134    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationModel.cs" />
    124135    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolution.cs" />
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs

    r5809 r5816  
    3030namespace HeuristicLab.Problems.DataAnalysis {
    3131  /// <summary>
    32   /// Abstract base class for classification data analysis solutions
     32  /// Represents a classification data analysis solution
    3333  /// </summary>
    3434  [StorableClass]
    35   public abstract class ClassificationSolution : DataAnalysisSolution, IClassificationSolution {
     35  public class ClassificationSolution : DataAnalysisSolution, IClassificationSolution {
    3636    private const string TrainingAccuracyResultName = "Accuracy (training)";
    3737    private const string TestAccuracyResultName = "Accuracy (test)";
     
    6767      Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue()));
    6868      RecalculateResults();
     69    }
     70
     71    public override IDeepCloneable Clone(Cloner cloner) {
     72      return new ClassificationSolution(this, cloner);
    6973    }
    7074
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringSolution.cs

    r5809 r5816  
    2727namespace HeuristicLab.Problems.DataAnalysis {
    2828  /// <summary>
    29   /// Abstract base class for clustering data analysis solutions
     29  /// Represents a clustering data analysis solution
    3030  /// </summary>
    3131  [StorableClass]
    32   public abstract class ClusteringSolution : DataAnalysisSolution, IClusteringSolution {
     32  public class ClusteringSolution : DataAnalysisSolution, IClusteringSolution {
    3333
    3434    [StorableConstructor]
     
    3939    public ClusteringSolution(IClusteringModel model, IClusteringProblemData problemData)
    4040      : base(model, problemData) {
     41    }
     42
     43    public override IDeepCloneable Clone(Cloner cloner) {
     44      return new ClusteringSolution(this, cloner);
    4145    }
    4246
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r5809 r5816  
    3030namespace HeuristicLab.Problems.DataAnalysis {
    3131  /// <summary>
    32   /// Abstract base class for regression data analysis solutions
     32  /// Represents a regression data analysis solution
    3333  /// </summary>
    3434  [StorableClass]
    35   public abstract class RegressionSolution : DataAnalysisSolution, IRegressionSolution {
     35  public class RegressionSolution : DataAnalysisSolution, IRegressionSolution {
    3636    private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
    3737    private const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
     
    9999    }
    100100
     101    public override IDeepCloneable Clone(Cloner cloner) {
     102      return new RegressionSolution(this, cloner);
     103    }
     104
    101105    protected override void OnProblemDataChanged(EventArgs e) {
    102106      base.OnProblemDataChanged(e);
Note: See TracChangeset for help on using the changeset viewer.