Changeset 16311 for branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
- Timestamp:
- 11/20/18 15:26:57 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /stable/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Algorithms.DataAnalysis/3.4 10321-10322 /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 6917-7005 /branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4 9070-13099 /branches/CloningRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.4 5815-6180 /branches/DataAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Algorithms.DataAnalysis/3.4 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Algorithms.DataAnalysis/3.4 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Algorithms.DataAnalysis/3.4 5060 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 11570-12508 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Algorithms.DataAnalysis/3.4 11130-12721 /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis/3.4 13819-14091 /branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4 8116-8789 /branches/LogResidualEvaluator/HeuristicLab.Algorithms.DataAnalysis/3.4 10202-10483 /branches/NET40/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 5138-5162 /branches/ParallelEngine/HeuristicLab.Algorithms.DataAnalysis/3.4 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Algorithms.DataAnalysis/3.4 7773-7810 /branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Algorithms.DataAnalysis/3.4 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Algorithms.DataAnalysis/3.4 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 5370-5682 /branches/Trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 6829-6865 /branches/VNS/HeuristicLab.Algorithms.DataAnalysis/3.4 5594-5752 /branches/Weighted TSNE/3.4 15451-15531 /branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4 14232-14825 /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 15406-15681
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r16308 r16311 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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 { … … 106 97 x[column] = inputData[row, column]; 107 98 } 108 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 99 // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save! 100 lock (mlpLocker) { 101 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 102 } 109 103 yield return y[0]; 110 104 } … … 112 106 113 107 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 114 double[,] inputData = dataset.ToArray( 108 double[,] inputData = dataset.ToArray(allowedInputVariables, rows); 115 109 116 110 int n = inputData.GetLength(0); … … 123 117 x[column] = inputData[row, column]; 124 118 } 125 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 119 // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save! 120 lock (mlpLocker) { 121 alglib.mlpprocess(multiLayerPerceptron, x, ref y); 122 } 126 123 // find class for with the largest probability value 127 124 int maxProbClassIndex = 0; … … 137 134 } 138 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 139 154 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 140 155 return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData)); … … 143 158 return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData)); 144 159 } 145 146 #region events147 public event EventHandler Changed;148 private void OnChanged(EventArgs e) {149 var handlers = Changed;150 if (handlers != null)151 handlers(this, e);152 }153 #endregion154 160 155 161 #region persistence
Note: See TracChangeset
for help on using the changeset viewer.