Changeset 13941
- Timestamp:
- 06/28/16 13:33:17 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 77 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; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicClassificationModelCreator.cs
r12012 r13941 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 27 27 public interface ISymbolicClassificationModelCreator : IItem { 28 ISymbolicClassificationModel CreateSymbolicClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);28 ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit); 29 29 } 30 30 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModelCreator.cs
r12012 r13941 25 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 26 26 public interface ISymbolicDiscriminantFunctionClassificationModelCreator : ISymbolicClassificationModelCreator { 27 ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit);27 ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit, double upperEstimationLimit); 28 28 } 29 29 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/AccuracyMaximizingThresholdsModelCreator.cs
r12012 r13941 45 45 46 46 47 public ISymbolicClassificationModel CreateSymbolicClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {48 return CreateSymbolicDiscriminantFunctionClassificationModel(t ree, interpreter, lowerEstimationLimit, upperEstimationLimit);47 public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) { 48 return CreateSymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 49 49 } 50 public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {51 return new SymbolicDiscriminantFunctionClassificationModel(t ree, interpreter, new AccuracyMaximizationThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);50 public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) { 51 return new SymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, new AccuracyMaximizationThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit); 52 52 } 53 53 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/NearestNeighborModelCreator.cs
r12012 r13941 54 54 55 55 56 public ISymbolicClassificationModel CreateSymbolicClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {57 return new SymbolicNearestNeighbourClassificationModel( KParameter.Value.Value, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);56 public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) { 57 return new SymbolicNearestNeighbourClassificationModel(targetVariable, KParameter.Value.Value, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 58 58 } 59 59 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/ModelCreators/NormalDistributedThresholdsModelCreator.cs
r12012 r13941 46 46 47 47 48 public ISymbolicClassificationModel CreateSymbolicClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {49 return CreateSymbolicDiscriminantFunctionClassificationModel(t ree, interpreter, lowerEstimationLimit, upperEstimationLimit);48 public ISymbolicClassificationModel CreateSymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) { 49 return CreateSymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 50 50 } 51 public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {52 return new SymbolicDiscriminantFunctionClassificationModel(t ree, interpreter, new NormalDistributionCutPointsThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit);51 public ISymbolicDiscriminantFunctionClassificationModel CreateSymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) { 52 return new SymbolicDiscriminantFunctionClassificationModel(targetVariable, tree, interpreter, new NormalDistributionCutPointsThresholdCalculator(), lowerEstimationLimit, upperEstimationLimit); 53 53 } 54 54 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r13941 81 81 82 82 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 83 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);83 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 84 84 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 85 85 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r12012 r13941 71 71 72 72 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) { 73 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);73 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 74 74 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 75 75 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs
r12012 r13941 91 91 ApplyLinearScalingParameter.ExecutionContext = context; 92 92 93 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);93 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(problemData.TargetVariable, tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 94 94 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(problemData); 95 95 model.RecalculateModelParameters(problemData, rows); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r13941 81 81 82 82 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 83 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);83 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 84 84 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 85 85 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r12012 r13941 64 64 65 65 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 66 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);66 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 67 67 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 68 68 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs
r12012 r13941 71 71 72 72 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 73 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);73 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 74 74 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 75 75 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r12012 r13941 64 64 65 65 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 66 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);66 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 67 67 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 68 68 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs
r13921 r13941 42 42 protected SymbolicClassificationModel(bool deserializing) : base(deserializing) { } 43 43 44 protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) : base(original, cloner) { 44 protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) 45 : base(original, cloner) { 45 46 targetVariable = original.targetVariable; 46 47 } 47 48 48 protected SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 49 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, string targetVariable = "Target") 49 protected SymbolicClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 50 50 : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 51 51 this.targetVariable = targetVariable; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPhenotypicDiversityAnalyzer.cs
r12422 r13941 125 125 var evaluatedValues = new ItemArray<DoubleArray>(trees.Length); 126 126 for (int i = 0; i < trees.Length; ++i) { 127 var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel( trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper);127 var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(problemData.TargetVariable, trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper); 128 128 model.RecalculateModelParameters(problemData, rows); 129 129 var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r12744 r13941 73 73 74 74 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) { 75 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);76 75 var classificationProblemData = (IClassificationProblemData)problemData; 76 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(classificationProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 77 77 78 var rows = classificationProblemData.TrainingIndices; 78 79 model.RecalculateModelParameters(classificationProblemData, rows); … … 93 94 double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) { 94 95 var clonedTree = (ISymbolicExpressionTree)tree.Clone(); 95 var model = modelCreator.CreateSymbolicClassificationModel( clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);96 var model = modelCreator.CreateSymbolicClassificationModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 96 97 97 98 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r12509 r13941 65 65 thresholdCalculator = cloner.Clone(original.thresholdCalculator); 66 66 } 67 public SymbolicDiscriminantFunctionClassificationModel( ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator,67 public SymbolicDiscriminantFunctionClassificationModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator, 68 68 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 69 : base(t ree, interpreter, lowerEstimationLimit, upperEstimationLimit) {69 : base(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 70 70 this.thresholds = new double[0]; 71 71 this.classValues = new double[0]; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicNearestNeighbourClassificationModel.cs
r12509 r13941 55 55 trainedClasses = new List<double>(original.trainedClasses); 56 56 } 57 public SymbolicNearestNeighbourClassificationModel( int k, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)58 : base(t ree, interpreter, lowerEstimationLimit, upperEstimationLimit) {57 public SymbolicNearestNeighbourClassificationModel(string targetVariable, int k, ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 58 : base(targetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 59 59 this.k = k; 60 60 frequencyComparer = new ClassFrequencyComparer(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r13670 r13941 43 43 44 44 protected override void UpdateModel(ISymbolicExpressionTree tree) { 45 var model = new SymbolicRegressionModel( tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);45 var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit); 46 46 model.Scale(Content.ProblemData); 47 47 Content.Model = model; … … 73 73 var model = Content.Model; 74 74 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices, 75 applyLinearScaling: true, maxIterations: 50, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit);75 applyLinearScaling: true, maxIterations: 50, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit); 76 76 UpdateModel(Content.Model.SymbolicExpressionTree); 77 77 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r13241 r13941 89 89 90 90 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 91 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);91 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 92 92 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 93 93 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs
r12012 r13941 54 54 55 55 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 56 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);56 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 57 57 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 58 58 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r13941 63 63 64 64 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 65 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);65 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 66 66 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 67 67 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r12012 r13941 42 42 43 43 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) { 44 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);44 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs
r12012 r13941 55 55 56 56 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 57 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);57 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 58 58 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 59 59 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r12012 r13941 42 42 43 43 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) { 44 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);44 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r13921 r13941 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 42 43 protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { } 43 44 44 protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) { 45 protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) 46 : base(original, cloner) { 45 47 this.targetVariable = original.targetVariable; 46 48 } 47 49 48 public SymbolicRegressionModel( ISymbolicExpressionTree tree,50 public SymbolicRegressionModel(string targetVariable, ISymbolicExpressionTree tree, 49 51 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 50 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, 51 string targetVariable = "Target") 52 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 52 53 : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 53 54 this.targetVariable = targetVariable; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r12744 r13941 69 69 70 70 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) { 71 return new SymbolicRegressionModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 71 var regressionProblemData = (IRegressionProblemData)problemData; 72 return new SymbolicRegressionModel(regressionProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 72 73 } 73 74 … … 83 84 public static ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, SymbolicRegressionSolutionImpactValuesCalculator impactValuesCalculator, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData, DoubleLimit estimationLimits, IEnumerable<int> rows, double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) { 84 85 var clonedTree = (ISymbolicExpressionTree)tree.Clone(); 85 var model = new SymbolicRegressionModel( clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);86 var model = new SymbolicRegressionModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 86 87 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol 87 88 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r12641 r13941 75 75 // impact < 0 if new solution is better 76 76 // impact > 0 if new solution is worse 77 double impact = (originalR *originalR) - (newR*newR);77 double impact = (originalR * originalR) - (newR * newR); 78 78 impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value); 79 79 SwitchNode(parent, replacementNode, node); … … 83 83 84 84 protected override void UpdateModel(ISymbolicExpressionTree tree) { 85 var model = new SymbolicTimeSeriesPrognosisModel( tree, Content.Model.Interpreter);85 var model = new SymbolicTimeSeriesPrognosisModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter); 86 86 model.Scale(Content.ProblemData); 87 87 Content.Model = model; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r12012 r13941 72 72 mse = mseCalculator.MeanSquaredError; 73 73 } else if (applyLinearScaling) { //first create model to perform linear scaling and afterwards calculate fitness for the scaled model 74 var model = new SymbolicTimeSeriesPrognosisModel( (ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit);74 var model = new SymbolicTimeSeriesPrognosisModel(problemData.TargetVariable, (ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit); 75 75 model.Scale(problemData); 76 76 var scaledSolution = model.SymbolicExpressionTree; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r13941 64 64 65 65 protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 66 var model = new SymbolicTimeSeriesPrognosisModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);66 var model = new SymbolicTimeSeriesPrognosisModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 67 67 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 68 68 return new SymbolicTimeSeriesPrognosisSolution(model, (ITimeSeriesPrognosisProblemData)ProblemDataParameter.ActualValue.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveValidationBestSolutionAnalyzer.cs
r12012 r13941 52 52 53 53 protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 54 var model = new SymbolicTimeSeriesPrognosisModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);54 var model = new SymbolicTimeSeriesPrognosisModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 55 55 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 56 56 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
r12509 r13941 47 47 } 48 48 49 public SymbolicTimeSeriesPrognosisModel( ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) : base(tree, interpreter, lowerLimit, upperLimit) { }49 public SymbolicTimeSeriesPrognosisModel(string targetVariable, ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) : base(targetVariable, tree, interpreter, lowerLimit, upperLimit) { } 50 50 51 51 public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r13921 r13941 61 61 public IEnumerable<string> VariablesUsedForPrediction { 62 62 get { 63 return63 var variables = 64 64 SymbolicExpressionTree.IterateNodesPrefix() 65 65 .OfType<VariableTreeNode>() 66 66 .Select(x => x.VariableName) 67 .Distinct() 68 .OrderBy(x => x); 67 .Distinct(); 68 var variableConditions = SymbolicExpressionTree.IterateNodesPrefix() 69 .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct(); 70 71 return variables.Union(variableConditions).OrderBy(x => x); 69 72 } 70 73 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r13766 r13941 132 132 <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" /> 133 133 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> 134 <Compile Include="Implementation\Classification\ClassificationModel.cs" /> 134 135 <Compile Include="Implementation\Clustering\ClusteringProblem.cs" /> 135 136 <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" /> 136 137 <Compile Include="Implementation\Clustering\ClusteringSolution.cs" /> 137 138 <Compile Include="Implementation\ConstantModel.cs" /> 139 <Compile Include="Implementation\DataAnalysisModel.cs" /> 138 140 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 139 141 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> … … 143 145 </Compile> 144 146 <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" /> 147 <Compile Include="Implementation\Regression\RegressionModel.cs" /> 145 148 <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" /> 146 149 <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r13921 r13941 32 32 [StorableClass] 33 33 [Item("ClassificationEnsembleModel", "A classification model that contains an ensemble of multiple classification models")] 34 public class ClassificationEnsembleModel : NamedItem, IClassificationEnsembleModel {35 public IEnumerable<string> VariablesUsedForPrediction {34 public class ClassificationEnsembleModel : ClassificationModel, IClassificationEnsembleModel { 35 public override IEnumerable<string> VariablesUsedForPrediction { 36 36 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 37 }38 39 public string TargetVariable {40 get { return models.First().TargetVariable; }41 37 } 42 38 … … 56 52 public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { } 57 53 public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models) 58 : base( ) {54 : base(string.Empty) { 59 55 this.name = ItemName; 60 56 this.description = ItemDescription; 61 57 this.models = new List<IClassificationModel>(models); 58 59 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 62 60 } 63 61 … … 66 64 } 67 65 68 #region IClassificationEnsembleModel Members69 66 public void Add(IClassificationModel model) { 67 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 70 68 models.Add(model); 71 69 } 72 70 public void Remove(IClassificationModel model) { 73 71 models.Remove(model); 72 if (!models.Any()) TargetVariable = string.Empty; 74 73 } 75 74 … … 85 84 } 86 85 87 #endregion88 86 89 #region IClassificationModel Members 90 91 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 87 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 92 88 foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) { 93 89 // return the class which is most often occuring … … 101 97 } 102 98 103 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {99 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 104 100 return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData)); 105 101 } 106 #endregion 102 103 107 104 } 108 105 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r13921 r13941 33 33 [StorableClass] 34 34 [Item("DiscriminantFunctionClassificationModel", "Represents a classification model that uses a discriminant function and classification thresholds.")] 35 public class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {36 public IEnumerable<string> VariablesUsedForPrediction {35 public class DiscriminantFunctionClassificationModel : ClassificationModel, IDiscriminantFunctionClassificationModel { 36 public override IEnumerable<string> VariablesUsedForPrediction { 37 37 get { return model.VariablesUsedForPrediction; } 38 38 } 39 40 public string TargetVariable { get { return model.TargetVariable; } }41 39 42 40 [Storable] … … 79 77 80 78 public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator) 81 : base( ) {79 : base(model.TargetVariable) { 82 80 this.name = ItemName; 83 81 this.description = ItemDescription; 82 84 83 this.model = model; 85 84 this.classValues = new double[0]; … … 121 120 } 122 121 123 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {122 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 124 123 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 125 124 foreach (var x in GetEstimatedValues(dataset, rows)) { … … 141 140 #endregion 142 141 143 public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) { 142 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 143 return CreateDiscriminantFunctionClassificationSolution(problemData); 144 } 145 public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution( 146 IClassificationProblemData problemData) { 144 147 return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData)); 145 }146 147 public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {148 return CreateDiscriminantFunctionClassificationSolution(problemData);149 148 } 150 149 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs
r13921 r13941 31 31 [StorableClass] 32 32 [Item("Constant Model", "A model that always returns the same constant value regardless of the presented input data.")] 33 public class ConstantModel : NamedItem, IRegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {34 public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }33 public class ConstantModel : RegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue { 34 public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 35 35 36 [Storable]37 private readonly string targetVariable;38 public string TargetVariable {39 get { return targetVariable; }40 }41 36 42 37 [Storable] … … 52 47 : base(original, cloner) { 53 48 this.constant = original.constant; 54 this.targetVariable = original.targetVariable;55 49 } 56 50 … … 58 52 59 53 public ConstantModel(double constant, string targetVariable = "Target") 60 : base( ) {54 : base(targetVariable) { 61 55 this.name = ItemName; 62 56 this.description = ItemDescription; 63 57 this.constant = constant; 64 58 this.ReadOnly = true; // changing a constant regression model is not supported 65 this.targetVariable = targetVariable;66 59 } 67 60 68 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 69 62 return rows.Select(row => Constant); 70 63 } … … 76 69 } 77 70 78 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {71 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 79 72 return new ConstantRegressionSolution(this, new RegressionProblemData(problemData)); 80 73 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r13921 r13941 32 32 [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")] 33 33 [Obsolete] 34 public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue { 35 public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 36 37 [Storable] 38 private readonly string targetVariable; 39 public string TargetVariable { 40 get { return targetVariable; } 41 } 34 public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue { 35 public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 42 36 43 37 [Storable] … … 53 47 : base(original, cloner) { 54 48 this.constant = original.constant; 55 this.targetVariable = original.targetVariable;56 49 } 57 50 … … 59 52 60 53 public ConstantRegressionModel(double constant, string targetVariable = "Target") 61 : base( ) {54 : base(targetVariable) { 62 55 this.name = ItemName; 63 56 this.description = ItemDescription; 64 57 this.constant = constant; 65 58 this.ReadOnly = true; // changing a constant regression model is not supported 66 this.targetVariable = targetVariable;67 59 } 68 60 69 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 70 62 return rows.Select(row => Constant); 71 63 } 72 64 73 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 74 66 return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData)); 75 67 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13921 r13941 33 33 [StorableClass] 34 34 [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")] 35 public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {36 public IEnumerable<string> VariablesUsedForPrediction {35 public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel { 36 public override IEnumerable<string> VariablesUsedForPrediction { 37 37 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 38 38 } … … 41 41 public IEnumerable<IRegressionModel> Models { 42 42 get { return new List<IRegressionModel>(models); } 43 }44 45 [Storable]46 private readonly string target;47 public string TargetVariable {48 get { return models.First().TargetVariable; }49 43 } 50 44 … … 109 103 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { } 110 104 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights) 111 : base( ) {105 : base(string.Empty) { 112 106 this.name = ItemName; 113 107 this.description = ItemDescription; 114 108 115 116 109 this.models = new List<IRegressionModel>(models); 117 110 this.modelWeights = new List<double>(modelWeights); 111 112 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 118 113 } 119 114 120 115 public void Add(IRegressionModel model) { 116 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 117 Add(model, 1.0); 122 118 } 123 119 public void Add(IRegressionModel model, double weight) { 120 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 124 122 models.Add(model); 125 123 modelWeights.Add(weight); … … 131 129 } 132 130 public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) { 131 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable; 132 133 133 this.models.AddRange(models); 134 134 modelWeights.AddRange(weights); … … 140 140 models.RemoveAt(index); 141 141 modelWeights.RemoveAt(index); 142 143 if (!models.Any()) TargetVariable = string.Empty; 142 144 OnChanged(); 143 145 } … … 148 150 modelWeights.RemoveAt(index); 149 151 } 152 153 if (!models.Any()) TargetVariable = string.Empty; 150 154 OnChanged(); 151 155 } … … 174 178 } 175 179 176 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {180 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 177 181 double weightsSum = modelWeights.Sum(); 178 182 var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows) … … 222 226 223 227 224 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {228 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 225 229 return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData)); 226 }227 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {228 return CreateRegressionSolution(problemData);229 230 } 230 231 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r13921 r13941 30 30 [StorableClass] 31 31 [Item("Autoregressive TimeSeries Model", "A linear autoregressive time series model used to predict future values.")] 32 public class TimeSeriesPrognosisAutoRegressiveModel : NamedItem, ITimeSeriesPrognosisModel {33 public IEnumerable<string> VariablesUsedForPrediction {32 public class TimeSeriesPrognosisAutoRegressiveModel : RegressionModel, ITimeSeriesPrognosisModel { 33 public override IEnumerable<string> VariablesUsedForPrediction { 34 34 get { return Enumerable.Empty<string>(); } // what to return here? 35 35 } … … 39 39 [Storable] 40 40 public double Constant { get; private set; } 41 [Storable]42 public string TargetVariable { get; private set; }43 41 44 42 public int TimeOffset { get { return Phi.Length; } } … … 50 48 this.Phi = (double[])original.Phi.Clone(); 51 49 this.Constant = original.Constant; 52 this.TargetVariable = original.TargetVariable;53 50 } 54 51 public override IDeepCloneable Clone(Cloner cloner) { … … 56 53 } 57 54 public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant) 58 : base( "AR(1) Model") {55 : base(targetVariable, "AR(1) Model") { 59 56 Phi = (double[])phi.Clone(); 60 57 Constant = constant; 61 TargetVariable = targetVariable;62 58 } 63 59 … … 95 91 } 96 92 97 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {93 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 98 94 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 99 95 foreach (int row in rows) { … … 115 111 return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData)); 116 112 } 117 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {113 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 118 114 throw new NotSupportedException(); 119 115 }
Note: See TracChangeset
for help on using the changeset viewer.