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/Regression
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r6612 r6666  
    5858      this.models = original.Models.Select(m => cloner.Clone(m)).ToList();
    5959    }
     60
     61    public RegressionEnsembleModel() : this(Enumerable.Empty<IRegressionModel>()) { }
    6062    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models)
    6163      : base() {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleProblemData.cs

    r6238 r6666  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.IO;
    2523using System.Linq;
    2624using HeuristicLab.Common;
     
    4745    }
    4846
     47    private static RegressionEnsembleProblemData emptyProblemData;
     48    public new static RegressionEnsembleProblemData EmptyProblemData {
     49      get { return emptyProblemData; }
     50    }
     51    static RegressionEnsembleProblemData() {
     52      var problemData = new RegressionEnsembleProblemData();
     53      problemData.Parameters.Clear();
     54      problemData.Name = "Empty Regression ProblemData";
     55      problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded.";
     56      problemData.isEmpty = true;
     57
     58      problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset()));
     59      problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, ""));
     60      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     61      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     62      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     63      emptyProblemData = problemData;
     64    }
     65
    4966    [StorableConstructor]
    5067    private RegressionEnsembleProblemData(bool deserializing) : base(deserializing) { }
     68    private RegressionEnsembleProblemData(RegressionEnsembleProblemData original, Cloner cloner) : base(original, cloner) { }
     69    public override IDeepCloneable Clone(Cloner cloner) {
     70      if (this == emptyProblemData) return emptyProblemData;
     71      return new RegressionEnsembleProblemData(this, cloner);
     72    }
    5173
    52     private RegressionEnsembleProblemData(RegressionEnsembleProblemData original, Cloner cloner)
    53       : base(original, cloner) {
    54     }
    55     public override IDeepCloneable Clone(Cloner cloner) { return new RegressionEnsembleProblemData(this, cloner); }
    56 
     74    public RegressionEnsembleProblemData() : base() { }
    5775    public RegressionEnsembleProblemData(IRegressionProblemData regressionProblemData)
    5876      : base(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) {
     
    6280      TestPartition.End = regressionProblemData.TestPartition.End;
    6381    }
     82    public RegressionEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
     83      : base(dataset, allowedInputVariables, targetVariable) {
     84    }
    6485  }
    6586}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6613 r6666  
    3535  [StorableClass]
    3636  [Item("Regression Ensemble Solution", "A regression solution that contains an ensemble of multiple regression models")]
    37   // [Creatable("Data Analysis")]
     37  [Creatable("Data Analysis - Ensembles")]
    3838  public sealed class RegressionEnsembleSolution : RegressionSolution, IRegressionEnsembleSolution {
    3939    public new IRegressionEnsembleModel Model {
    4040      get { return (IRegressionEnsembleModel)base.Model; }
     41    }
     42
     43    public new RegressionEnsembleProblemData ProblemData {
     44      get { return (RegressionEnsembleProblemData)base.ProblemData; }
     45      set { base.ProblemData = value; }
    4146    }
    4247
     
    5964    private void AfterDeserialization() {
    6065      foreach (var model in Model.Models) {
    61         IRegressionProblemData problemData = (IRegressionProblemData)ProblemData.Clone();
     66        IRegressionProblemData problemData = (IRegressionProblemData) ProblemData.Clone();
    6267        problemData.TrainingPartition.Start = trainingPartitions[model].Start;
    6368        problemData.TrainingPartition.End = trainingPartitions[model].End;
     
    8287
    8388      regressionSolutions = cloner.Clone(original.regressionSolutions);
     89      RegisterRegressionSolutionsEventHandler();
     90    }
     91
     92    public RegressionEnsembleSolution()
     93      : base(new RegressionEnsembleModel(), RegressionEnsembleProblemData.EmptyProblemData) {
     94      trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
     95      testPartitions = new Dictionary<IRegressionModel, IntRange>();
     96      regressionSolutions = new ItemCollection<IRegressionSolution>();
     97
    8498      RegisterRegressionSolutionsEventHandler();
    8599    }
     
    203217    #endregion
    204218
     219    protected override void OnProblemDataChanged() {
     220      IRegressionProblemData problemData = new RegressionProblemData(ProblemData.Dataset,
     221                                                                     ProblemData.AllowedInputVariables,
     222                                                                     ProblemData.TargetVariable);
     223      problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start;
     224      problemData.TrainingPartition.End = ProblemData.TrainingPartition.End;
     225      problemData.TestPartition.Start = ProblemData.TestPartition.Start;
     226      problemData.TestPartition.End = ProblemData.TestPartition.End;
     227
     228      foreach (var solution in RegressionSolutions) {
     229        if (solution is RegressionEnsembleSolution)
     230          solution.ProblemData = ProblemData;
     231        else
     232          solution.ProblemData = problemData;
     233      }
     234      foreach (var trainingPartition in trainingPartitions.Values) {
     235        trainingPartition.Start = ProblemData.TrainingPartition.Start;
     236        trainingPartition.End = ProblemData.TrainingPartition.End;
     237      }
     238      foreach (var testPartition in testPartitions.Values) {
     239        testPartition.Start = ProblemData.TestPartition.Start;
     240        testPartition.End = ProblemData.TestPartition.End;
     241      }
     242
     243      base.OnProblemDataChanged();
     244    }
     245
    205246    public void AddRegressionSolutions(IEnumerable<IRegressionSolution> solutions) {
    206       solutions.OfType<RegressionEnsembleSolution>().SelectMany(ensemble => ensemble.RegressionSolutions);
    207247      regressionSolutions.AddRange(solutions);
    208248    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r6439 r6666  
    3434  [Item("RegressionProblemData", "Represents an item containing all data defining a regression problem.")]
    3535  public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData {
    36     private const string TargetVariableParameterName = "TargetVariable";
     36    protected const string TargetVariableParameterName = "TargetVariable";
    3737
    3838    #region default data
     
    6868    private static string defaultTargetVariable;
    6969
     70    private static RegressionProblemData emptyProblemData;
     71    public static RegressionProblemData EmptyProblemData {
     72      get { return emptyProblemData; }
     73    }
     74
    7075    static RegressionProblemData() {
    7176      defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1);
     
    7479      defaultAllowedInputVariables = new List<string>() { "x" };
    7580      defaultTargetVariable = "y";
     81
     82      var problemData = new RegressionProblemData();
     83      problemData.Parameters.Clear();
     84      problemData.Name = "Empty Regression ProblemData";
     85      problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded.";
     86      problemData.isEmpty = true;
     87
     88      problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset()));
     89      problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, ""));
     90      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     91      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
     92      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     93      emptyProblemData = problemData;
    7694    }
    7795    #endregion
     
    91109    }
    92110
    93 
    94111    protected RegressionProblemData(RegressionProblemData original, Cloner cloner)
    95112      : base(original, cloner) {
    96113      RegisterParameterEvents();
    97114    }
    98     public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblemData(this, cloner); }
     115    public override IDeepCloneable Clone(Cloner cloner) {
     116      if (this == emptyProblemData) return emptyProblemData;
     117      return new RegressionProblemData(this, cloner);
     118    }
    99119
    100120    public RegressionProblemData()
Note: See TracChangeset for help on using the changeset viewer.