Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13941


Ignore:
Timestamp:
06/28/16 13:33:17 (8 years ago)
Author:
mkommend
Message:

#2604:

  • Base classes for data analysis, classification, and regression models
  • Added target variable to classification and regression models
  • Switched parameter order in data analysis solutions (model, problemdata)
Location:
trunk/sources
Files:
3 added
77 edited

Legend:

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

    r13092 r13941  
    139139      }
    140140
    141       var model = new OneRClassificationModel(bestVariable, bestSplits.Select(s => s.thresholdValue).ToArray(), bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass);
     141      var model = new OneRClassificationModel(problemData.TargetVariable, bestVariable, bestSplits.Select(s => s.thresholdValue).ToArray(), bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass);
    142142      var solution = new OneRClassificationSolution(model, (IClassificationProblemData)problemData.Clone());
    143143
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationModel.cs

    r13921 r13941  
    3131  [StorableClass]
    3232  [Item("OneR Classification Model", "A model that uses intervals for one variable to determine the class.")]
    33   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; }
     33  public class OneRClassificationModel : ClassificationModel {
     34    public override IEnumerable<string> VariablesUsedForPrediction {
     35      get { return new[] { Variable }; }
    4036    }
    4137
     
    7470    public override IDeepCloneable Clone(Cloner cloner) { return new OneRClassificationModel(this, cloner); }
    7571
    76     public OneRClassificationModel(string variable, double[] splits, double[] classes, double missingValuesClass = double.NaN)
    77       : base() {
     72    public OneRClassificationModel(string targetVariable, string variable, double[] splits, double[] classes, double missingValuesClass = double.NaN)
     73      : base(targetVariable) {
    7874      if (splits.Length != classes.Length) {
    7975        throw new ArgumentException("Number of splits and classes has to be equal.");
     
    9288    // uses sorting to return the values in the order of rows, instead of using nested for loops
    9389    // to avoid O(n²) runtime
    94     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     90    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    9591      var values = dataset.GetDoubleValues(Variable, rows).ToArray();
    9692      var rowsArray = rows.ToArray();
     
    116112    }
    117113
    118     public IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     114    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    119115      return new OneRClassificationSolution(this, new ClassificationProblemData(problemData));
    120116    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r13917 r13941  
    376376
    377377      var ensembleModel = new RegressionEnsembleModel(models, coefficients.Take(models.Count)) { AverageModelEstimates = false };
    378       var ensembleSolution = ensembleModel.CreateRegressionSolution(problemData);
     378      var ensembleSolution = (IRegressionEnsembleSolution)ensembleModel.CreateRegressionSolution(problemData);
    379379      return ensembleSolution;
    380380    }
     
    443443      progRootNode.AddSubtree(startNode);
    444444      var t = new SymbolicExpressionTree(progRootNode);
    445       var combinedModel = new SymbolicRegressionModel(t, interpreter, lowerLimit, upperLimit);
     445      var combinedModel = new SymbolicRegressionModel(problemData.TargetVariable, t, interpreter, lowerLimit, upperLimit);
    446446      var sol = new SymbolicRegressionSolution(combinedModel, problemData);
    447447      return sol;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r13922 r13941  
    3434  [StorableClass]
    3535  [Item("GaussianProcessModel", "Represents a Gaussian process posterior.")]
    36   public sealed class GaussianProcessModel : NamedItem, IGaussianProcessModel {
    37     public IEnumerable<string> VariablesUsedForPrediction {
     36  public sealed class GaussianProcessModel : RegressionModel, IGaussianProcessModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
    3838      get { return allowedInputVariables; }
    3939    }
     
    6565      get { return meanFunction; }
    6666    }
    67     [Storable]
    68     private string targetVariable;
    69     public string TargetVariable {
    70       get { return targetVariable; }
    71     }
     67
    7268    [Storable]
    7369    private string[] allowedInputVariables;
     
    132128      this.trainingDataset = cloner.Clone(original.trainingDataset);
    133129      this.negativeLogLikelihood = original.negativeLogLikelihood;
    134       this.targetVariable = original.targetVariable;
    135130      this.sqrSigmaNoise = original.sqrSigmaNoise;
    136131      if (original.meanParameter != null) {
     
    151146      IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction,
    152147      bool scaleInputs = true)
    153       : base() {
     148      : base(targetVariable) {
    154149      this.name = ItemName;
    155150      this.description = ItemDescription;
    156151      this.meanFunction = (IMeanFunction)meanFunction.Clone();
    157152      this.covarianceFunction = (ICovarianceFunction)covarianceFunction.Clone();
    158       this.targetVariable = targetVariable;
    159153      this.allowedInputVariables = allowedInputVariables.ToArray();
    160154
     
    186180
    187181      IEnumerable<double> y;
    188       y = ds.GetDoubleValues(targetVariable, rows);
     182      y = ds.GetDoubleValues(TargetVariable, rows);
    189183
    190184      int n = x.GetLength(0);
     
    305299
    306300    #region IRegressionModel Members
    307     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     301    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    308302      return GetEstimatedValuesHelper(dataset, rows);
    309303    }
    310     public GaussianProcessRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     304    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    311305      return new GaussianProcessRegressionSolution(this, new RegressionProblemData(problemData));
    312     }
    313     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    314       return CreateRegressionSolution(problemData);
    315306    }
    316307    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/StudentTProcessModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("StudentTProcessModel", "Represents a Student-t process posterior.")]
    36   public sealed class StudentTProcessModel : NamedItem, IGaussianProcessModel {
    37     public IEnumerable<string> VariablesUsedForPrediction {
     36  public sealed class StudentTProcessModel : RegressionModel, IGaussianProcessModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
    3838      get { return allowedInputVariables; }
    3939    }
     
    6565      get { return meanFunction; }
    6666    }
    67     [Storable]
    68     private string targetVariable;
    69     public string TargetVariable {
    70       get { return targetVariable; }
    71     }
     67
    7268    [Storable]
    7369    private string[] allowedInputVariables;
     
    135131      this.trainingDataset = cloner.Clone(original.trainingDataset);
    136132      this.negativeLogLikelihood = original.negativeLogLikelihood;
    137       this.targetVariable = original.targetVariable;
    138133      if (original.meanParameter != null) {
    139134        this.meanParameter = (double[])original.meanParameter.Clone();
     
    155150      IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction,
    156151      bool scaleInputs = true)
    157       : base() {
     152      : base(targetVariable) {
    158153      this.name = ItemName;
    159154      this.description = ItemDescription;
    160155      this.meanFunction = (IMeanFunction)meanFunction.Clone();
    161156      this.covarianceFunction = (ICovarianceFunction)covarianceFunction.Clone();
    162       this.targetVariable = targetVariable;
    163157      this.allowedInputVariables = allowedInputVariables.ToArray();
    164158
     
    190184
    191185      IEnumerable<double> y;
    192       y = ds.GetDoubleValues(targetVariable, rows);
     186      y = ds.GetDoubleValues(TargetVariable, rows);
    193187
    194188      int n = x.GetLength(0);
     
    322316
    323317    #region IRegressionModel Members
    324     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     318    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    325319      return GetEstimatedValuesHelper(dataset, rows);
    326320    }
    327     public GaussianProcessRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     321    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    328322      return new GaussianProcessRegressionSolution(this, new RegressionProblemData(problemData));
    329     }
    330     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    331       return CreateRegressionSolution(problemData);
    332323    }
    333324    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r13921 r13941  
    3333  [Item("Gradient boosted tree model", "")]
    3434  // this is essentially a collection of weighted regression models
    35   public sealed class GradientBoostedTreesModel : NamedItem, IGradientBoostedTreesModel {
     35  public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel {
    3636    // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models
    3737    #region Backwards compatible code, remove with 3.5
     
    5858    #endregion
    5959
    60     public string TargetVariable {
    61       get { return models.First().TargetVariable; }
    62     }
    63 
    64     public IEnumerable<string> VariablesUsedForPrediction {
     60    public override IEnumerable<string> VariablesUsedForPrediction {
    6561      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    6662    }
     
    8581    }
    8682    [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")]
    87     public GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
    88       : base("Gradient boosted tree model", string.Empty) {
     83    internal GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
     84      : base(string.Empty, "Gradient boosted tree model", string.Empty) {
    8985      this.models = new List<IRegressionModel>(models);
    9086      this.weights = new List<double>(weights);
     
    9793    }
    9894
    99     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     95    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    10096      // allocate target array go over all models and add up weighted estimation for each row
    10197      if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable.
     
    113109    }
    114110
    115     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    116112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    117113    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r13921 r13941  
    3434  // recalculate the actual GBT model on demand
    3535  [Item("Gradient boosted tree model", "")]
    36   public sealed class GradientBoostedTreesModelSurrogate : NamedItem, IGradientBoostedTreesModel {
     36  public sealed class GradientBoostedTreesModelSurrogate : RegressionModel, IGradientBoostedTreesModel {
    3737    // don't store the actual model!
    3838    private IGradientBoostedTreesModel actualModel; // the actual model is only recalculated when necessary
     
    5555    private int maxSize;
    5656
    57     public string TargetVariable {
    58       get { return trainingProblemData.TargetVariable; }
    59     }
    6057
    61     public IEnumerable<string> VariablesUsedForPrediction {
     58    public override IEnumerable<string> VariablesUsedForPrediction {
    6259      get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    6360    }
     
    8380    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
    8481      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
    85       : base("Gradient boosted tree model", string.Empty) {
     82      : base(trainingProblemData.TargetVariable, "Gradient boosted tree model", string.Empty) {
    8683      this.trainingProblemData = trainingProblemData;
    8784      this.seed = seed;
     
    107104
    108105    // forward message to actual model (recalculate model first if necessary)
    109     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     106    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    110107      if (actualModel == null) actualModel = RecalculateModel();
    111108      return actualModel.GetEstimatedValues(dataset, rows);
    112109    }
    113110
    114     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    115112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    116113    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("RegressionTreeModel", "Represents a decision tree for regression.")]
    36   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; }
     36  public sealed class RegressionTreeModel : RegressionModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
     38      get { return tree.Select(t => t.VarName).Where(v => v != TreeNode.NO_VARIABLE); }
    4339    }
    4440
     
    9086    private TreeNode[] tree;
    9187
    92     #region old storable format 
     88    #region old storable format
    9389    // remove with HL 3.4
    9490    [Storable(AllowOneWay = true)]
     
    167163    }
    168164
    169     internal RegressionTreeModel(TreeNode[] tree)
    170       : base("RegressionTreeModel", "Represents a decision tree for regression.") {
     165    internal RegressionTreeModel(TreeNode[] tree, string target = "Target")
     166      : base(target, "RegressionTreeModel", "Represents a decision tree for regression.") {
    171167      this.tree = tree;
    172168    }
     
    194190    }
    195191
    196     public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
     192    public override IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
    197193      // lookup columns for variableNames in one pass over the tree to speed up evaluation later on
    198194      ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length];
     
    208204    }
    209205
    210     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     206    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    211207      return new RegressionSolution(this, new RegressionProblemData(problemData));
    212208    }
     
    227223      }
    228224    }
     225
    229226  }
    230227}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r12509 r13941  
    111111      IClassificationProblemData problemData,
    112112      IEnumerable<int> rows) {
    113       var model = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter, new AccuracyMaximizationThresholdCalculator());
     113      var model = new SymbolicDiscriminantFunctionClassificationModel(problemData.TargetVariable, tree, interpreter, new AccuracyMaximizationThresholdCalculator());
    114114      model.RecalculateModelParameters(problemData, rows);
    115115      return model;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r13238 r13941  
    110110      addition.AddSubtree(cNode);
    111111
    112       SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone());
     112      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone());
    113113      solution.Model.Name = "Linear Regression Model";
    114114      solution.Name = "Linear Regression Solution";
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs

    r13238 r13941  
    9595      relClassError = alglib.mnlrelclserror(lm, inputMatrix, nRows);
    9696
    97       MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution((IClassificationProblemData)problemData.Clone(), new MultinomialLogitModel(lm, targetVariable, allowedInputVariables, classValues));
     97      MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution(new MultinomialLogitModel(lm, targetVariable, allowedInputVariables, classValues), (IClassificationProblemData)problemData.Clone());
    9898      return solution;
    9999    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public MultinomialLogitClassificationSolution(IClassificationProblemData problemData, MultinomialLogitModel logitModel)
     45    public MultinomialLogitClassificationSolution( MultinomialLogitModel logitModel,IClassificationProblemData problemData)
    4646      : base(logitModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("Multinomial Logit Model", "Represents a multinomial logit model for classification.")]
    36   public sealed class MultinomialLogitModel : NamedItem, IClassificationModel {
     36  public sealed class MultinomialLogitModel : ClassificationModel {
    3737
    3838    private alglib.logitmodel logitModel;
     
    4848    }
    4949
    50     public IEnumerable<string> VariablesUsedForPrediction {
     50    public override IEnumerable<string> VariablesUsedForPrediction {
    5151      get { return allowedInputVariables; }
    5252    }
    5353
    54     public string TargetVariable {
    55       get { return targetVariable; }
    56     }
    57 
    58     [Storable]
    59     private string targetVariable;
    6054    [Storable]
    6155    private string[] allowedInputVariables;
     
    7266      logitModel = new alglib.logitmodel();
    7367      logitModel.innerobj.w = (double[])original.logitModel.innerobj.w.Clone();
    74       targetVariable = original.targetVariable;
    7568      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    7669      classValues = (double[])original.classValues.Clone();
    7770    }
    7871    public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)
    79       : base() {
     72      : base(targetVariable) {
    8073      this.name = ItemName;
    8174      this.description = ItemDescription;
    8275      this.logitModel = logitModel;
    83       this.targetVariable = targetVariable;
    8476      this.allowedInputVariables = allowedInputVariables.ToArray();
    8577      this.classValues = (double[])classValues.Clone();
     
    9082    }
    9183
    92     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     84    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    9385      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    9486
     
    116108    }
    117109
    118     public MultinomialLogitClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    119       return new MultinomialLogitClassificationSolution(new ClassificationProblemData(problemData), this);
    120     }
    121 
    122 
    123 
    124     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    125       return CreateClassificationSolution(problemData);
     110    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     111      return new MultinomialLogitClassificationSolution(this, new ClassificationProblemData(problemData));
    126112    }
    127113
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionStatic.cs

    r13669 r13941  
    2525using System.Linq;
    2626using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies;
    27 using HeuristicLab.Common;
    2827using HeuristicLab.Core;
    2928using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    177176
    178177          var t = new SymbolicExpressionTree(treeGen.Exec(bestCode, bestConsts, bestNParams, scalingFactor, scalingOffset));
    179           var model = new SymbolicRegressionModel(t, interpreter, lowerEstimationLimit, upperEstimationLimit);
     178          var model = new SymbolicRegressionModel(problemData.TargetVariable, t, interpreter, lowerEstimationLimit, upperEstimationLimit);
    180179
    181180          // model has already been scaled linearly in Eval
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaClassificationSolution.cs

    r12012 r13941  
    4040      : base(original, cloner) {
    4141    }
    42     public NcaClassificationSolution(IClassificationProblemData problemData, INcaModel ncaModel)
     42    public NcaClassificationSolution(INcaModel ncaModel, IClassificationProblemData problemData)
    4343      : base(ncaModel, problemData) {
    4444    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r13921 r13941  
    3030  [Item("NCA Model", "")]
    3131  [StorableClass]
    32   public class NcaModel : NamedItem, INcaModel {
    33     public IEnumerable<string> VariablesUsedForPrediction {
     32  public class NcaModel : ClassificationModel, INcaModel {
     33    public override IEnumerable<string> VariablesUsedForPrediction {
    3434      get { return allowedInputVariables; }
    35     }
    36 
    37     public string TargetVariable {
    38       get { return targetVariable; }
    3935    }
    4036
     
    4642    [Storable]
    4743    private string[] allowedInputVariables;
    48     [Storable]
    49     private string targetVariable;
    5044    [Storable]
    5145    private INearestNeighbourModel nnModel;
     
    5953      this.transformationMatrix = (double[,])original.transformationMatrix.Clone();
    6054      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    61       this.targetVariable = original.targetVariable;
    6255      this.nnModel = cloner.Clone(original.nnModel);
    6356      this.classValues = (double[])original.classValues.Clone();
    6457    }
    65     public NcaModel(int k, double[,] transformationMatrix, IDataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues) {
     58    public NcaModel(int k, double[,] transformationMatrix, IDataset dataset, IEnumerable<int> rows, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)
     59      : base(targetVariable) {
    6660      Name = ItemName;
    6761      Description = ItemDescription;
    6862      this.transformationMatrix = (double[,])transformationMatrix.Clone();
    6963      this.allowedInputVariables = allowedInputVariables.ToArray();
    70       this.targetVariable = targetVariable;
    7164      this.classValues = (double[])classValues.Clone();
    7265
     
    7972    }
    8073
    81     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     74    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    8275      var ds = ReduceDataset(dataset, rows);
    8376      return nnModel.GetEstimatedClassValues(ds, Enumerable.Range(0, ds.Rows));
    8477    }
    8578
    86     public INcaClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    87       return new NcaClassificationSolution(new ClassificationProblemData(problemData), this);
     79    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     80      return new NcaClassificationSolution(this, new ClassificationProblemData(problemData));
    8881    }
    8982
    90     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    91       return CreateClassificationSolution(problemData);
     83    INcaClassificationSolution INcaModel.CreateClassificationSolution(IClassificationProblemData problemData) {
     84      return new NcaClassificationSolution(this, new ClassificationProblemData(problemData));
    9285    }
    9386
     
    9588      var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    9689
    97       var targets = dataset.GetDoubleValues(targetVariable, rows).ToArray();
     90      var targets = dataset.GetDoubleValues(TargetVariable, rows).ToArray();
    9891      var result = new double[data.GetLength(0), transformationMatrix.GetLength(1) + 1];
    9992      for (int i = 0; i < data.GetLength(0); i++)
     
    111104          .Range(0, transformationMatrix.GetLength(1))
    112105          .Select(x => "X" + x.ToString())
    113           .Concat(targetVariable.ToEnumerable()),
     106          .Concat(TargetVariable.ToEnumerable()),
    114107        Reduce(dataset, rows));
    115108    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs

    r13238 r13941  
    8181    public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k) {
    8282      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    83       return new NearestNeighbourClassificationSolution(problemDataClone, Train(problemDataClone, k));
     83      return new NearestNeighbourClassificationSolution(Train(problemDataClone, k), problemDataClone);
    8484    }
    8585
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourClassificationSolution(IClassificationProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourClassificationSolution(INearestNeighbourModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("NearestNeighbourModel", "Represents a nearest neighbour model for regression and classification.")]
    36   public sealed class NearestNeighbourModel : NamedItem, INearestNeighbourModel {
     36  public sealed class NearestNeighbourModel : ClassificationModel, INearestNeighbourModel {
    3737
    3838    private alglib.nearestneighbor.kdtree kdTree;
     
    4848    }
    4949
    50     public IEnumerable<string> VariablesUsedForPrediction {
     50    public override IEnumerable<string> VariablesUsedForPrediction {
    5151      get { return allowedInputVariables; }
    5252    }
    5353
    54     public string TargetVariable {
    55       get { return targetVariable; }
    56     }
    57 
    58     [Storable]
    59     private string targetVariable;
    6054    [Storable]
    6155    private string[] allowedInputVariables;
     
    9993
    10094      k = original.k;
    101       targetVariable = original.targetVariable;
    10295      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    10396      if (original.classValues != null)
    10497        this.classValues = (double[])original.classValues.Clone();
    10598    }
    106     public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null) {
     99    public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
     100      : base(targetVariable) {
    107101      Name = ItemName;
    108102      Description = ItemDescription;
    109103      this.k = k;
    110       this.targetVariable = targetVariable;
    111104      this.allowedInputVariables = allowedInputVariables.ToArray();
    112105
     
    171164    }
    172165
    173     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     166    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    174167      if (classValues == null) throw new InvalidOperationException("No class values are defined.");
    175168      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     
    209202    }
    210203
    211     public INearestNeighbourRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    212       return new NearestNeighbourRegressionSolution(new RegressionProblemData(problemData), this);
    213     }
     204
    214205    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    215       return CreateRegressionSolution(problemData);
    216     }
    217     public INearestNeighbourClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    218       return new NearestNeighbourClassificationSolution(new ClassificationProblemData(problemData), this);
    219     }
    220     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    221       return CreateClassificationSolution(problemData);
     206      return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData));
     207    }
     208    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     209      return new NearestNeighbourClassificationSolution(this, new ClassificationProblemData(problemData));
    222210    }
    223211
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs

    r13238 r13941  
    8080    public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k) {
    8181      var clonedProblemData = (IRegressionProblemData)problemData.Clone();
    82       return new NearestNeighbourRegressionSolution(clonedProblemData, Train(problemData, k));
     82      return new NearestNeighbourRegressionSolution(Train(problemData, k), clonedProblemData);
    8383    }
    8484
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegressionSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NearestNeighbourRegressionSolution(IRegressionProblemData problemData, INearestNeighbourModel nnModel)
     45    public NearestNeighbourRegressionSolution(INearestNeighbourModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs

    r13238 r13941  
    220220
    221221      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    222       return new NeuralNetworkClassificationSolution(problemDataClone, new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()));
     222      return new NeuralNetworkClassificationSolution(new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()), problemDataClone);
    223223    }
    224224    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkClassificationSolution(IClassificationProblemData problemData, INeuralNetworkModel nnModel)
     45    public NeuralNetworkClassificationSolution(INeuralNetworkModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs

    r13238 r13941  
    204204      relClassError = alglib.mlperelclserror(mlpEnsemble, inputMatrix, nRows);
    205205      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    206       return new NeuralNetworkEnsembleClassificationSolution(problemDataClone, new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()));
     206      return new NeuralNetworkEnsembleClassificationSolution(new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables, problemDataClone.ClassValues.ToArray()), problemDataClone);
    207207    }
    208208    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkEnsembleClassificationSolution(IClassificationProblemData problemData, INeuralNetworkEnsembleModel nnModel)
     45    public NeuralNetworkEnsembleClassificationSolution(INeuralNetworkEnsembleModel nnModel, IClassificationProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("NeuralNetworkEnsembleModel", "Represents a neural network ensemble for regression and classification.")]
    36   public sealed class NeuralNetworkEnsembleModel : NamedItem, INeuralNetworkEnsembleModel {
     36  public sealed class NeuralNetworkEnsembleModel : ClassificationModel, INeuralNetworkEnsembleModel {
    3737
    3838    private alglib.mlpensemble mlpEnsemble;
     
    4848    }
    4949
    50     public string TargetVariable {
    51       get { return targetVariable; }
    52     }
    53 
    54     public IEnumerable<string> VariablesUsedForPrediction {
     50    public override IEnumerable<string> VariablesUsedForPrediction {
    5551      get { return allowedInputVariables; }
    5652    }
     
    8076    }
    8177    public NeuralNetworkEnsembleModel(alglib.mlpensemble mlpEnsemble, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
    82       : base() {
     78      : base(targetVariable) {
    8379      this.name = ItemName;
    8480      this.description = ItemDescription;
     
    111107    }
    112108
    113     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     109    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    114110      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    115111
     
    137133    }
    138134
    139     public INeuralNetworkEnsembleRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    140       return new NeuralNetworkEnsembleRegressionSolution(new RegressionEnsembleProblemData(problemData), this);
    141     }
    142     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    143       return CreateRegressionSolution(problemData);
    144     }
    145     public INeuralNetworkEnsembleClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    146       return new NeuralNetworkEnsembleClassificationSolution(new ClassificationEnsembleProblemData(problemData), this);
    147     }
    148     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    149       return CreateClassificationSolution(problemData);
     135    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     136      return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData));
     137    }
     138    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     139      return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData));
    150140    }
    151141
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs

    r13238 r13941  
    190190      avgRelError = alglib.mlpeavgrelerror(mlpEnsemble, inputMatrix, nRows);
    191191
    192       return new NeuralNetworkEnsembleRegressionSolution((IRegressionProblemData)problemData.Clone(), new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables));
     192      return new NeuralNetworkEnsembleRegressionSolution(new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone());
    193193    }
    194194    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegressionSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkEnsembleRegressionSolution(IRegressionProblemData problemData, INeuralNetworkEnsembleModel nnModel)
     45    public NeuralNetworkEnsembleRegressionSolution(INeuralNetworkEnsembleModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747      RecalculateResults();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("NeuralNetworkModel", "Represents a neural network for regression and classification.")]
    36   public sealed class NeuralNetworkModel : NamedItem, INeuralNetworkModel {
     36  public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel {
    3737
    3838    private alglib.multilayerperceptron multiLayerPerceptron;
     
    4848    }
    4949
    50     public IEnumerable<string> VariablesUsedForPrediction {
     50    public override IEnumerable<string> VariablesUsedForPrediction {
    5151      get { return allowedInputVariables; }
    5252    }
    5353
    54     public string TargetVariable {
    55       get { return targetVariable; }
    56     }
    57 
    58     [Storable]
    59     private string targetVariable;
    6054    [Storable]
    6155    private string[] allowedInputVariables;
     
    8276      multiLayerPerceptron.innerobj.x = (double[])original.multiLayerPerceptron.innerobj.x.Clone();
    8377      multiLayerPerceptron.innerobj.y = (double[])original.multiLayerPerceptron.innerobj.y.Clone();
    84       targetVariable = original.targetVariable;
    8578      allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    8679      if (original.classValues != null)
     
    8881    }
    8982    public NeuralNetworkModel(alglib.multilayerperceptron multiLayerPerceptron, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
    90       : base() {
     83      : base(targetVariable) {
    9184      this.name = ItemName;
    9285      this.description = ItemDescription;
    9386      this.multiLayerPerceptron = multiLayerPerceptron;
    94       this.targetVariable = targetVariable;
    9587      this.allowedInputVariables = allowedInputVariables.ToArray();
    9688      if (classValues != null)
     
    119111    }
    120112
    121     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     113    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    122114      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    123115
     
    145137    }
    146138
    147     public INeuralNetworkRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    148       return new NeuralNetworkRegressionSolution(new RegressionProblemData(problemData), this);
    149     }
    150     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    151       return CreateRegressionSolution(problemData);
    152     }
    153     public INeuralNetworkClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    154       return new NeuralNetworkClassificationSolution(new ClassificationProblemData(problemData), this);
    155     }
    156     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    157       return CreateClassificationSolution(problemData);
     139    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     140      return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData));
     141    }
     142    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     143      return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData));
    158144    }
    159145
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs

    r13238 r13941  
    207207      avgRelError = alglib.mlpavgrelerror(multiLayerPerceptron, inputMatrix, nRows);
    208208
    209       return new NeuralNetworkRegressionSolution((IRegressionProblemData)problemData.Clone(), new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables));
     209      return new NeuralNetworkRegressionSolution(new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone());
    210210    }
    211211    #endregion
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegressionSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public NeuralNetworkRegressionSolution(IRegressionProblemData problemData, INeuralNetworkModel nnModel)
     45    public NeuralNetworkRegressionSolution(INeuralNetworkModel nnModel, IRegressionProblemData problemData)
    4646      : base(nnModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs

    r13238 r13941  
    143143
    144144      if (CreateSolution) {
    145         var solution = new RandomForestClassificationSolution((IClassificationProblemData)Problem.ProblemData.Clone(), model);
     145        var solution = new RandomForestClassificationSolution(model, (IClassificationProblemData)Problem.ProblemData.Clone());
    146146        Results.Add(new Result(RandomForestClassificationModelResultName, "The random forest classification solution.", solution));
    147147      }
    148148    }
    149    
     149
    150150    // keep for compatibility with old API
    151151    public static RandomForestClassificationSolution CreateRandomForestClassificationSolution(IClassificationProblemData problemData, int nTrees, double r, double m, int seed,
    152152      out double rmsError, out double relClassificationError, out double outOfBagRmsError, out double outOfBagRelClassificationError) {
    153153      var model = CreateRandomForestClassificationModel(problemData, nTrees, r, m, seed, out rmsError, out relClassificationError, out outOfBagRmsError, out outOfBagRelClassificationError);
    154       return new RandomForestClassificationSolution((IClassificationProblemData)problemData.Clone(), model);
     154      return new RandomForestClassificationSolution(model, (IClassificationProblemData)problemData.Clone());
    155155    }
    156156
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassificationSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public RandomForestClassificationSolution(IClassificationProblemData problemData, IRandomForestModel randomForestModel)
     45    public RandomForestClassificationSolution(IRandomForestModel randomForestModel, IClassificationProblemData problemData)
    4646      : base(randomForestModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r13921 r13941  
    3434  [StorableClass]
    3535  [Item("RandomForestModel", "Represents a random forest for regression and classification.")]
    36   public sealed class RandomForestModel : NamedItem, IRandomForestModel {
     36  public sealed class RandomForestModel : ClassificationModel, IRandomForestModel {
    3737    // not persisted
    3838    private alglib.decisionforest randomForest;
     
    4545    }
    4646
    47     public IEnumerable<string> VariablesUsedForPrediction {
     47    public override IEnumerable<string> VariablesUsedForPrediction {
    4848      get { return originalTrainingData.AllowedInputVariables; }
    4949    }
    5050
    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     }
    6251
    6352    // instead of storing the data of the model itself
     
    10796
    10897    // random forest models can only be created through the static factory methods CreateRegressionModel and CreateClassificationModel
    109     private RandomForestModel(alglib.decisionforest randomForest,
     98    private RandomForestModel(string targetVariable, alglib.decisionforest randomForest,
    11099      int seed, IDataAnalysisProblemData originalTrainingData,
    111100      int nTrees, double r, double m, double[] classValues = null)
    112       : base() {
     101      : base(targetVariable) {
    113102      this.name = ItemName;
    114103      this.description = ItemDescription;
     
    163152    }
    164153
    165     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     154    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    166155      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows);
    167156      AssertInputMatrix(inputData);
     
    190179    }
    191180
    192     public IRandomForestRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    193       return new RandomForestRegressionSolution(new RegressionProblemData(problemData), this);
    194     }
    195     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    196       return CreateRegressionSolution(problemData);
    197     }
    198     public IRandomForestClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    199       return new RandomForestClassificationSolution(new ClassificationProblemData(problemData), this);
    200     }
    201     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    202       return CreateClassificationSolution(problemData);
     181
     182    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     183      return new RandomForestRegressionSolution(this, new RegressionProblemData(problemData));
     184    }
     185    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     186      return new RandomForestClassificationSolution(this, new ClassificationProblemData(problemData));
    203187    }
    204188
     
    221205      outOfBagRmsError = rep.oobrmserror;
    222206
    223       return new RandomForestModel(dForest, seed, problemData, nTrees, r, m);
     207      return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m);
    224208    }
    225209
     
    258242      outOfBagRelClassificationError = rep.oobrelclserror;
    259243
    260       return new RandomForestModel(dForest, seed, problemData, nTrees, r, m, classValues);
     244      return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m, classValues);
    261245    }
    262246
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs

    r13238 r13941  
    143143
    144144      if (CreateSolution) {
    145         var solution = new RandomForestRegressionSolution((IRegressionProblemData)Problem.ProblemData.Clone(), model);
     145        var solution = new RandomForestRegressionSolution(model, (IRegressionProblemData)Problem.ProblemData.Clone());
    146146        Results.Add(new Result(RandomForestRegressionModelResultName, "The random forest regression solution.", solution));
    147147      }
     
    153153      var model = CreateRandomForestRegressionModel(problemData, nTrees, r, m, seed,
    154154        out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
    155       return new RandomForestRegressionSolution((IRegressionProblemData)problemData.Clone(), model);
     155      return new RandomForestRegressionSolution(model, (IRegressionProblemData)problemData.Clone());
    156156    }
    157157
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegressionSolution.cs

    r12012 r13941  
    4343      : base(original, cloner) {
    4444    }
    45     public RandomForestRegressionSolution(IRegressionProblemData problemData, IRandomForestModel randomForestModel)
     45    public RandomForestRegressionSolution(IRandomForestModel randomForestModel, IRegressionProblemData problemData)
    4646      : base(randomForestModel, problemData) {
    4747    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs

    r13921 r13941  
    3737  [StorableClass]
    3838  [Item("SupportVectorMachineModel", "Represents a support vector machine model.")]
    39   public sealed class SupportVectorMachineModel : NamedItem, ISupportVectorMachineModel {
    40     public IEnumerable<string> VariablesUsedForPrediction {
     39  public sealed class SupportVectorMachineModel : ClassificationModel, ISupportVectorMachineModel {
     40    public override IEnumerable<string> VariablesUsedForPrediction {
    4141      get { return allowedInputVariables; }
    4242    }
    4343
    44     public string TargetVariable {
    45       get { return targetVariable; }
    46     }
    4744
    4845    private svm_model model;
     
    9087
    9188    [Storable]
    92     private string targetVariable;
    93     [Storable]
    9489    private string[] allowedInputVariables;
    9590    [Storable]
     
    10398      this.model = original.model;
    10499      this.rangeTransform = original.rangeTransform;
    105       this.targetVariable = original.targetVariable;
    106100      this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
    107101      if (original.classValues != null)
     
    113107    }
    114108    public SupportVectorMachineModel(svm_model model, RangeTransform rangeTransform, string targetVariable, IEnumerable<string> allowedInputVariables)
    115       : base() {
     109      : base(targetVariable) {
    116110      this.name = ItemName;
    117111      this.description = ItemDescription;
    118112      this.model = model;
    119113      this.rangeTransform = rangeTransform;
    120       this.targetVariable = targetVariable;
    121114      this.allowedInputVariables = allowedInputVariables.ToArray();
    122115    }
     
    130123      return GetEstimatedValuesHelper(dataset, rows);
    131124    }
    132     public SupportVectorRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     125    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    133126      return new SupportVectorRegressionSolution(this, new RegressionProblemData(problemData));
    134127    }
    135     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    136       return CreateRegressionSolution(problemData);
    137     }
    138128    #endregion
    139129
    140130    #region IClassificationModel Members
    141     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     131    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    142132      if (classValues == null) throw new NotSupportedException();
    143133      // return the original class value instead of the predicted value of the model
     
    159149    }
    160150
    161     public SupportVectorClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     151    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    162152      return new SupportVectorClassificationSolution(this, new ClassificationProblemData(problemData));
    163     }
    164     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    165       return CreateClassificationSolution(problemData);
    166153    }
    167154    #endregion
    168155    private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) {
    169156      // calculate predictions for the currently requested rows
    170       svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows);
     157      svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, TargetVariable, allowedInputVariables, rows);
    171158      svm_problem scaledProblem = rangeTransform.Scale(problem);
    172159
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs

    r13238 r13941  
    134134
    135135      var interpreter = new SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(problemData.TargetVariable);
    136       var model = new SymbolicTimeSeriesPrognosisModel(tree, interpreter);
     136      var model = new SymbolicTimeSeriesPrognosisModel(problemData.TargetVariable, tree, interpreter);
    137137      var solution = model.CreateTimeSeriesPrognosisSolution((ITimeSeriesPrognosisProblemData)problemData.Clone());
    138138      return solution;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicClassificationModelCreator.cs

    r12012 r13941  
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2727  public interface ISymbolicClassificationModelCreator : IItem {
    28     ISymbolicClassificationModel CreateSymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);
     28    ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);
    2929  }
    3030}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModelCreator.cs

    r12012 r13941  
    2525namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2626  public interface ISymbolicDiscriminantFunctionClassificationModelCreator : ISymbolicClassificationModelCreator {
    27     ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);
     27    ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);
    2828  }
    2929}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/AccuracyMaximizingThresholdsModelCreator.cs

    r12012 r13941  
    4545
    4646
    47     public ISymbolicClassificationModel CreateSymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    48       return CreateSymbolicDiscriminantFunctionClassificationModel(tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
     47    public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
     48      return CreateSymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
    4949    }
    50     public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    51       return new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter, new AccuracyMaximizationThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);
     50    public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
     51      return new SymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, new AccuracyMaximizationThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);
    5252    }
    5353
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/NearestNeighborModelCreator.cs

    r12012 r13941  
    5454
    5555
    56     public ISymbolicClassificationModel CreateSymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    57       return new SymbolicNearestNeighbourClassificationModel(KParameter.Value.Value, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
     56    public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
     57      return new SymbolicNearestNeighbourClassificationModel(targetVariable, KParameter.Value.Value, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
    5858    }
    5959
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/NormalDistributedThresholdsModelCreator.cs

    r12012 r13941  
    4646
    4747
    48     public ISymbolicClassificationModel CreateSymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    49       return CreateSymbolicDiscriminantFunctionClassificationModel(tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
     48    public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
     49      return CreateSymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
    5050    }
    51     public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    52       return new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter, new NormalDistributionCutPointsThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);
     51    public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
     52      return new SymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, new NormalDistributionCutPointsThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);
    5353    }
    5454
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r12012 r13941  
    8181
    8282    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    83       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     83      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    8484      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    8585
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs

    r12012 r13941  
    7171
    7272    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) {
    73       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     73      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    7474      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    7575
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs

    r12012 r13941  
    9191      ApplyLinearScalingParameter.ExecutionContext = context;
    9292
    93       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     93      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(problemData.TargetVariable, tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    9494      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(problemData);
    9595      model.RecalculateModelParameters(problemData, rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r12012 r13941  
    8181
    8282    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    83       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     83      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    8484      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    8585
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r12012 r13941  
    6464
    6565    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    66       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     66      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    6767      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    6868
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs

    r12012 r13941  
    7171
    7272    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    73       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     73      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    7474      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    7575
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r12012 r13941  
    6464
    6565    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    66       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     66      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    6767      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    6868
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs

    r13921 r13941  
    4242    protected SymbolicClassificationModel(bool deserializing) : base(deserializing) { }
    4343
    44     protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) : base(original, cloner) {
     44    protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner)
     45      : base(original, cloner) {
    4546      targetVariable = original.targetVariable;
    4647    }
    4748
    48     protected SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    49       double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, string targetVariable = "Target")
     49    protected SymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    5050      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
    5151      this.targetVariable = targetVariable;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPhenotypicDiversityAnalyzer.cs

    r12422 r13941  
    125125        var evaluatedValues = new ItemArray<DoubleArray>(trees.Length);
    126126        for (int i = 0; i < trees.Length; ++i) {
    127           var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper);
     127          var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(problemData.TargetVariable, trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper);
    128128          model.RecalculateModelParameters(problemData, rows);
    129129          var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs

    r12744 r13941  
    7373
    7474    protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    75       var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    7675      var classificationProblemData = (IClassificationProblemData)problemData;
     76      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(classificationProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
     77
    7778      var rows = classificationProblemData.TrainingIndices;
    7879      model.RecalculateModelParameters(classificationProblemData, rows);
     
    9394      double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) {
    9495      var clonedTree = (ISymbolicExpressionTree)tree.Clone();
    95       var model = modelCreator.CreateSymbolicClassificationModel(clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
     96      var model = modelCreator.CreateSymbolicClassificationModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    9697
    9798      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r12509 r13941  
    6565      thresholdCalculator = cloner.Clone(original.thresholdCalculator);
    6666    }
    67     public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator,
     67    public SymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator,
    6868      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    69       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     69      : base(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
    7070      this.thresholds = new double[0];
    7171      this.classValues = new double[0];
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicNearestNeighbourClassificationModel.cs

    r12509 r13941  
    5555      trainedClasses = new List<double>(original.trainedClasses);
    5656    }
    57     public SymbolicNearestNeighbourClassificationModel(int k, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    58       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     57    public SymbolicNearestNeighbourClassificationModel(string targetVariable, int k, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
     58      : base(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
    5959      this.k = k;
    6060      frequencyComparer = new ClassFrequencyComparer();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r13670 r13941  
    4343
    4444    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    45       var model = new SymbolicRegressionModel(tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
     45      var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
    4646      model.Scale(Content.ProblemData);
    4747      Content.Model = model;
     
    7373      var model = Content.Model;
    7474      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices,
    75         applyLinearScaling: true, maxIterations: 50, updateVariableWeights: true,lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit);
     75        applyLinearScaling: true, maxIterations: 50, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit);
    7676      UpdateModel(Content.Model.SymbolicExpressionTree);
    7777    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r13241 r13941  
    8989
    9090    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    91       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     91      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    9292      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    9393      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs

    r12012 r13941  
    5454
    5555    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    56       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     56      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    5757      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    5858      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r12012 r13941  
    6363
    6464    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    65       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     65      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    6666      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    6767      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r12012 r13941  
    4242
    4343    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    44       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     44      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    4545      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    4646      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs

    r12012 r13941  
    5555
    5656    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    57       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     57      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    5858      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    5959      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r12012 r13941  
    4242
    4343    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    44       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     44      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    4545      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    4646      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r13921 r13941  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    4243    protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { }
    4344
    44     protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) {
     45    protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner)
     46      : base(original, cloner) {
    4547      this.targetVariable = original.targetVariable;
    4648    }
    4749
    48     public SymbolicRegressionModel(ISymbolicExpressionTree tree,
     50    public SymbolicRegressionModel(string targetVariable, ISymbolicExpressionTree tree,
    4951      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    50       double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue,
    51       string targetVariable = "Target")
     52      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    5253      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
    5354      this.targetVariable = targetVariable;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r12744 r13941  
    6969
    7070    protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    71       return new SymbolicRegressionModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
     71      var regressionProblemData = (IRegressionProblemData)problemData;
     72      return new SymbolicRegressionModel(regressionProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    7273    }
    7374
     
    8384    public static ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, SymbolicRegressionSolutionImpactValuesCalculator impactValuesCalculator, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData, DoubleLimit estimationLimits, IEnumerable<int> rows, double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) {
    8485      var clonedTree = (ISymbolicExpressionTree)tree.Clone();
    85       var model = new SymbolicRegressionModel(clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
     86      var model = new SymbolicRegressionModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    8687      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol
    8788
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r12641 r13941  
    7575        // impact < 0 if new solution is better
    7676        // impact > 0 if new solution is worse
    77         double impact = (originalR*originalR) - (newR*newR);
     77        double impact = (originalR * originalR) - (newR * newR);
    7878        impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value);
    7979        SwitchNode(parent, replacementNode, node);
     
    8383
    8484    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    85       var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter);
     85      var model = new SymbolicTimeSeriesPrognosisModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter);
    8686      model.Scale(Content.ProblemData);
    8787      Content.Model = model;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs

    r12012 r13941  
    7272        mse = mseCalculator.MeanSquaredError;
    7373      } else if (applyLinearScaling) { //first create model to perform linear scaling and afterwards calculate fitness for the scaled model
    74         var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit);
     74        var model = new SymbolicTimeSeriesPrognosisModel(problemData.TargetVariable, (ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit);
    7575        model.Scale(problemData);
    7676        var scaledSolution = model.SymbolicExpressionTree;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r12012 r13941  
    6464
    6565    protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    66       var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     66      var model = new SymbolicTimeSeriesPrognosisModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    6767      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    6868      return new SymbolicTimeSeriesPrognosisSolution(model, (ITimeSeriesPrognosisProblemData)ProblemDataParameter.ActualValue.Clone());
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveValidationBestSolutionAnalyzer.cs

    r12012 r13941  
    5252
    5353    protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    54       var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     54      var model = new SymbolicTimeSeriesPrognosisModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    5555      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    5656
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs

    r12509 r13941  
    4747    }
    4848
    49     public SymbolicTimeSeriesPrognosisModel(ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) : base(tree, interpreter, lowerLimit, upperLimit) { }
     49    public SymbolicTimeSeriesPrognosisModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) : base(targetVariable, tree, interpreter, lowerLimit, upperLimit) { }
    5050
    5151    public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r13921 r13941  
    6161    public IEnumerable<string> VariablesUsedForPrediction {
    6262      get {
    63         return
     63        var variables =
    6464          SymbolicExpressionTree.IterateNodesPrefix()
    6565            .OfType<VariableTreeNode>()
    6666            .Select(x => x.VariableName)
    67             .Distinct()
    68             .OrderBy(x => x);
     67            .Distinct();
     68        var variableConditions = SymbolicExpressionTree.IterateNodesPrefix()
     69          .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct();
     70
     71        return variables.Union(variableConditions).OrderBy(x => x);
    6972      }
    7073    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r13766 r13941  
    132132    <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" />
    133133    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" />
     134    <Compile Include="Implementation\Classification\ClassificationModel.cs" />
    134135    <Compile Include="Implementation\Clustering\ClusteringProblem.cs" />
    135136    <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" />
    136137    <Compile Include="Implementation\Clustering\ClusteringSolution.cs" />
    137138    <Compile Include="Implementation\ConstantModel.cs" />
     139    <Compile Include="Implementation\DataAnalysisModel.cs" />
    138140    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    139141    <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" />
     
    143145    </Compile>
    144146    <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" />
     147    <Compile Include="Implementation\Regression\RegressionModel.cs" />
    145148    <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" />
    146149    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r13921 r13941  
    3232  [StorableClass]
    3333  [Item("ClassificationEnsembleModel", "A classification model that contains an ensemble of multiple classification models")]
    34   public class ClassificationEnsembleModel : NamedItem, IClassificationEnsembleModel {
    35     public IEnumerable<string> VariablesUsedForPrediction {
     34  public class ClassificationEnsembleModel : ClassificationModel, IClassificationEnsembleModel {
     35    public override IEnumerable<string> VariablesUsedForPrediction {
    3636      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    37     }
    38 
    39     public string TargetVariable {
    40       get { return models.First().TargetVariable; }
    4137    }
    4238
     
    5652    public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { }
    5753    public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models)
    58       : base() {
     54      : base(string.Empty) {
    5955      this.name = ItemName;
    6056      this.description = ItemDescription;
    6157      this.models = new List<IClassificationModel>(models);
     58
     59      if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable;
    6260    }
    6361
     
    6664    }
    6765
    68     #region IClassificationEnsembleModel Members
    6966    public void Add(IClassificationModel model) {
     67      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
    7068      models.Add(model);
    7169    }
    7270    public void Remove(IClassificationModel model) {
    7371      models.Remove(model);
     72      if (!models.Any()) TargetVariable = string.Empty;
    7473    }
    7574
     
    8584    }
    8685
    87     #endregion
    8886
    89     #region IClassificationModel Members
    90 
    91     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     87    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    9288      foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) {
    9389        // return the class which is most often occuring
     
    10197    }
    10298
    103     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
     99    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    104100      return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData));
    105101    }
    106     #endregion
     102
     103
    107104  }
    108105}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r13921 r13941  
    3333  [StorableClass]
    3434  [Item("DiscriminantFunctionClassificationModel", "Represents a classification model that uses a discriminant function and classification thresholds.")]
    35   public class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {
    36     public IEnumerable<string> VariablesUsedForPrediction {
     35  public class DiscriminantFunctionClassificationModel : ClassificationModel, IDiscriminantFunctionClassificationModel {
     36    public override IEnumerable<string> VariablesUsedForPrediction {
    3737      get { return model.VariablesUsedForPrediction; }
    3838    }
    39 
    40     public string TargetVariable { get { return model.TargetVariable; } }
    4139
    4240    [Storable]
     
    7977
    8078    public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator)
    81       : base() {
     79      : base(model.TargetVariable) {
    8280      this.name = ItemName;
    8381      this.description = ItemDescription;
     82
    8483      this.model = model;
    8584      this.classValues = new double[0];
     
    121120    }
    122121
    123     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     122    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    124123      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    125124      foreach (var x in GetEstimatedValues(dataset, rows)) {
     
    141140    #endregion
    142141
    143     public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) {
     142    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     143      return CreateDiscriminantFunctionClassificationSolution(problemData);
     144    }
     145    public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(
     146      IClassificationProblemData problemData) {
    144147      return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData));
    145     }
    146 
    147     public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    148       return CreateDiscriminantFunctionClassificationSolution(problemData);
    149148    }
    150149  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs

    r13921 r13941  
    3131  [StorableClass]
    3232  [Item("Constant Model", "A model that always returns the same constant value regardless of the presented input data.")]
    33   public class ConstantModel : NamedItem, IRegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
    34     public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
     33  public class ConstantModel : RegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
     34    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
    3535
    36     [Storable]
    37     private readonly string targetVariable;
    38     public string TargetVariable {
    39       get { return targetVariable; }
    40     }
    4136
    4237    [Storable]
     
    5247      : base(original, cloner) {
    5348      this.constant = original.constant;
    54       this.targetVariable = original.targetVariable;
    5549    }
    5650
     
    5852
    5953    public ConstantModel(double constant, string targetVariable = "Target")
    60       : base() {
     54      : base(targetVariable) {
    6155      this.name = ItemName;
    6256      this.description = ItemDescription;
    6357      this.constant = constant;
    6458      this.ReadOnly = true; // changing a constant regression model is not supported
    65       this.targetVariable = targetVariable;
    6659    }
    6760
    68     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     61    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    6962      return rows.Select(row => Constant);
    7063    }
     
    7669    }
    7770
    78     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     71    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    7972      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
    8073    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r13921 r13941  
    3232  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
    3333  [Obsolete]
    34   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     }
     34  public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue {
     35    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
    4236
    4337    [Storable]
     
    5347      : base(original, cloner) {
    5448      this.constant = original.constant;
    55       this.targetVariable = original.targetVariable;
    5649    }
    5750
     
    5952
    6053    public ConstantRegressionModel(double constant, string targetVariable = "Target")
    61       : base() {
     54      : base(targetVariable) {
    6255      this.name = ItemName;
    6356      this.description = ItemDescription;
    6457      this.constant = constant;
    6558      this.ReadOnly = true; // changing a constant regression model is not supported
    66       this.targetVariable = targetVariable;
    6759    }
    6860
    69     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     61    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    7062      return rows.Select(row => Constant);
    7163    }
    7264
    73     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     65    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    7466      return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData));
    7567    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r13921 r13941  
    3333  [StorableClass]
    3434  [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")]
    35   public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {
    36     public IEnumerable<string> VariablesUsedForPrediction {
     35  public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel {
     36    public override IEnumerable<string> VariablesUsedForPrediction {
    3737      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    3838    }
     
    4141    public IEnumerable<IRegressionModel> Models {
    4242      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; }
    4943    }
    5044
     
    109103    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { }
    110104    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights)
    111       : base() {
     105      : base(string.Empty) {
    112106      this.name = ItemName;
    113107      this.description = ItemDescription;
    114108
    115 
    116109      this.models = new List<IRegressionModel>(models);
    117110      this.modelWeights = new List<double>(modelWeights);
     111
     112      if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable;
    118113    }
    119114
    120115    public void Add(IRegressionModel model) {
     116      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
    121117      Add(model, 1.0);
    122118    }
    123119    public void Add(IRegressionModel model, double weight) {
     120      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
     121
    124122      models.Add(model);
    125123      modelWeights.Add(weight);
     
    131129    }
    132130    public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) {
     131      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable;
     132
    133133      this.models.AddRange(models);
    134134      modelWeights.AddRange(weights);
     
    140140      models.RemoveAt(index);
    141141      modelWeights.RemoveAt(index);
     142
     143      if (!models.Any()) TargetVariable = string.Empty;
    142144      OnChanged();
    143145    }
     
    148150        modelWeights.RemoveAt(index);
    149151      }
     152
     153      if (!models.Any()) TargetVariable = string.Empty;
    150154      OnChanged();
    151155    }
     
    174178    }
    175179
    176     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     180    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    177181      double weightsSum = modelWeights.Sum();
    178182      var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)
     
    222226
    223227
    224     public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     228    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    225229      return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData));
    226     }
    227     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    228       return CreateRegressionSolution(problemData);
    229230    }
    230231  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r13921 r13941  
    3030  [StorableClass]
    3131  [Item("Autoregressive TimeSeries Model", "A linear autoregressive time series model used to predict future values.")]
    32   public class TimeSeriesPrognosisAutoRegressiveModel : NamedItem, ITimeSeriesPrognosisModel {
    33     public IEnumerable<string> VariablesUsedForPrediction {
     32  public class TimeSeriesPrognosisAutoRegressiveModel : RegressionModel, ITimeSeriesPrognosisModel {
     33    public override IEnumerable<string> VariablesUsedForPrediction {
    3434      get { return Enumerable.Empty<string>(); } // what to return here?
    3535    }
     
    3939    [Storable]
    4040    public double Constant { get; private set; }
    41     [Storable]
    42     public string TargetVariable { get; private set; }
    4341
    4442    public int TimeOffset { get { return Phi.Length; } }
     
    5048      this.Phi = (double[])original.Phi.Clone();
    5149      this.Constant = original.Constant;
    52       this.TargetVariable = original.TargetVariable;
    5350    }
    5451    public override IDeepCloneable Clone(Cloner cloner) {
     
    5653    }
    5754    public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant)
    58       : base("AR(1) Model") {
     55      : base(targetVariable, "AR(1) Model") {
    5956      Phi = (double[])phi.Clone();
    6057      Constant = constant;
    61       TargetVariable = targetVariable;
    6258    }
    6359
     
    9591    }
    9692
    97     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     93    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9894      var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable);
    9995      foreach (int row in rows) {
     
    115111      return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData));
    116112    }
    117     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     113    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    118114      throw new NotSupportedException();
    119115    }
Note: See TracChangeset for help on using the changeset viewer.