- Timestamp:
- 12/15/18 12:07:16 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r15769 r16386 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 -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r15583 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r15786 r16386 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(); … … 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
r15739 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r15739 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r15583 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
r15583 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs
r15786 r16386 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) { -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
r15583 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r15854 r16386 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 -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs
r15583 r16386 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/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs
r15583 r16386 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.