Free cookie consent management tool by TermsFeed Policy Generator

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/HeuristicLab.Algorithms.DataAnalysis/3.4
Files:
38 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;
Note: See TracChangeset for help on using the changeset viewer.