Changeset 13921


Ignore:
Timestamp:
06/19/16 19:56:11 (3 years ago)
Author:
bburlacu
Message:

#2604: Revert changes to DataAnalysisSolution and IDataAnalysisSolution and implement the desired properties in model classes that implement IDataAnalysisModel, IRegressionModel and IClassificationModel.

Location:
trunk/sources
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationModel.cs

    r13098 r13921  
    3232  [Item("OneR Classification Model", "A model that uses intervals for one variable to determine the class.")]
    3333  public class OneRClassificationModel : NamedItem, IClassificationModel {
     34    public IEnumerable<string> VariablesUsedForPrediction {
     35      get { return Enumerable.Empty<string>(); }
     36    }
     37
     38    public string TargetVariable {
     39      get { return variable; }
     40    }
     41
    3442    [Storable]
    3543    protected string variable;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r13784 r13921  
    3535  [Item("GaussianProcessModel", "Represents a Gaussian process posterior.")]
    3636  public sealed class GaussianProcessModel : NamedItem, IGaussianProcessModel {
     37    public IEnumerable<string> VariablesUsedForPrediction { get; }
     38
    3739    [Storable]
    3840    private double negativeLogLikelihood;
     
    392394      }
    393395    }
     396
    394397  }
    395398}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/StudentTProcessModel.cs

    r13784 r13921  
    3535  [Item("StudentTProcessModel", "Represents a Student-t process posterior.")]
    3636  public sealed class StudentTProcessModel : NamedItem, IGaussianProcessModel {
     37    public IEnumerable<string> VariablesUsedForPrediction {
     38      get { return allowedInputVariables; }
     39    }
     40
    3741    [Storable]
    3842    private double negativeLogLikelihood;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r13157 r13921  
    5858    #endregion
    5959
     60    public string TargetVariable {
     61      get { return models.First().TargetVariable; }
     62    }
     63
     64    public IEnumerable<string> VariablesUsedForPrediction {
     65      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     66    }
     67
    6068    private readonly IList<IRegressionModel> models;
    6169    public IEnumerable<IRegressionModel> Models { get { return models; } }
     
    108116      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    109117    }
     118
    110119  }
    111120}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r13157 r13921  
    2222
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    5455    private int maxSize;
    5556
     57    public string TargetVariable {
     58      get { return trainingProblemData.TargetVariable; }
     59    }
     60
     61    public IEnumerable<string> VariablesUsedForPrediction {
     62      get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     63    }
    5664
    5765    [StorableConstructor]
     
    7381
    7482    // create only the surrogate model without an actual model
    75     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
     83    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     84      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
    7685      : base("Gradient boosted tree model", string.Empty) {
    7786      this.trainingProblemData = trainingProblemData;
     
    8695
    8796    // wrap an actual model in a surrograte
    88     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu, IGradientBoostedTreesModel model)
     97    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     98      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu,
     99      IGradientBoostedTreesModel model)
    89100      : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) {
    90101      this.actualModel = model;
     
    104115      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    105116    }
    106 
    107117
    108118    private IGradientBoostedTreesModel RecalculateModel() {
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r13895 r13921  
    3535  [Item("RegressionTreeModel", "Represents a decision tree for regression.")]
    3636  public sealed class RegressionTreeModel : NamedItem, IRegressionModel {
     37    public IEnumerable<string> VariablesUsedForPrediction {
     38      get { return Enumerable.Empty<string>(); }
     39    }
     40
     41    public string TargetVariable {
     42      get { return string.Empty; }
     43    }
    3744
    3845    // trees are represented as a flat array   
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs

    r12509 r13921  
    4646        }
    4747      }
     48    }
     49
     50    public IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
     54    public string TargetVariable {
     55      get { return targetVariable; }
    4856    }
    4957
     
    111119      return new MultinomialLogitClassificationSolution(new ClassificationProblemData(problemData), this);
    112120    }
     121
     122
     123
    113124    IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    114125      return CreateClassificationSolution(problemData);
     
    135146    }
    136147    #endregion
     148
    137149  }
    138150}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r12509 r13921  
    3131  [StorableClass]
    3232  public class NcaModel : NamedItem, INcaModel {
     33    public IEnumerable<string> VariablesUsedForPrediction {
     34      get { return allowedInputVariables; }
     35    }
     36
     37    public string TargetVariable {
     38      get { return targetVariable; }
     39    }
    3340
    3441    [Storable]
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r12509 r13921  
    4646        }
    4747      }
     48    }
     49
     50    public IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
     54    public string TargetVariable {
     55      get { return targetVariable; }
    4856    }
    4957
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r12509 r13921  
    4646        }
    4747      }
     48    }
     49
     50    public string TargetVariable {
     51      get { return targetVariable; }
     52    }
     53
     54    public IEnumerable<string> VariablesUsedForPrediction {
     55      get { return allowedInputVariables; }
    4856    }
    4957
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r12817 r13921  
    4646        }
    4747      }
     48    }
     49
     50    public IEnumerable<string> VariablesUsedForPrediction {
     51      get { return allowedInputVariables; }
     52    }
     53
     54    public string TargetVariable {
     55      get { return targetVariable; }
    4856    }
    4957
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r12509 r13921  
    4545    }
    4646
     47    public IEnumerable<string> VariablesUsedForPrediction {
     48      get { return originalTrainingData.AllowedInputVariables; }
     49    }
     50
     51    public string TargetVariable {
     52      get {
     53        var regressionProblemData = originalTrainingData as IRegressionProblemData;
     54        var classificationProblemData = originalTrainingData as IClassificationProblemData;
     55        if (classificationProblemData != null)
     56          return classificationProblemData.TargetVariable;
     57        if (regressionProblemData != null)
     58          return regressionProblemData.TargetVariable;
     59        throw new InvalidOperationException("Getting the target variable requires either a regression or a classification problem data.");
     60      }
     61    }
     62
    4763    // instead of storing the data of the model itself
    4864    // we instead only store data necessary to recalculate the same model lazily on demand
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs

    r12509 r13921  
    3838  [Item("SupportVectorMachineModel", "Represents a support vector machine model.")]
    3939  public sealed class SupportVectorMachineModel : NamedItem, ISupportVectorMachineModel {
     40    public IEnumerable<string> VariablesUsedForPrediction {
     41      get { return allowedInputVariables; }
     42    }
     43
     44    public string TargetVariable {
     45      get { return targetVariable; }
     46    }
    4047
    4148    private svm_model model;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs

    r12509 r13921  
    3737    public static new Image StaticItemImage {
    3838      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
     39    }
     40
     41    public IEnumerable<string> VariablesUsedForPrediction {
     42      get { return allowedInputVariables; }
    3943    }
    4044
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs

    r12509 r13921  
    3333  [Item(Name = "SymbolicClassificationModel", Description = "Represents a symbolic classification model.")]
    3434  public abstract class SymbolicClassificationModel : SymbolicDataAnalysisModel, ISymbolicClassificationModel {
     35    [Storable]
     36    private readonly string targetVariable;
     37    public string TargetVariable {
     38      get { return targetVariable; }
     39    }
    3540
    3641    [StorableConstructor]
    3742    protected SymbolicClassificationModel(bool deserializing) : base(deserializing) { }
    38     protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) : base(original, cloner) { }
     43
     44    protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) : base(original, cloner) {
     45      targetVariable = original.targetVariable;
     46    }
     47
    3948    protected SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    40       double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    41       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { }
     49      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, string targetVariable = "Target")
     50      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     51      this.targetVariable = targetVariable;
     52    }
    4253
    4354    public abstract IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r12509 r13921  
    3333  [Item(Name = "Symbolic Regression Model", Description = "Represents a symbolic regression model.")]
    3434  public class SymbolicRegressionModel : SymbolicDataAnalysisModel, ISymbolicRegressionModel {
    35 
     35    [Storable]
     36    private readonly string targetVariable;
     37    public string TargetVariable {
     38      get { return targetVariable; }
     39    }
    3640
    3741    [StorableConstructor]
    3842    protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { }
    39     protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) { }
    4043
    41     public SymbolicRegressionModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    42       double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    43       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { }
     44    protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) {
     45      this.targetVariable = original.targetVariable;
     46    }
     47
     48    public SymbolicRegressionModel(ISymbolicExpressionTree tree,
     49      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     50      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue,
     51      string targetVariable = "Target")
     52      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     53      this.targetVariable = targetVariable;
     54    }
    4455
    4556    public override IDeepCloneable Clone(Cloner cloner) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r12012 r13921  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
     25using System.Linq;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    5658      get { return interpreter; }
    5759    }
     60
     61    public IEnumerable<string> VariablesUsedForPrediction {
     62      get {
     63        return
     64          SymbolicExpressionTree.IterateNodesPrefix()
     65            .OfType<VariableTreeNode>()
     66            .Select(x => x.VariableName)
     67            .Distinct()
     68            .OrderBy(x => x);
     69      }
     70    }
     71
    5872    #endregion
    5973
     
    160174    }
    161175    #endregion
     176
    162177  }
    163178}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r12509 r13921  
    3333  [Item("ClassificationEnsembleModel", "A classification model that contains an ensemble of multiple classification models")]
    3434  public class ClassificationEnsembleModel : NamedItem, IClassificationEnsembleModel {
     35    public IEnumerable<string> VariablesUsedForPrediction {
     36      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     37    }
     38
     39    public string TargetVariable {
     40      get { return models.First().TargetVariable; }
     41    }
    3542
    3643    [Storable]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r12509 r13921  
    3434  [Item("DiscriminantFunctionClassificationModel", "Represents a classification model that uses a discriminant function and classification thresholds.")]
    3535  public class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {
     36    public IEnumerable<string> VariablesUsedForPrediction {
     37      get { return model.VariablesUsedForPrediction; }
     38    }
     39
     40    public string TargetVariable { get { return model.TargetVariable; } }
     41
    3642    [Storable]
    3743    private IRegressionModel model;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs

    r13154 r13921  
    3232  [Item("Constant Model", "A model that always returns the same constant value regardless of the presented input data.")]
    3333  public class ConstantModel : NamedItem, IRegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
     34    public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
     35
    3436    [Storable]
    35     private double constant;
     37    private readonly string targetVariable;
     38    public string TargetVariable {
     39      get { return targetVariable; }
     40    }
     41
     42    [Storable]
     43    private readonly double constant;
    3644    public double Constant {
    3745      get { return constant; }
     
    4452      : base(original, cloner) {
    4553      this.constant = original.constant;
     54      this.targetVariable = original.targetVariable;
    4655    }
     56
    4757    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantModel(this, cloner); }
    4858
    49     public ConstantModel(double constant)
     59    public ConstantModel(double constant, string targetVariable = "Target")
    5060      : base() {
    5161      this.name = ItemName;
     
    5363      this.constant = constant;
    5464      this.ReadOnly = true; // changing a constant regression model is not supported
     65      this.targetVariable = targetVariable;
    5566    }
    5667
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs

    r13826 r13921  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    111111    protected override void DeregisterItemEvents(IEnumerable<IResult> items) { }
    112112
    113     public virtual IEnumerable<string> GetUsedVariablesForPrediction() {
    114       return this.ProblemData.AllowedInputVariables;
    115     }
    116 
    117113    #region INamedItem Members
    118114    [Storable]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r13100 r13921  
    3333  [Obsolete]
    3434  public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue {
     35    public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
     36
     37    [Storable]
     38    private readonly string targetVariable;
     39    public string TargetVariable {
     40      get { return targetVariable; }
     41    }
     42
    3543    [Storable]
    3644    private double constant;
     
    4553      : base(original, cloner) {
    4654      this.constant = original.constant;
     55      this.targetVariable = original.targetVariable;
    4756    }
     57
    4858    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantRegressionModel(this, cloner); }
    4959
    50     public ConstantRegressionModel(double constant)
     60    public ConstantRegressionModel(double constant, string targetVariable = "Target")
    5161      : base() {
    5262      this.name = ItemName;
     
    5464      this.constant = constant;
    5565      this.ReadOnly = true; // changing a constant regression model is not supported
     66      this.targetVariable = targetVariable;
    5667    }
    5768
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r13715 r13921  
    3434  [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")]
    3535  public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {
     36    public IEnumerable<string> VariablesUsedForPrediction {
     37      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     38    }
    3639
    3740    private List<IRegressionModel> models;
    3841    public IEnumerable<IRegressionModel> Models {
    3942      get { return new List<IRegressionModel>(models); }
     43    }
     44
     45    [Storable]
     46    private readonly string target;
     47    public string TargetVariable {
     48      get { return models.First().TargetVariable; }
    4049    }
    4150
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r12509 r13921  
    3131  [Item("Autoregressive TimeSeries Model", "A linear autoregressive time series model used to predict future values.")]
    3232  public class TimeSeriesPrognosisAutoRegressiveModel : NamedItem, ITimeSeriesPrognosisModel {
     33    public IEnumerable<string> VariablesUsedForPrediction {
     34      get { return Enumerable.Empty<string>(); } // what to return here?
     35    }
     36
    3337    [Storable]
    3438    public double[] Phi { get; private set; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs

    r12509 r13921  
    2525    IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows);
    2626    IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData);
     27    string TargetVariable { get; }
    2728  }
    2829}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs

    r12012 r13921  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Core;
    2324
    2425namespace HeuristicLab.Problems.DataAnalysis {
    2526  public interface IDataAnalysisModel : INamedItem {
     27    IEnumerable<string> VariablesUsedForPrediction { get; }
    2628  }
    2729}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisSolution.cs

    r13826 r13921  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    2928    IDataAnalysisModel Model { get; }
    3029    IDataAnalysisProblemData ProblemData { get; set; }
    31     IEnumerable<string> GetUsedVariablesForPrediction();
    3230
    3331    event EventHandler ModelChanged;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs

    r12509 r13921  
    2525    IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows);
    2626    IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData);
     27    string TargetVariable { get; }
    2728  }
    2829}
Note: See TracChangeset for help on using the changeset viewer.