Changeset 17054
- Timestamp:
- 07/04/19 13:00:24 (5 years ago)
- Location:
- stable
- Files:
-
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 16241,16243-16244,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis merged: 16243,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged: 16243,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r16167 r17054 262 262 263 263 264 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 265 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 266 } 267 268 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 269 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 270 271 var regressionProblemData = problemData as IRegressionProblemData; 272 if (regressionProblemData != null) 273 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 274 275 var classificationProblemData = problemData as IClassificationProblemData; 276 if (classificationProblemData != null) 277 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 278 279 throw new ArgumentException("The problem data is not compatible with this nearest neighbour model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 280 } 281 264 282 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) { 265 283 return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
r16387 r17054 130 130 } 131 131 132 133 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 134 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 135 } 136 137 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 138 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 139 140 var regressionProblemData = problemData as IRegressionProblemData; 141 if (regressionProblemData != null) 142 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 143 144 var classificationProblemData = problemData as IClassificationProblemData; 145 if (classificationProblemData != null) 146 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 147 148 throw new ArgumentException("The problem data is not compatible with this neural network ensemble. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 149 } 150 132 151 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 133 152 return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r16387 r17054 134 134 } 135 135 136 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 137 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 138 } 139 140 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 141 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 142 143 var regressionProblemData = problemData as IRegressionProblemData; 144 if (regressionProblemData != null) 145 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 146 147 var classificationProblemData = problemData as IClassificationProblemData; 148 if (classificationProblemData != null) 149 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 150 151 throw new ArgumentException("The problem data is not compatible with this neural network. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 152 } 153 136 154 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 137 155 return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs
r15788 r17054 286 286 } 287 287 288 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 289 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 290 } 291 292 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 293 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 294 295 var regressionProblemData = problemData as IRegressionProblemData; 296 if (regressionProblemData != null) 297 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 298 299 var classificationProblemData = problemData as IClassificationProblemData; 300 if (classificationProblemData != null) 301 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 302 303 throw new ArgumentException("The problem data is not compatible with this random forest. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 304 } 305 288 306 public static RandomForestModel CreateRegressionModel(IRegressionProblemData problemData, int nTrees, double r, double m, int seed, 289 307 out double rmsError, out double outOfBagRmsError, out double avgRelError, out double outOfBagAvgRelError) { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r16160 r17054 126 126 return new SupportVectorRegressionSolution(this, new RegressionProblemData(problemData)); 127 127 } 128 #endregion 128 129 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 130 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 131 } 132 #endregion 133 134 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 135 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 136 137 var regressionProblemData = problemData as IRegressionProblemData; 138 if (regressionProblemData != null) 139 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 140 141 var classificationProblemData = problemData as IClassificationProblemData; 142 if (classificationProblemData != null) 143 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 144 145 throw new ArgumentException("The problem data is not compatible with this SVM. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 146 } 129 147 130 148 #region IClassificationModel Members … … 153 171 } 154 172 #endregion 173 155 174 private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) { 156 175 // calculate predictions for the currently requested rows -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs
r15584 r17054 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; … … 34 35 [StorableClass] 35 36 [Item("KMeansClusteringModel", "Represents a k-Means clustering model.")] 36 public sealed class KMeansClusteringModel : NamedItem, IClusteringModel {37 public sealed class KMeansClusteringModel : DataAnalysisModel, IClusteringModel { 37 38 public static new Image StaticItemImage { 38 39 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 39 40 } 40 41 41 public IEnumerable<string> VariablesUsedForPrediction {42 public override IEnumerable<string> VariablesUsedForPrediction { 42 43 get { return allowedInputVariables; } 43 44 } … … 84 85 } 85 86 87 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 88 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 89 return IsDatasetCompatible(problemData.Dataset, out errorMessage); 90 } 91 86 92 87 93 public IEnumerable<int> GetClusterValues(IDataset dataset, IEnumerable<int> rows) { -
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis merged: 16241,16243-16244,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16243
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged: 16243,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs
r15584 r17054 74 74 } 75 75 76 public virtual bool IsProblemDataCompatible(IClassificationProblemData problemData, out string errorMessage) { 77 return ClassificationModel.IsProblemDataCompatible(this, problemData, out errorMessage); 78 } 79 80 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 81 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 82 var classificationProblemData = problemData as IClassificationProblemData; 83 if (classificationProblemData == null) 84 throw new ArgumentException("The problem data is not compatible with this classification model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 85 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 86 } 87 76 88 #region events 77 89 public event EventHandler TargetVariableChanged; -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression (added) merged: 16243,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 (added) merged: 16243,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r15584 r17054 83 83 } 84 84 85 public virtual bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 86 return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage); 87 } 88 89 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 90 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 91 var regressionProblemData = problemData as IRegressionProblemData; 92 if (regressionProblemData == null) 93 throw new ArgumentException("The problem data is not compatible with this symbolic regression model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 94 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 95 } 96 85 97 #region events 86 98 public event EventHandler TargetVariableChanged; -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r15584 r17054 34 34 /// </summary> 35 35 [StorableClass] 36 public abstract class SymbolicDataAnalysisModel : NamedItem, ISymbolicDataAnalysisModel {36 public abstract class SymbolicDataAnalysisModel : DataAnalysisModel, ISymbolicDataAnalysisModel { 37 37 public static new Image StaticItemImage { 38 38 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } … … 59 59 } 60 60 61 public IEnumerable<string> VariablesUsedForPrediction {61 public override IEnumerable<string> VariablesUsedForPrediction { 62 62 get { 63 63 var variables = -
stable/HeuristicLab.Problems.DataAnalysis.Trading/3.4/ProblemData.cs
r15584 r17054 1650 1650 OnChanged(); 1651 1651 } 1652 1653 public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {1654 var data = problemData as ProblemData;1655 if (data == null) throw new ArgumentException("The problem data is not a problem data set for trading. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");1656 1657 string errorMessage;1658 if (!data.IsProblemDataCompatible(this, out errorMessage)) {1659 throw new InvalidOperationException(errorMessage);1660 }1661 1662 base.AdjustProblemDataProperties(data);1663 1664 var toDelete = PriceChangeVariableParameter.ValidValues.ToList();1665 foreach (var entry in data.PriceChangeVariableParameter.ValidValues) {1666 if (toDelete.Any(x => x.Value == entry.Value)) {1667 toDelete.RemoveAll(x => x.Value == entry.Value);1668 } else {1669 PriceChangeVariableParameter.ValidValues.Add(new StringValue(entry.Value));1670 }1671 }1672 PriceChangeVariableParameter.Value =1673 PriceChangeVariableParameter.ValidValues.Single(v => v.Value == data.PriceChangeVariable);1674 1675 foreach (var varToDelete in toDelete) PriceChangeVariableParameter.ValidValues.Remove(varToDelete);1676 1677 TransactionCostsParameter.Value.Value = data.TransactionCosts;1678 1679 OnChanged();1680 }1681 1652 } 1682 1653 } -
stable/HeuristicLab.Problems.DataAnalysis.Trading/3.4/Symbolic/Model.cs
r15584 r17054 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 53 54 } 54 55 56 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 57 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 58 return IsDatasetCompatible(problemData.Dataset, out errorMessage); 59 } 60 61 55 62 // Transforms an enumerable of real values to an enumerable of trading signals (buy(1) / hold(0) / sell(-1)) 56 63 public static IEnumerable<double> GetSignals(IEnumerable<double> xs) { -
stable/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views merged: 16244
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4 merged: 16244
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs
r15584 r17054 141 141 142 142 var solution = (IDataAnalysisSolution)Content.Clone(); 143 problemData.AdjustProblemDataProperties(solution.ProblemData);144 145 143 solution.ProblemData = problemData; 146 144 if (!solution.Name.EndsWith(" with loaded problemData")) … … 231 229 232 230 try { 233 problemData.AdjustProblemDataProperties(Content.ProblemData);234 231 Content.ProblemData = problemData; 235 232 -
stable/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis/3.4 merged: 16241,16243-16244,16763
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r16247 r17054 167 167 } 168 168 } 169 170 public bool ContainsVariable(string variableName) { 171 return variableValues.ContainsKey(variableName); 172 } 169 173 public IEnumerable<string> DoubleVariables { 170 174 get { return variableValues.Where(p => p.Value is IList<double>).Select(p => p.Key); } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationModel.cs
r15584 r17054 66 66 public abstract IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 67 67 68 public virtual bool IsProblemDataCompatible(IClassificationProblemData problemData, out string errorMessage) { 69 return IsProblemDataCompatible(this, problemData, out errorMessage); 70 } 71 72 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 73 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 74 var classificationProblemData = problemData as IClassificationProblemData; 75 if (classificationProblemData == null) 76 throw new ArgumentException("The problem data is not compatible with this classification model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 77 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 78 } 79 80 public static bool IsProblemDataCompatible(IClassificationModel model, IClassificationProblemData problemData, out string errorMessage) { 81 if (model == null) throw new ArgumentNullException("model", "The provided model is null."); 82 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 83 errorMessage = string.Empty; 84 85 if (model.TargetVariable != problemData.TargetVariable) 86 errorMessage = string.Format("The target variable of the model {0} does not match the target variable of the problemData {1}.", model.TargetVariable, problemData.TargetVariable); 87 88 var evaluationErrorMessage = string.Empty; 89 var datasetCompatible = model.IsDatasetCompatible(problemData.Dataset, out evaluationErrorMessage); 90 if (!datasetCompatible) 91 errorMessage += evaluationErrorMessage; 92 93 return string.IsNullOrEmpty(errorMessage); 94 } 95 68 96 #region events 69 97 public event EventHandler TargetVariableChanged; -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r15584 r17054 467 467 } 468 468 #endregion 469 470 protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {471 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");472 IClassificationProblemData classificationProblemData = problemData as IClassificationProblemData;473 if (classificationProblemData == null)474 throw new ArgumentException("The problem data is no classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");475 476 var returnValue = base.IsProblemDataCompatible(classificationProblemData, out errorMessage);477 //check targetVariable478 if (classificationProblemData.InputVariables.All(var => var.Value != TargetVariable)) {479 errorMessage = string.Format("The target variable {0} is not present in the new problem data.", TargetVariable)480 + Environment.NewLine + errorMessage;481 return false;482 }483 484 var newClassValues = classificationProblemData.Dataset.GetDoubleValues(TargetVariable).Distinct().OrderBy(x => x);485 if (!newClassValues.SequenceEqual(ClassValues)) {486 errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data.");487 returnValue = false;488 }489 490 var newPositivieClassName = classificationProblemData.PositiveClass;491 if (newPositivieClassName != PositiveClass) {492 errorMessage = errorMessage + string.Format("The positive class differs in the provided classification problem data.");493 returnValue = false;494 }495 496 return returnValue;497 }498 499 public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {500 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");501 ClassificationProblemData classificationProblemData = problemData as ClassificationProblemData;502 if (classificationProblemData == null)503 throw new ArgumentException("The problem data is not a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");504 505 base.AdjustProblemDataProperties(problemData);506 TargetVariable = classificationProblemData.TargetVariable;507 for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)508 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);509 510 PositiveClass = classificationProblemData.PositiveClass;511 512 for (int i = 0; i < Classes; i++) {513 for (int j = 0; j < Classes; j++) {514 ClassificationPenaltiesParameter.Value[i, j] = classificationProblemData.GetClassificationPenalty(ClassValuesCache[i], ClassValuesCache[j]);515 }516 }517 }518 469 } 519 470 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r15584 r17054 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 44 45 public new IClassificationProblemData ProblemData { 45 46 get { return (IClassificationProblemData)base.ProblemData; } 46 set { base.ProblemData = value; } 47 set { 48 if (value == null) throw new ArgumentNullException("The problemData must not be null."); 49 string errorMessage = string.Empty; 50 if (!Model.IsProblemDataCompatible(value, out errorMessage)) throw new ArgumentException(errorMessage); 51 52 base.ProblemData = value; 53 } 47 54 } 48 55 -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs
r15584 r17054 83 83 } 84 84 85 public virtual bool IsProblemDataCompatible(IClassificationProblemData problemData, out string errorMessage) { 86 return ClassificationModel.IsProblemDataCompatible(this, problemData, out errorMessage); 87 } 88 89 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 90 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 91 92 var regressionProblemData = problemData as IRegressionProblemData; 93 if (regressionProblemData != null) 94 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 95 96 var classificationProblemData = problemData as IClassificationProblemData; 97 if (classificationProblemData != null) 98 return IsProblemDataCompatible(classificationProblemData, out errorMessage); 99 100 throw new ArgumentException("The problem data is compatible with this model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 101 } 102 85 103 #region IStringConvertibleValue 86 104 public bool ReadOnly { get; private set; } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisModel.cs
r15584 r17054 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 38 39 39 40 public abstract IEnumerable<string> VariablesUsedForPrediction { get; } 41 42 public virtual bool IsDatasetCompatible(IDataset dataset, out string errorMessage) { 43 if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null."); 44 return IsDatasetCompatible(this, dataset, out errorMessage); 45 } 46 47 public abstract bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage); 48 49 public static bool IsDatasetCompatible(IDataAnalysisModel model, IDataset dataset, out string errorMessage) { 50 if(model == null) throw new ArgumentNullException("model", "The provided model is null."); 51 if (dataset == null) throw new ArgumentNullException("dataset", "The provided dataset is null."); 52 errorMessage = string.Empty; 53 54 foreach (var variable in model.VariablesUsedForPrediction) { 55 if (!dataset.ContainsVariable(variable)) { 56 if (string.IsNullOrEmpty(errorMessage)) { 57 errorMessage = "The following variables must be present in the dataset for model evaluation:"; 58 } 59 errorMessage += System.Environment.NewLine + " " + variable; 60 } 61 } 62 63 return string.IsNullOrEmpty(errorMessage); 64 } 40 65 } 41 66 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r16164 r17054 207 207 if (listeners != null) listeners(this, EventArgs.Empty); 208 208 } 209 210 protected virtual bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {211 errorMessage = string.Empty;212 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");213 214 //check allowed input variables215 StringBuilder message = new StringBuilder();216 var variables = new HashSet<string>(problemData.InputVariables.Select(x => x.Value));217 foreach (var item in AllowedInputVariables) {218 if (!variables.Contains(item))219 message.AppendLine("Input variable '" + item + "' is not present in the new problem data.");220 }221 222 if (message.Length != 0) {223 errorMessage = message.ToString();224 return false;225 }226 return true;227 228 }229 230 public virtual void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {231 DataAnalysisProblemData data = problemData as DataAnalysisProblemData;232 if (data == null) throw new ArgumentException("The problem data is not a data analysis problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");233 234 string errorMessage;235 if (!data.IsProblemDataCompatible(this, out errorMessage)) {236 throw new InvalidOperationException(errorMessage);237 }238 239 foreach (var inputVariable in InputVariables) {240 var variable = data.InputVariables.FirstOrDefault(i => i.Value == inputVariable.Value);241 InputVariables.SetItemCheckedState(inputVariable, variable != null && data.InputVariables.ItemChecked(variable));242 }243 }244 209 } 245 210 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs
r15584 r17054 58 58 get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; } 59 59 set { 60 if (this[ProblemDataResultName].Value != value) { 61 if (value != null) { 62 ProblemData.Changed -= new EventHandler(ProblemData_Changed); 63 this[ProblemDataResultName].Value = value; 64 ProblemData.Changed += new EventHandler(ProblemData_Changed); 65 OnProblemDataChanged(); 66 } 67 } 60 if (value == null) throw new ArgumentNullException("The problemData must not be null."); 61 if (this[ProblemDataResultName].Value == value) return; 62 string errorMessage = string.Empty; 63 if (!Model.IsProblemDataCompatible(value, out errorMessage)) throw new ArgumentException(errorMessage); 64 65 ProblemData.Changed -= new EventHandler(ProblemData_Changed); 66 this[ProblemDataResultName].Value = value; 67 ProblemData.Changed += new EventHandler(ProblemData_Changed); 68 OnProblemDataChanged(); 68 69 } 69 70 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionModel.cs
r15584 r17054 67 67 public abstract IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData); 68 68 69 public virtual bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) { 70 return IsProblemDataCompatible(this, problemData, out errorMessage); 71 } 72 73 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 74 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 75 var regressionProblemData = problemData as IRegressionProblemData; 76 if (regressionProblemData == null) 77 throw new ArgumentException("The problem data is not compatible with this regression model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 78 return IsProblemDataCompatible(regressionProblemData, out errorMessage); 79 } 80 81 public static bool IsProblemDataCompatible(IRegressionModel model, IRegressionProblemData problemData, out string errorMessage) { 82 if (model == null) throw new ArgumentNullException("model", "The provided model is null."); 83 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null."); 84 errorMessage = string.Empty; 85 86 if (model.TargetVariable != problemData.TargetVariable) 87 errorMessage = string.Format("The target variable of the model {0} does not match the target variable of the problemData {1}.", model.TargetVariable, problemData.TargetVariable); 88 89 var evaluationErrorMessage = string.Empty; 90 var datasetCompatible = model.IsDatasetCompatible(problemData.Dataset, out evaluationErrorMessage); 91 if (!datasetCompatible) 92 errorMessage += evaluationErrorMessage; 93 94 return string.IsNullOrEmpty(errorMessage); 95 } 96 69 97 #region events 70 98 public event EventHandler TargetVariableChanged; -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r15584 r17054 161 161 OnChanged(); 162 162 } 163 164 protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {165 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");166 IRegressionProblemData regressionProblemData = problemData as IRegressionProblemData;167 if (regressionProblemData == null)168 throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");169 170 var returnValue = base.IsProblemDataCompatible(problemData, out errorMessage);171 return returnValue;172 }173 174 public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {175 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");176 RegressionProblemData regressionProblemData = problemData as RegressionProblemData;177 if (regressionProblemData == null)178 throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");179 180 base.AdjustProblemDataProperties(problemData);181 }182 163 } 183 164 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r15584 r17054 70 70 public new IRegressionProblemData ProblemData { 71 71 get { return (IRegressionProblemData)base.ProblemData; } 72 set { base.ProblemData = value; } 72 set { 73 if (value == null) throw new ArgumentNullException("The problemData must not be null."); 74 string errorMessage = string.Empty; 75 if (!Model.IsProblemDataCompatible(value, out errorMessage)) throw new ArgumentException(errorMessage); 76 77 base.ProblemData = value; 78 } 73 79 } 74 80 -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r15584 r17054 1620 1620 OnChanged(); 1621 1621 } 1622 1623 protected override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {1624 if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");1625 ITimeSeriesPrognosisProblemData timeseriesProblemData = problemData as ITimeSeriesPrognosisProblemData;1626 if (timeseriesProblemData == null)1627 throw new ArgumentException("The problem data is not a time-series problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");1628 1629 var returnValue = base.IsProblemDataCompatible(problemData, out errorMessage);1630 //check targetVariable1631 if (problemData.InputVariables.All(var => var.Value != TargetVariable)) {1632 errorMessage = string.Format("The target variable {0} is not present in the new problem data.", TargetVariable)1633 + Environment.NewLine + errorMessage;1634 return false;1635 }1636 return returnValue;1637 }1638 1639 public override void AdjustProblemDataProperties(IDataAnalysisProblemData problemData) {1640 TimeSeriesPrognosisProblemData timeSeriesProblemData = problemData as TimeSeriesPrognosisProblemData;1641 if (timeSeriesProblemData == null)1642 throw new ArgumentException("The problem data is not a timeseries problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");1643 1644 var trainingDataStart = TrainingIndices.First();1645 1646 base.AdjustProblemDataProperties(problemData);1647 1648 TestPartition.Start = trainingDataStart;1649 1650 TrainingHorizon = timeSeriesProblemData.TrainingHorizon;1651 TestHorizon = timeSeriesProblemData.TestHorizon;1652 }1653 1654 1622 } 1655 1623 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs
r15584 r17054 31 31 IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows); 32 32 IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 33 bool IsProblemDataCompatible(IClassificationProblemData problemData, out string errorMessage); 33 34 string TargetVariable { get; set; } 34 35 event EventHandler TargetVariableChanged; -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs
r15584 r17054 30 30 public interface IDataAnalysisModel : INamedItem { 31 31 IEnumerable<string> VariablesUsedForPrediction { get; } 32 bool IsDatasetCompatible(IDataset dataset, out string errorMessage); 33 bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage); 32 34 } 33 35 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r15584 r17054 49 49 50 50 event EventHandler Changed; 51 52 void AdjustProblemDataProperties(IDataAnalysisProblemData problemData);53 51 } 54 52 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataset.cs
r15584 r17054 33 33 IEnumerable<string> DateTimeVariables { get; } 34 34 35 bool ContainsVariable(string variablename); 35 36 bool VariableHasType<T>(string variableName); 36 37 -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs
r15584 r17054 31 31 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 32 32 IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData); 33 bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage); 33 34 string TargetVariable { get; set; } 34 35 event EventHandler TargetVariableChanged;
Note: See TracChangeset
for help on using the changeset viewer.