Changeset 16386 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork
- Timestamp:
- 12/15/18 12:07:16 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 5 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/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
Note: See TracChangeset
for help on using the changeset viewer.