- Timestamp:
- 12/15/18 12:36:08 (6 years ago)
- Location:
- branches/2892_LR-prediction-intervals
- Files:
-
- 27 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2892_LR-prediction-intervals
- Property svn:ignore
-
old new 1 *.docstates 2 *.psess 3 *.resharper 4 *.suo 5 *.user 6 *.vsp 7 Doxygen 8 FxCopResults.txt 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 11 HeuristicLab 3.3.5.1.ReSharper.user 12 HeuristicLab 3.3.6.0.ReSharper.user 13 HeuristicLab.4.5.resharper.user 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 16 HeuristicLab.resharper.user 17 ProtoGen.exe 1 18 TestResults 19 _ReSharper.HeuristicLab 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 22 _ReSharper.HeuristicLab.ExtLibs 23 bin 24 protoc.exe 25 obj 26 .vs
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r15583 r16388 210 210 protected override void Run(CancellationToken cancellationToken) { 211 211 // Set up the algorithm 212 if (SetSeedRandomly) Seed = new System.Random().Next();212 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 213 213 var rand = new MersenneTwister((uint)Seed); 214 214 … … 258 258 259 259 modifiableDataset.RemoveVariable(targetVarName); 260 modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest) );260 modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest).ToList()); 261 261 262 262 SampleTrainingData(rand, modifiableDataset, rRows, problemData.Dataset, curY, problemData.TargetVariable, problemData.TrainingIndices); // all training indices from the original problem data are allowed -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r15583 r16388 186 186 protected override void Run(CancellationToken cancellationToken) { 187 187 // Set up the algorithm 188 if (SetSeedRandomly) Seed = new System.Random().Next();188 if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed(); 189 189 190 190 // Set up the results display -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r15744 r16388 131 131 <SubType>Code</SubType> 132 132 </Compile> 133 <Compile Include="DoubleArrayExtensions.cs" /> 133 134 <Compile Include="FixedDataAnalysisAlgorithm.cs" /> 134 135 <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" /> -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r15583 r16388 80 80 inputMatrix = factorMatrix.HorzCat(inputMatrix); 81 81 82 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))82 if (inputMatrix.ContainsNanOrInfinity()) 83 83 throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset."); 84 84 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r15744 r16388 92 92 int nVarCoeff = doubleVariables.Count(); 93 93 var tree = LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(), 94 doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(), 94 doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(), 95 95 @const: coefficients[nFeatures]); 96 96 97 97 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone()); 98 98 solution.Model.Name = "Linear Regression Model"; … … 147 147 inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix); 148 148 149 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))149 if (inputMatrix.ContainsNanOrInfinity()) 150 150 throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset."); 151 151 } -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs
r15583 r16388 78 78 inputMatrix = factorMatrix.HorzCat(inputMatrix); 79 79 80 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))80 if (inputMatrix.ContainsNanOrInfinity()) 81 81 throw new NotSupportedException("Multinomial logit classification does not support NaN or infinity values in the input dataset."); 82 82 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs
r15583 r16388 65 65 66 66 var ds = ReduceDataset(dataset, rows); 67 nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues );67 nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues: classValues); 68 68 } 69 69 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r15583 r16388 130 130 // automatic determination of weights (all features should have variance = 1) 131 131 this.weights = this.allowedInputVariables 132 .Select(name => 1.0 / dataset.GetDoubleValues(name, rows).StandardDeviationPop()) 132 .Select(name => { 133 var pop = dataset.GetDoubleValues(name, rows).StandardDeviationPop(); 134 return pop.IsAlmost(0) ? 1.0 : 1.0/pop; 135 }) 133 136 .Concat(new double[] { 1.0 }) // no scaling for target variable 134 137 .ToArray(); … … 142 145 } 143 146 144 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))147 if (inputMatrix.ContainsNanOrInfinity()) 145 148 throw new NotSupportedException( 146 149 "Nearest neighbour model does not support NaN or infinity values in the input dataset."); … … 259 262 260 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 a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 280 } 281 261 282 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) { 262 283 return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData)); -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs
r15583 r16388 115 115 public NeuralNetworkClassification() 116 116 : base() { 117 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 118 (IntValue)new IntValue(0).AsReadOnly(), 119 (IntValue)new IntValue(1).AsReadOnly(), 117 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 118 (IntValue)new IntValue(0).AsReadOnly(), 119 (IntValue)new IntValue(1).AsReadOnly(), 120 120 (IntValue)new IntValue(2).AsReadOnly() }); 121 121 var selectedHiddenLayerValue = (from v in validHiddenLayerValues … … 185 185 IEnumerable<int> rows = problemData.TrainingIndices; 186 186 double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows); 187 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))187 if (inputMatrix.ContainsNanOrInfinity()) 188 188 throw new NotSupportedException("Neural network classification does not support NaN or infinity values in the input dataset."); 189 189 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs
r15583 r16388 171 171 IEnumerable<int> rows = problemData.TrainingIndices; 172 172 double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows); 173 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))173 if (inputMatrix.ContainsNanOrInfinity()) 174 174 throw new NotSupportedException("Neural network ensemble classification does not support NaN or infinity values in the input dataset."); 175 175 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
r15739 r16388 36 36 public sealed class NeuralNetworkEnsembleModel : ClassificationModel, INeuralNetworkEnsembleModel { 37 37 38 private object mlpEnsembleLocker = new object(); 38 39 private alglib.mlpensemble mlpEnsemble; 39 public alglib.mlpensemble MultiLayerPerceptronEnsemble {40 get { return mlpEnsemble; }41 set {42 if (value != mlpEnsemble) {43 if (value == null) throw new ArgumentNullException();44 mlpEnsemble = value;45 OnChanged(EventArgs.Empty);46 }47 }48 }49 40 50 41 public override IEnumerable<string> VariablesUsedForPrediction { … … 103 94 } 104 95 // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe 105 lock (mlpEnsemble ) {96 lock (mlpEnsembleLocker) { 106 97 alglib.mlpeprocess(mlpEnsemble, x, ref y); 107 98 } … … 123 114 } 124 115 // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe 125 lock (mlpEnsemble ) {116 lock (mlpEnsembleLocker) { 126 117 alglib.mlpeprocess(mlpEnsemble, x, ref y); 127 118 } … … 139 130 } 140 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 a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 149 } 150 141 151 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 142 152 return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData)); … … 145 155 return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData)); 146 156 } 147 148 #region events 149 public event EventHandler Changed; 150 private void OnChanged(EventArgs e) { 151 var handlers = Changed; 152 if (handlers != null) 153 handlers(this, e); 154 } 155 #endregion 156 157 157 158 #region persistence 158 159 [Storable] -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs
r15583 r16388 125 125 public NeuralNetworkEnsembleRegression() 126 126 : base() { 127 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 128 (IntValue)new IntValue(0).AsReadOnly(), 129 (IntValue)new IntValue(1).AsReadOnly(), 127 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 128 (IntValue)new IntValue(0).AsReadOnly(), 129 (IntValue)new IntValue(1).AsReadOnly(), 130 130 (IntValue)new IntValue(2).AsReadOnly() }); 131 131 var selectedHiddenLayerValue = (from v in validHiddenLayerValues … … 170 170 IEnumerable<int> rows = problemData.TrainingIndices; 171 171 double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows); 172 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))172 if (inputMatrix.ContainsNanOrInfinity()) 173 173 throw new NotSupportedException("Neural network ensemble regression does not support NaN or infinity values in the input dataset."); 174 174 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r15739 r16388 36 36 public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel { 37 37 38 private object mlpLocker = new object(); 38 39 private alglib.multilayerperceptron multiLayerPerceptron; 39 public alglib.multilayerperceptron MultiLayerPerceptron {40 get { return multiLayerPerceptron; }41 set {42 if (value != multiLayerPerceptron) {43 if (value == null) throw new ArgumentNullException();44 multiLayerPerceptron = value;45 OnChanged(EventArgs.Empty);46 }47 }48 }49 40 50 41 public override IEnumerable<string> VariablesUsedForPrediction { … … 107 98 } 108 99 // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save! 109 lock (m ultiLayerPerceptron) {100 lock (mlpLocker) { 110 101 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 111 102 } … … 127 118 } 128 119 // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save! 129 lock (m ultiLayerPerceptron) {120 lock (mlpLocker) { 130 121 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 131 122 } … … 143 134 } 144 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 a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData"); 152 } 153 145 154 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 146 155 return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData)); … … 149 158 return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData)); 150 159 } 151 152 #region events153 public event EventHandler Changed;154 private void OnChanged(EventArgs e) {155 var handlers = Changed;156 if (handlers != null)157 handlers(this, e);158 }159 #endregion160 160 161 161 #region persistence -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs
r15583 r16388 115 115 public NeuralNetworkRegression() 116 116 : base() { 117 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 118 (IntValue)new IntValue(0).AsReadOnly(), 119 (IntValue)new IntValue(1).AsReadOnly(), 117 var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 118 (IntValue)new IntValue(0).AsReadOnly(), 119 (IntValue)new IntValue(1).AsReadOnly(), 120 120 (IntValue)new IntValue(2).AsReadOnly() }); 121 121 var selectedHiddenLayerValue = (from v in validHiddenLayerValues … … 186 186 IEnumerable<int> rows = problemData.TrainingIndices; 187 187 double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows); 188 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))188 if (inputMatrix.ContainsNanOrInfinity()) 189 189 throw new NotSupportedException("Neural network regression does not support NaN or infinity values in the input dataset."); 190 190 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r15583 r16388 186 186 qualityTable.Rows.Add(testRMSERow); 187 187 Results.Add(new Result(qualityTable.Name, qualityTable.Name + " for all restarts", qualityTable)); 188 if (SetSeedRandomly) Seed = (new System.Random()).Next();188 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 189 189 var rand = new MersenneTwister((uint)Seed); 190 190 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling, rand); -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
r15583 r16388 135 135 protected override void Run(CancellationToken cancellationToken) { 136 136 double rmsError, relClassificationError, outOfBagRmsError, outOfBagRelClassificationError; 137 if (SetSeedRandomly) Seed = new System.Random().Next();137 if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed(); 138 138 139 139 var model = CreateRandomForestClassificationModel(Problem.ProblemData, NumberOfTrees, R, M, Seed, out rmsError, out relClassificationError, out outOfBagRmsError, out outOfBagRelClassificationError); -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs
r15583 r16388 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 a regression nor a classification problem data. 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) { … … 310 328 public static RandomForestModel CreateClassificationModel(IClassificationProblemData problemData, int nTrees, double r, double m, int seed, 311 329 out double rmsError, out double outOfBagRmsError, out double relClassificationError, out double outOfBagRelClassificationError) { 312 return CreateClassificationModel(problemData, problemData.TrainingIndices, nTrees, r, m, seed, 330 return CreateClassificationModel(problemData, problemData.TrainingIndices, nTrees, r, m, seed, 313 331 out rmsError, out outOfBagRmsError, out relClassificationError, out outOfBagRelClassificationError); 314 332 } … … 370 388 371 389 private static void AssertInputMatrix(double[,] inputMatrix) { 372 if (inputMatrix.C ast<double>().Any(x => Double.IsNaN(x) || Double.IsInfinity(x)))390 if (inputMatrix.ContainsNanOrInfinity()) 373 391 throw new NotSupportedException("Random forest modeling does not support NaN or infinity values in the input dataset."); 374 392 } -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
r15583 r16388 134 134 protected override void Run(CancellationToken cancellationToken) { 135 135 double rmsError, avgRelError, outOfBagRmsError, outOfBagAvgRelError; 136 if (SetSeedRandomly) Seed = new System.Random().Next();136 if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed(); 137 137 var model = CreateRandomForestRegressionModel(Problem.ProblemData, NumberOfTrees, R, M, Seed, 138 138 out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError); -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r15583 r16388 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 a regression nor a classification problem data. 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 157 svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, TargetVariable,allowedInputVariables, rows);176 svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, allowedInputVariables, rows); 158 177 svm_problem scaledProblem = rangeTransform.Scale(problem); 159 178 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs
r15583 r16388 35 35 public class SupportVectorMachineUtil { 36 36 /// <summary> 37 /// Transforms <paramref name="problemData"/> into a data structure as needed by libSVM. 38 /// </summary> 39 /// <param name="problemData">The problem data to transform</param> 37 /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM. 38 /// </summary> 39 /// <param name="dataset">The source dataset</param> 40 /// <param name="targetVariable">The target variable</param> 41 /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param> 40 42 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 41 43 /// <returns>A problem data type that can be used to train a support vector machine.</returns> 42 44 public static svm_problem CreateSvmProblem(IDataset dataset, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) { 43 double[] targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray(); 44 svm_node[][] nodes = new svm_node[targetVector.Length][]; 45 double[] targetVector ; 46 var nRows = rowIndices.Count(); 47 if (string.IsNullOrEmpty(targetVariable)) { 48 // if the target variable is not set (e.g. for prediction of a trained model) we just use a zero vector 49 targetVector = new double[nRows]; 50 } else { 51 targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray(); 52 } 53 svm_node[][] nodes = new svm_node[nRows][]; 45 54 int maxNodeIndex = 0; 46 55 int svmProblemRowIndex = 0; … … 66 75 67 76 /// <summary> 77 /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM for prediction. 78 /// </summary> 79 /// <param name="dataset">The problem data to transform</param> 80 /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param> 81 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 82 /// <returns>A problem data type that can be used for prediction with a trained support vector machine.</returns> 83 public static svm_problem CreateSvmProblem(IDataset dataset, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) { 84 // for prediction we don't need a target variable 85 return CreateSvmProblem(dataset, string.Empty, inputVariables, rowIndices); 86 } 87 88 /// <summary> 68 89 /// Instantiate and return a svm_parameter object with default values. 69 90 /// </summary> -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs
r15583 r16388 275 275 if (wdist != null) wdist.Initialize(problemData); 276 276 if (state == null) { 277 if (SetSeedRandomly) Seed = new System.Random().Next();277 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 278 278 var random = new MersenneTwister((uint)Seed); 279 279 var dataset = problemData.Dataset; -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs
r15583 r16388 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;29 28 using HeuristicLab.Optimization; 30 29 using HeuristicLab.Parameters; … … 97 96 inputMatrix[i, timeOffset] = targetValues[i + problemData.TrainingPartition.Start]; 98 97 99 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))98 if (inputMatrix.ContainsNanOrInfinity()) 100 99 throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset."); 101 100 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs
r15583 r16388 91 91 int[] xyc; 92 92 double[,] inputMatrix = dataset.ToArray(allowedInputVariables, rows); 93 if (inputMatrix.C ast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))93 if (inputMatrix.ContainsNanOrInfinity()) 94 94 throw new NotSupportedException("k-Means clustering does not support NaN or infinity values in the input dataset."); 95 95 -
branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs
r15583 r16388 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) {
Note: See TracChangeset
for help on using the changeset viewer.