Changeset 13941 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 06/28/16 13:33:17 (8 years ago)
- 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 139 139 } 140 140 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); 142 142 var solution = new OneRClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 143 143 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationModel.cs
r13921 r13941 31 31 [StorableClass] 32 32 [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 }; } 40 36 } 41 37 … … 74 70 public override IDeepCloneable Clone(Cloner cloner) { return new OneRClassificationModel(this, cloner); } 75 71 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) { 78 74 if (splits.Length != classes.Length) { 79 75 throw new ArgumentException("Number of splits and classes has to be equal."); … … 92 88 // uses sorting to return the values in the order of rows, instead of using nested for loops 93 89 // 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) { 95 91 var values = dataset.GetDoubleValues(Variable, rows).ToArray(); 96 92 var rowsArray = rows.ToArray(); … … 116 112 } 117 113 118 public IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {114 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 119 115 return new OneRClassificationSolution(this, new ClassificationProblemData(problemData)); 120 116 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r13917 r13941 376 376 377 377 var ensembleModel = new RegressionEnsembleModel(models, coefficients.Take(models.Count)) { AverageModelEstimates = false }; 378 var ensembleSolution = ensembleModel.CreateRegressionSolution(problemData);378 var ensembleSolution = (IRegressionEnsembleSolution)ensembleModel.CreateRegressionSolution(problemData); 379 379 return ensembleSolution; 380 380 } … … 443 443 progRootNode.AddSubtree(startNode); 444 444 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); 446 446 var sol = new SymbolicRegressionSolution(combinedModel, problemData); 447 447 return sol; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
r13922 r13941 34 34 [StorableClass] 35 35 [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 { 38 38 get { return allowedInputVariables; } 39 39 } … … 65 65 get { return meanFunction; } 66 66 } 67 [Storable] 68 private string targetVariable; 69 public string TargetVariable { 70 get { return targetVariable; } 71 } 67 72 68 [Storable] 73 69 private string[] allowedInputVariables; … … 132 128 this.trainingDataset = cloner.Clone(original.trainingDataset); 133 129 this.negativeLogLikelihood = original.negativeLogLikelihood; 134 this.targetVariable = original.targetVariable;135 130 this.sqrSigmaNoise = original.sqrSigmaNoise; 136 131 if (original.meanParameter != null) { … … 151 146 IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction, 152 147 bool scaleInputs = true) 153 : base( ) {148 : base(targetVariable) { 154 149 this.name = ItemName; 155 150 this.description = ItemDescription; 156 151 this.meanFunction = (IMeanFunction)meanFunction.Clone(); 157 152 this.covarianceFunction = (ICovarianceFunction)covarianceFunction.Clone(); 158 this.targetVariable = targetVariable;159 153 this.allowedInputVariables = allowedInputVariables.ToArray(); 160 154 … … 186 180 187 181 IEnumerable<double> y; 188 y = ds.GetDoubleValues( targetVariable, rows);182 y = ds.GetDoubleValues(TargetVariable, rows); 189 183 190 184 int n = x.GetLength(0); … … 305 299 306 300 #region IRegressionModel Members 307 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {301 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 308 302 return GetEstimatedValuesHelper(dataset, rows); 309 303 } 310 public GaussianProcessRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {304 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 311 305 return new GaussianProcessRegressionSolution(this, new RegressionProblemData(problemData)); 312 }313 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {314 return CreateRegressionSolution(problemData);315 306 } 316 307 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/StudentTProcessModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [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 { 38 38 get { return allowedInputVariables; } 39 39 } … … 65 65 get { return meanFunction; } 66 66 } 67 [Storable] 68 private string targetVariable; 69 public string TargetVariable { 70 get { return targetVariable; } 71 } 67 72 68 [Storable] 73 69 private string[] allowedInputVariables; … … 135 131 this.trainingDataset = cloner.Clone(original.trainingDataset); 136 132 this.negativeLogLikelihood = original.negativeLogLikelihood; 137 this.targetVariable = original.targetVariable;138 133 if (original.meanParameter != null) { 139 134 this.meanParameter = (double[])original.meanParameter.Clone(); … … 155 150 IEnumerable<double> hyp, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction, 156 151 bool scaleInputs = true) 157 : base( ) {152 : base(targetVariable) { 158 153 this.name = ItemName; 159 154 this.description = ItemDescription; 160 155 this.meanFunction = (IMeanFunction)meanFunction.Clone(); 161 156 this.covarianceFunction = (ICovarianceFunction)covarianceFunction.Clone(); 162 this.targetVariable = targetVariable;163 157 this.allowedInputVariables = allowedInputVariables.ToArray(); 164 158 … … 190 184 191 185 IEnumerable<double> y; 192 y = ds.GetDoubleValues( targetVariable, rows);186 y = ds.GetDoubleValues(TargetVariable, rows); 193 187 194 188 int n = x.GetLength(0); … … 322 316 323 317 #region IRegressionModel Members 324 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {318 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 325 319 return GetEstimatedValuesHelper(dataset, rows); 326 320 } 327 public GaussianProcessRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {321 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 328 322 return new GaussianProcessRegressionSolution(this, new RegressionProblemData(problemData)); 329 }330 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {331 return CreateRegressionSolution(problemData);332 323 } 333 324 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r13921 r13941 33 33 [Item("Gradient boosted tree model", "")] 34 34 // this is essentially a collection of weighted regression models 35 public sealed class GradientBoostedTreesModel : NamedItem, IGradientBoostedTreesModel {35 public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel { 36 36 // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models 37 37 #region Backwards compatible code, remove with 3.5 … … 58 58 #endregion 59 59 60 public string TargetVariable { 61 get { return models.First().TargetVariable; } 62 } 63 64 public IEnumerable<string> VariablesUsedForPrediction { 60 public override IEnumerable<string> VariablesUsedForPrediction { 65 61 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 66 62 } … … 85 81 } 86 82 [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")] 87 publicGradientBoostedTreesModel(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) { 89 85 this.models = new List<IRegressionModel>(models); 90 86 this.weights = new List<double>(weights); … … 97 93 } 98 94 99 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {95 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 100 96 // allocate target array go over all models and add up weighted estimation for each row 101 97 if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable. … … 113 109 } 114 110 115 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {111 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 116 112 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 117 113 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r13921 r13941 34 34 // recalculate the actual GBT model on demand 35 35 [Item("Gradient boosted tree model", "")] 36 public sealed class GradientBoostedTreesModelSurrogate : NamedItem, IGradientBoostedTreesModel {36 public sealed class GradientBoostedTreesModelSurrogate : RegressionModel, IGradientBoostedTreesModel { 37 37 // don't store the actual model! 38 38 private IGradientBoostedTreesModel actualModel; // the actual model is only recalculated when necessary … … 55 55 private int maxSize; 56 56 57 public string TargetVariable {58 get { return trainingProblemData.TargetVariable; }59 }60 57 61 public IEnumerable<string> VariablesUsedForPrediction {58 public override IEnumerable<string> VariablesUsedForPrediction { 62 59 get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 63 60 } … … 83 80 public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, 84 81 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) { 86 83 this.trainingProblemData = trainingProblemData; 87 84 this.seed = seed; … … 107 104 108 105 // 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) { 110 107 if (actualModel == null) actualModel = RecalculateModel(); 111 108 return actualModel.GetEstimatedValues(dataset, rows); 112 109 } 113 110 114 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {111 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 115 112 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 116 113 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [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); } 43 39 } 44 40 … … 90 86 private TreeNode[] tree; 91 87 92 #region old storable format 88 #region old storable format 93 89 // remove with HL 3.4 94 90 [Storable(AllowOneWay = true)] … … 167 163 } 168 164 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.") { 171 167 this.tree = tree; 172 168 } … … 194 190 } 195 191 196 public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {192 public override IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) { 197 193 // lookup columns for variableNames in one pass over the tree to speed up evaluation later on 198 194 ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length]; … … 208 204 } 209 205 210 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {206 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 211 207 return new RegressionSolution(this, new RegressionProblemData(problemData)); 212 208 } … … 227 223 } 228 224 } 225 229 226 } 230 227 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r12509 r13941 111 111 IClassificationProblemData problemData, 112 112 IEnumerable<int> rows) { 113 var model = new SymbolicDiscriminantFunctionClassificationModel( tree, interpreter, new AccuracyMaximizationThresholdCalculator());113 var model = new SymbolicDiscriminantFunctionClassificationModel(problemData.TargetVariable, tree, interpreter, new AccuracyMaximizationThresholdCalculator()); 114 114 model.RecalculateModelParameters(problemData, rows); 115 115 return model; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r13238 r13941 110 110 addition.AddSubtree(cNode); 111 111 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()); 113 113 solution.Model.Name = "Linear Regression Model"; 114 114 solution.Name = "Linear Regression Solution"; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs
r13238 r13941 95 95 relClassError = alglib.mnlrelclserror(lm, inputMatrix, nRows); 96 96 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()); 98 98 return solution; 99 99 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public MultinomialLogitClassificationSolution( IClassificationProblemData problemData, MultinomialLogitModel logitModel)45 public MultinomialLogitClassificationSolution( MultinomialLogitModel logitModel,IClassificationProblemData problemData) 46 46 : base(logitModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [Item("Multinomial Logit Model", "Represents a multinomial logit model for classification.")] 36 public sealed class MultinomialLogitModel : NamedItem, IClassificationModel {36 public sealed class MultinomialLogitModel : ClassificationModel { 37 37 38 38 private alglib.logitmodel logitModel; … … 48 48 } 49 49 50 public IEnumerable<string> VariablesUsedForPrediction {50 public override IEnumerable<string> VariablesUsedForPrediction { 51 51 get { return allowedInputVariables; } 52 52 } 53 53 54 public string TargetVariable {55 get { return targetVariable; }56 }57 58 [Storable]59 private string targetVariable;60 54 [Storable] 61 55 private string[] allowedInputVariables; … … 72 66 logitModel = new alglib.logitmodel(); 73 67 logitModel.innerobj.w = (double[])original.logitModel.innerobj.w.Clone(); 74 targetVariable = original.targetVariable;75 68 allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 76 69 classValues = (double[])original.classValues.Clone(); 77 70 } 78 71 public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues) 79 : base( ) {72 : base(targetVariable) { 80 73 this.name = ItemName; 81 74 this.description = ItemDescription; 82 75 this.logitModel = logitModel; 83 this.targetVariable = targetVariable;84 76 this.allowedInputVariables = allowedInputVariables.ToArray(); 85 77 this.classValues = (double[])classValues.Clone(); … … 90 82 } 91 83 92 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {84 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 93 85 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 94 86 … … 116 108 } 117 109 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)); 126 112 } 127 113 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionStatic.cs
r13669 r13941 25 25 using System.Linq; 26 26 using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies; 27 using HeuristicLab.Common;28 27 using HeuristicLab.Core; 29 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 177 176 178 177 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); 180 179 181 180 // model has already been scaled linearly in Eval -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaClassificationSolution.cs
r12012 r13941 40 40 : base(original, cloner) { 41 41 } 42 public NcaClassificationSolution(I ClassificationProblemData problemData, INcaModel ncaModel)42 public NcaClassificationSolution(INcaModel ncaModel, IClassificationProblemData problemData) 43 43 : base(ncaModel, problemData) { 44 44 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs
r13921 r13941 30 30 [Item("NCA Model", "")] 31 31 [StorableClass] 32 public class NcaModel : NamedItem, INcaModel {33 public IEnumerable<string> VariablesUsedForPrediction {32 public class NcaModel : ClassificationModel, INcaModel { 33 public override IEnumerable<string> VariablesUsedForPrediction { 34 34 get { return allowedInputVariables; } 35 }36 37 public string TargetVariable {38 get { return targetVariable; }39 35 } 40 36 … … 46 42 [Storable] 47 43 private string[] allowedInputVariables; 48 [Storable]49 private string targetVariable;50 44 [Storable] 51 45 private INearestNeighbourModel nnModel; … … 59 53 this.transformationMatrix = (double[,])original.transformationMatrix.Clone(); 60 54 this.allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 61 this.targetVariable = original.targetVariable;62 55 this.nnModel = cloner.Clone(original.nnModel); 63 56 this.classValues = (double[])original.classValues.Clone(); 64 57 } 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) { 66 60 Name = ItemName; 67 61 Description = ItemDescription; 68 62 this.transformationMatrix = (double[,])transformationMatrix.Clone(); 69 63 this.allowedInputVariables = allowedInputVariables.ToArray(); 70 this.targetVariable = targetVariable;71 64 this.classValues = (double[])classValues.Clone(); 72 65 … … 79 72 } 80 73 81 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {74 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 82 75 var ds = ReduceDataset(dataset, rows); 83 76 return nnModel.GetEstimatedClassValues(ds, Enumerable.Range(0, ds.Rows)); 84 77 } 85 78 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)); 88 81 } 89 82 90 I ClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {91 return CreateClassificationSolution(problemData);83 INcaClassificationSolution INcaModel.CreateClassificationSolution(IClassificationProblemData problemData) { 84 return new NcaClassificationSolution(this, new ClassificationProblemData(problemData)); 92 85 } 93 86 … … 95 88 var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 96 89 97 var targets = dataset.GetDoubleValues( targetVariable, rows).ToArray();90 var targets = dataset.GetDoubleValues(TargetVariable, rows).ToArray(); 98 91 var result = new double[data.GetLength(0), transformationMatrix.GetLength(1) + 1]; 99 92 for (int i = 0; i < data.GetLength(0); i++) … … 111 104 .Range(0, transformationMatrix.GetLength(1)) 112 105 .Select(x => "X" + x.ToString()) 113 .Concat( targetVariable.ToEnumerable()),106 .Concat(TargetVariable.ToEnumerable()), 114 107 Reduce(dataset, rows)); 115 108 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r13238 r13941 81 81 public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k) { 82 82 var problemDataClone = (IClassificationProblemData)problemData.Clone(); 83 return new NearestNeighbourClassificationSolution( problemDataClone, Train(problemDataClone, k));83 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k), problemDataClone); 84 84 } 85 85 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NearestNeighbourClassificationSolution(I ClassificationProblemData problemData, INearestNeighbourModel nnModel)45 public NearestNeighbourClassificationSolution(INearestNeighbourModel nnModel, IClassificationProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [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 { 37 37 38 38 private alglib.nearestneighbor.kdtree kdTree; … … 48 48 } 49 49 50 public IEnumerable<string> VariablesUsedForPrediction {50 public override IEnumerable<string> VariablesUsedForPrediction { 51 51 get { return allowedInputVariables; } 52 52 } 53 53 54 public string TargetVariable {55 get { return targetVariable; }56 }57 58 [Storable]59 private string targetVariable;60 54 [Storable] 61 55 private string[] allowedInputVariables; … … 99 93 100 94 k = original.k; 101 targetVariable = original.targetVariable;102 95 allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 103 96 if (original.classValues != null) 104 97 this.classValues = (double[])original.classValues.Clone(); 105 98 } 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) { 107 101 Name = ItemName; 108 102 Description = ItemDescription; 109 103 this.k = k; 110 this.targetVariable = targetVariable;111 104 this.allowedInputVariables = allowedInputVariables.ToArray(); 112 105 … … 171 164 } 172 165 173 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {166 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 174 167 if (classValues == null) throw new InvalidOperationException("No class values are defined."); 175 168 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); … … 209 202 } 210 203 211 public INearestNeighbourRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 212 return new NearestNeighbourRegressionSolution(new RegressionProblemData(problemData), this); 213 } 204 214 205 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)); 222 210 } 223 211 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r13238 r13941 80 80 public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k) { 81 81 var clonedProblemData = (IRegressionProblemData)problemData.Clone(); 82 return new NearestNeighbourRegressionSolution( clonedProblemData, Train(problemData, k));82 return new NearestNeighbourRegressionSolution(Train(problemData, k), clonedProblemData); 83 83 } 84 84 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegressionSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NearestNeighbourRegressionSolution(I RegressionProblemData problemData, INearestNeighbourModel nnModel)45 public NearestNeighbourRegressionSolution(INearestNeighbourModel nnModel, IRegressionProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs
r13238 r13941 220 220 221 221 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); 223 223 } 224 224 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NeuralNetworkClassificationSolution(I ClassificationProblemData problemData, INeuralNetworkModel nnModel)45 public NeuralNetworkClassificationSolution(INeuralNetworkModel nnModel, IClassificationProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs
r13238 r13941 204 204 relClassError = alglib.mlperelclserror(mlpEnsemble, inputMatrix, nRows); 205 205 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); 207 207 } 208 208 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NeuralNetworkEnsembleClassificationSolution(I ClassificationProblemData problemData, INeuralNetworkEnsembleModel nnModel)45 public NeuralNetworkEnsembleClassificationSolution(INeuralNetworkEnsembleModel nnModel, IClassificationProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [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 { 37 37 38 38 private alglib.mlpensemble mlpEnsemble; … … 48 48 } 49 49 50 public string TargetVariable { 51 get { return targetVariable; } 52 } 53 54 public IEnumerable<string> VariablesUsedForPrediction { 50 public override IEnumerable<string> VariablesUsedForPrediction { 55 51 get { return allowedInputVariables; } 56 52 } … … 80 76 } 81 77 public NeuralNetworkEnsembleModel(alglib.mlpensemble mlpEnsemble, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null) 82 : base( ) {78 : base(targetVariable) { 83 79 this.name = ItemName; 84 80 this.description = ItemDescription; … … 111 107 } 112 108 113 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {109 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 114 110 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 115 111 … … 137 133 } 138 134 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)); 150 140 } 151 141 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs
r13238 r13941 190 190 avgRelError = alglib.mlpeavgrelerror(mlpEnsemble, inputMatrix, nRows); 191 191 192 return new NeuralNetworkEnsembleRegressionSolution( (IRegressionProblemData)problemData.Clone(), new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables));192 return new NeuralNetworkEnsembleRegressionSolution(new NeuralNetworkEnsembleModel(mlpEnsemble, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone()); 193 193 } 194 194 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegressionSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NeuralNetworkEnsembleRegressionSolution(I RegressionProblemData problemData, INeuralNetworkEnsembleModel nnModel)45 public NeuralNetworkEnsembleRegressionSolution(INeuralNetworkEnsembleModel nnModel, IRegressionProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 RecalculateResults(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [Item("NeuralNetworkModel", "Represents a neural network for regression and classification.")] 36 public sealed class NeuralNetworkModel : NamedItem, INeuralNetworkModel {36 public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel { 37 37 38 38 private alglib.multilayerperceptron multiLayerPerceptron; … … 48 48 } 49 49 50 public IEnumerable<string> VariablesUsedForPrediction {50 public override IEnumerable<string> VariablesUsedForPrediction { 51 51 get { return allowedInputVariables; } 52 52 } 53 53 54 public string TargetVariable {55 get { return targetVariable; }56 }57 58 [Storable]59 private string targetVariable;60 54 [Storable] 61 55 private string[] allowedInputVariables; … … 82 76 multiLayerPerceptron.innerobj.x = (double[])original.multiLayerPerceptron.innerobj.x.Clone(); 83 77 multiLayerPerceptron.innerobj.y = (double[])original.multiLayerPerceptron.innerobj.y.Clone(); 84 targetVariable = original.targetVariable;85 78 allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 86 79 if (original.classValues != null) … … 88 81 } 89 82 public NeuralNetworkModel(alglib.multilayerperceptron multiLayerPerceptron, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null) 90 : base( ) {83 : base(targetVariable) { 91 84 this.name = ItemName; 92 85 this.description = ItemDescription; 93 86 this.multiLayerPerceptron = multiLayerPerceptron; 94 this.targetVariable = targetVariable;95 87 this.allowedInputVariables = allowedInputVariables.ToArray(); 96 88 if (classValues != null) … … 119 111 } 120 112 121 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {113 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 122 114 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 123 115 … … 145 137 } 146 138 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)); 158 144 } 159 145 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs
r13238 r13941 207 207 avgRelError = alglib.mlpavgrelerror(multiLayerPerceptron, inputMatrix, nRows); 208 208 209 return new NeuralNetworkRegressionSolution( (IRegressionProblemData)problemData.Clone(), new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables));209 return new NeuralNetworkRegressionSolution(new NeuralNetworkModel(multiLayerPerceptron, targetVariable, allowedInputVariables), (IRegressionProblemData)problemData.Clone()); 210 210 } 211 211 #endregion -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegressionSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public NeuralNetworkRegressionSolution(I RegressionProblemData problemData, INeuralNetworkModel nnModel)45 public NeuralNetworkRegressionSolution(INeuralNetworkModel nnModel, IRegressionProblemData problemData) 46 46 : base(nnModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
r13238 r13941 143 143 144 144 if (CreateSolution) { 145 var solution = new RandomForestClassificationSolution( (IClassificationProblemData)Problem.ProblemData.Clone(), model);145 var solution = new RandomForestClassificationSolution(model, (IClassificationProblemData)Problem.ProblemData.Clone()); 146 146 Results.Add(new Result(RandomForestClassificationModelResultName, "The random forest classification solution.", solution)); 147 147 } 148 148 } 149 149 150 150 // keep for compatibility with old API 151 151 public static RandomForestClassificationSolution CreateRandomForestClassificationSolution(IClassificationProblemData problemData, int nTrees, double r, double m, int seed, 152 152 out double rmsError, out double relClassificationError, out double outOfBagRmsError, out double outOfBagRelClassificationError) { 153 153 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()); 155 155 } 156 156 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassificationSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public RandomForestClassificationSolution(I ClassificationProblemData problemData, IRandomForestModel randomForestModel)45 public RandomForestClassificationSolution(IRandomForestModel randomForestModel, IClassificationProblemData problemData) 46 46 : base(randomForestModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs
r13921 r13941 34 34 [StorableClass] 35 35 [Item("RandomForestModel", "Represents a random forest for regression and classification.")] 36 public sealed class RandomForestModel : NamedItem, IRandomForestModel {36 public sealed class RandomForestModel : ClassificationModel, IRandomForestModel { 37 37 // not persisted 38 38 private alglib.decisionforest randomForest; … … 45 45 } 46 46 47 public IEnumerable<string> VariablesUsedForPrediction {47 public override IEnumerable<string> VariablesUsedForPrediction { 48 48 get { return originalTrainingData.AllowedInputVariables; } 49 49 } 50 50 51 public string TargetVariable {52 get {53 var regressionProblemData = originalTrainingData as IRegressionProblemData;54 var classificationProblemData = originalTrainingData as IClassificationProblemData;55 if (classificationProblemData != null)56 return classificationProblemData.TargetVariable;57 if (regressionProblemData != null)58 return regressionProblemData.TargetVariable;59 throw new InvalidOperationException("Getting the target variable requires either a regression or a classification problem data.");60 }61 }62 51 63 52 // instead of storing the data of the model itself … … 107 96 108 97 // 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, 110 99 int seed, IDataAnalysisProblemData originalTrainingData, 111 100 int nTrees, double r, double m, double[] classValues = null) 112 : base( ) {101 : base(targetVariable) { 113 102 this.name = ItemName; 114 103 this.description = ItemDescription; … … 163 152 } 164 153 165 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {154 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 166 155 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows); 167 156 AssertInputMatrix(inputData); … … 190 179 } 191 180 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)); 203 187 } 204 188 … … 221 205 outOfBagRmsError = rep.oobrmserror; 222 206 223 return new RandomForestModel( dForest, seed, problemData, nTrees, r, m);207 return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m); 224 208 } 225 209 … … 258 242 outOfBagRelClassificationError = rep.oobrelclserror; 259 243 260 return new RandomForestModel( dForest, seed, problemData, nTrees, r, m, classValues);244 return new RandomForestModel(problemData.TargetVariable, dForest, seed, problemData, nTrees, r, m, classValues); 261 245 } 262 246 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
r13238 r13941 143 143 144 144 if (CreateSolution) { 145 var solution = new RandomForestRegressionSolution( (IRegressionProblemData)Problem.ProblemData.Clone(), model);145 var solution = new RandomForestRegressionSolution(model, (IRegressionProblemData)Problem.ProblemData.Clone()); 146 146 Results.Add(new Result(RandomForestRegressionModelResultName, "The random forest regression solution.", solution)); 147 147 } … … 153 153 var model = CreateRandomForestRegressionModel(problemData, nTrees, r, m, seed, 154 154 out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError); 155 return new RandomForestRegressionSolution( (IRegressionProblemData)problemData.Clone(), model);155 return new RandomForestRegressionSolution(model, (IRegressionProblemData)problemData.Clone()); 156 156 } 157 157 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegressionSolution.cs
r12012 r13941 43 43 : base(original, cloner) { 44 44 } 45 public RandomForestRegressionSolution(IR egressionProblemData problemData, IRandomForestModel randomForestModel)45 public RandomForestRegressionSolution(IRandomForestModel randomForestModel, IRegressionProblemData problemData) 46 46 : base(randomForestModel, problemData) { 47 47 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r13921 r13941 37 37 [StorableClass] 38 38 [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 { 41 41 get { return allowedInputVariables; } 42 42 } 43 43 44 public string TargetVariable {45 get { return targetVariable; }46 }47 44 48 45 private svm_model model; … … 90 87 91 88 [Storable] 92 private string targetVariable;93 [Storable]94 89 private string[] allowedInputVariables; 95 90 [Storable] … … 103 98 this.model = original.model; 104 99 this.rangeTransform = original.rangeTransform; 105 this.targetVariable = original.targetVariable;106 100 this.allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 107 101 if (original.classValues != null) … … 113 107 } 114 108 public SupportVectorMachineModel(svm_model model, RangeTransform rangeTransform, string targetVariable, IEnumerable<string> allowedInputVariables) 115 : base( ) {109 : base(targetVariable) { 116 110 this.name = ItemName; 117 111 this.description = ItemDescription; 118 112 this.model = model; 119 113 this.rangeTransform = rangeTransform; 120 this.targetVariable = targetVariable;121 114 this.allowedInputVariables = allowedInputVariables.ToArray(); 122 115 } … … 130 123 return GetEstimatedValuesHelper(dataset, rows); 131 124 } 132 public SupportVectorRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {125 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 133 126 return new SupportVectorRegressionSolution(this, new RegressionProblemData(problemData)); 134 127 } 135 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {136 return CreateRegressionSolution(problemData);137 }138 128 #endregion 139 129 140 130 #region IClassificationModel Members 141 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {131 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 142 132 if (classValues == null) throw new NotSupportedException(); 143 133 // return the original class value instead of the predicted value of the model … … 159 149 } 160 150 161 public SupportVectorClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {151 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 162 152 return new SupportVectorClassificationSolution(this, new ClassificationProblemData(problemData)); 163 }164 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {165 return CreateClassificationSolution(problemData);166 153 } 167 154 #endregion 168 155 private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) { 169 156 // 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); 171 158 svm_problem scaledProblem = rangeTransform.Scale(problem); 172 159 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs
r13238 r13941 134 134 135 135 var interpreter = new SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(problemData.TargetVariable); 136 var model = new SymbolicTimeSeriesPrognosisModel( tree, interpreter);136 var model = new SymbolicTimeSeriesPrognosisModel(problemData.TargetVariable, tree, interpreter); 137 137 var solution = model.CreateTimeSeriesPrognosisSolution((ITimeSeriesPrognosisProblemData)problemData.Clone()); 138 138 return solution;
Note: See TracChangeset
for help on using the changeset viewer.