Changeset 16538 for branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
- Timestamp:
- 01/18/19 14:39:01 (5 years ago)
- Location:
- branches/2847_M5Regression
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs
r14843 r16538 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 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 { … … 102 93 x[column] = inputData[row, column]; 103 94 } 104 alglib.mlpeprocess(mlpEnsemble, x, ref y); 95 // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe 96 lock (mlpEnsembleLocker) { 97 alglib.mlpeprocess(mlpEnsemble, x, ref y); 98 } 105 99 yield return y[0]; 106 100 } … … 119 113 x[column] = inputData[row, column]; 120 114 } 121 alglib.mlpeprocess(mlpEnsemble, x, ref y); 115 // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe 116 lock (mlpEnsembleLocker) { 117 alglib.mlpeprocess(mlpEnsemble, x, ref y); 118 } 122 119 // find class for with the largest probability value 123 120 int maxProbClassIndex = 0; … … 133 130 } 134 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 135 151 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 136 152 return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData)); … … 139 155 return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData)); 140 156 } 141 142 #region events 143 public event EventHandler Changed; 144 private void OnChanged(EventArgs e) { 145 var handlers = Changed; 146 if (handlers != null) 147 handlers(this, e); 148 } 149 #endregion 150 157 151 158 #region persistence 152 159 [Storable]
Note: See TracChangeset
for help on using the changeset viewer.