Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/17/11 14:37:34 (13 years ago)
Author:
mkommend
Message:

#1592: Enabled creation of empty ensemble solutions and problem data changes.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r6613 r6666  
    4646      this.models = original.Models.Select(m => cloner.Clone(m)).ToList();
    4747    }
     48
     49    public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { }
    4850    public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models)
    4951      : base() {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r6520 r6666  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.IO;
    2523using System.Linq;
    2624using HeuristicLab.Common;
     
    3634
    3735    public override IEnumerable<int> TrainingIndizes {
    38       get {
    39         return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start);
    40       }
     36      get { return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); }
    4137    }
    4238    public override IEnumerable<int> TestIndizes {
    43       get {
    44         return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start);
    45       }
     39      get { return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); }
     40    }
     41
     42    private static ClassificationEnsembleProblemData emptyProblemData;
     43    public static ClassificationEnsembleProblemData EmptyProblemData {
     44      get { return emptyProblemData; }
     45    }
     46
     47    static ClassificationEnsembleProblemData() {
     48      var problemData = new ClassificationEnsembleProblemData();
     49      problemData.Parameters.Clear();
     50      problemData.Name = "Empty Classification ProblemData";
     51      problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded.";
     52      problemData.isEmpty = true;
     53
     54      problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset()));
     55      problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, ""));
     56      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     57      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     58      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     59      problemData.Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix(0, 0).AsReadOnly()));
     60      problemData.Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "", (DoubleMatrix)new DoubleMatrix(0, 0).AsReadOnly()));
     61      emptyProblemData = problemData;
    4662    }
    4763
    4864    [StorableConstructor]
    4965    protected ClassificationEnsembleProblemData(bool deserializing) : base(deserializing) { }
     66    protected ClassificationEnsembleProblemData(ClassificationEnsembleProblemData original, Cloner cloner) : base(original, cloner) { }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      if (this == emptyProblemData) return emptyProblemData;
     69      return new ClassificationEnsembleProblemData(this, cloner);
     70    }
    5071
    51     protected ClassificationEnsembleProblemData(ClassificationEnsembleProblemData original, Cloner cloner)
    52       : base(original, cloner) {
    53     }
    54     public override IDeepCloneable Clone(Cloner cloner) { return new ClassificationEnsembleProblemData(this, cloner); }
    55 
     72    public ClassificationEnsembleProblemData() : base() { }
    5673    public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData)
    5774      : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
     
    6178      this.TestPartition.End = classificationProblemData.TestPartition.End;
    6279    }
     80
     81    public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
     82      : base(dataset, allowedInputVariables, targetVariable) {
     83    }
    6384  }
    6485}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6613 r6666  
    3535  [StorableClass]
    3636  [Item("Classification Ensemble Solution", "A classification solution that contains an ensemble of multiple classification models")]
    37   // [Creatable("Data Analysis")]
     37  [Creatable("Data Analysis - Ensembles")]
    3838  public sealed class ClassificationEnsembleSolution : ClassificationSolution, IClassificationEnsembleSolution {
    3939    public new IClassificationEnsembleModel Model {
    4040      get { return (IClassificationEnsembleModel)base.Model; }
     41    }
     42    public new ClassificationEnsembleProblemData ProblemData {
     43      get { return (ClassificationEnsembleProblemData)base.ProblemData; }
     44      set { base.ProblemData = value; }
    4145    }
    4246
     
    8286
    8387      classificationSolutions = cloner.Clone(original.classificationSolutions);
     88      RegisterClassificationSolutionsEventHandler();
     89    }
     90
     91    public ClassificationEnsembleSolution()
     92      : base(new ClassificationEnsembleModel(), ClassificationEnsembleProblemData.EmptyProblemData) {
     93      trainingPartitions = new Dictionary<IClassificationModel, IntRange>();
     94      testPartitions = new Dictionary<IClassificationModel, IntRange>();
     95      classificationSolutions = new ItemCollection<IClassificationSolution>();
     96
    8497      RegisterClassificationSolutionsEventHandler();
    8598    }
     
    208221    #endregion
    209222
     223    protected override void OnProblemDataChanged() {
     224      IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset,
     225                                                                     ProblemData.AllowedInputVariables,
     226                                                                     ProblemData.TargetVariable);
     227      problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start;
     228      problemData.TrainingPartition.End = ProblemData.TrainingPartition.End;
     229      problemData.TestPartition.Start = ProblemData.TestPartition.Start;
     230      problemData.TestPartition.End = ProblemData.TestPartition.End;
     231
     232      foreach (var solution in ClassificationSolutions) {
     233        if (solution is ClassificationEnsembleSolution)
     234          solution.ProblemData = ProblemData;
     235        else
     236          solution.ProblemData = problemData;
     237      }
     238      foreach (var trainingPartition in trainingPartitions.Values) {
     239        trainingPartition.Start = ProblemData.TrainingPartition.Start;
     240        trainingPartition.End = ProblemData.TrainingPartition.End;
     241      }
     242      foreach (var testPartition in testPartitions.Values) {
     243        testPartition.Start = ProblemData.TestPartition.Start;
     244        testPartition.End = ProblemData.TestPartition.End;
     245      }
     246
     247      base.OnProblemDataChanged();
     248    }
     249
    210250    public void AddClassificationSolutions(IEnumerable<IClassificationSolution> solutions) {
    211251      classificationSolutions.AddRange(solutions);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r6654 r6666  
    3434  [Item("ClassificationProblemData", "Represents an item containing all data defining a classification problem.")]
    3535  public class ClassificationProblemData : DataAnalysisProblemData, IClassificationProblemData {
    36     private const string TargetVariableParameterName = "TargetVariable";
    37     private const string ClassNamesParameterName = "ClassNames";
    38     private const string ClassificationPenaltiesParameterName = "ClassificationPenalties";
    39     private const int MaximumNumberOfClasses = 20;
    40     private const int InspectedRowsToDetermineTargets = 500;
     36    protected const string TargetVariableParameterName = "TargetVariable";
     37    protected const string ClassNamesParameterName = "ClassNames";
     38    protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties";
     39    protected const int MaximumNumberOfClasses = 20;
     40    protected const int InspectedRowsToDetermineTargets = 500;
    4141
    4242    #region default data
     
    174174    private static IEnumerable<string> defaultAllowedInputVariables;
    175175    private static string defaultTargetVariable;
     176
     177    private static ClassificationProblemData emptyProblemData;
     178    public static ClassificationProblemData EmptyProblemData {
     179      get { return EmptyProblemData; }
     180    }
     181
    176182    static ClassificationProblemData() {
    177183      defaultDataset = new Dataset(defaultVariableNames, defaultData);
     
    181187      defaultAllowedInputVariables = defaultVariableNames.Except(new List<string>() { "sample", "class" });
    182188      defaultTargetVariable = "class";
     189
     190      var problemData = new ClassificationProblemData();
     191      problemData.Parameters.Clear();
     192      problemData.Name = "Empty Classification ProblemData";
     193      problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded.";
     194      problemData.isEmpty = true;
     195
     196      problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset()));
     197      problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, ""));
     198      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     199      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     200      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     201      problemData.Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix(0, 0).AsReadOnly()));
     202      problemData.Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "", (DoubleMatrix)new DoubleMatrix(0, 0).AsReadOnly()));
     203      emptyProblemData = problemData;
    183204    }
    184205    #endregion
     
    249270      RegisterParameterEvents();
    250271    }
    251     public override IDeepCloneable Clone(Cloner cloner) { return new ClassificationProblemData(this, cloner); }
     272    public override IDeepCloneable Clone(Cloner cloner) {
     273      if (this == emptyProblemData) return emptyProblemData;
     274      return new ClassificationProblemData(this, cloner);
     275    }
    252276
    253277    public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { }
Note: See TracChangeset for help on using the changeset viewer.