Changeset 11426 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 10/08/14 11:53:07 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestUtil.cs
r11362 r11426 43 43 44 44 public static class RandomForestUtil { 45 private static readonly object locker = new object(); 46 45 47 private static void CrossValidate(IRegressionProblemData problemData, Tuple<IEnumerable<int>, IEnumerable<int>>[] partitions, int nTrees, double r, double m, int seed, out double avgTestMse) { 46 48 avgTestMse = 0; … … 91 93 Parallel.ForEach(crossProduct, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, parameterCombination => { 92 94 var parameterValues = parameterCombination.ToList(); 93 double testMSE;94 95 var parameters = new RFParameter(); 95 96 for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); } 96 97 double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError; 97 var model = RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, (int)parameters.n, parameters.r, parameters.m, seed,98 out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError); 99 if (bestOutOfBagRmsError > outOfBagRmsError) {100 lock (bestParameters) {98 RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, (int)parameters.n, parameters.r, parameters.m, seed, out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError); 99 100 lock (locker) { 101 if (bestOutOfBagRmsError > outOfBagRmsError) { 101 102 bestOutOfBagRmsError = outOfBagRmsError; 102 103 bestParameters = (RFParameter)parameters.Clone(); … … 119 120 for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); } 120 121 double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError; 121 var model =RandomForestModel.CreateClassificationModel(problemData, problemData.TrainingIndices, (int)parameters.n, parameters.r, parameters.m, seed,122 RandomForestModel.CreateClassificationModel(problemData, problemData.TrainingIndices, (int)parameters.n, parameters.r, parameters.m, seed, 122 123 out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError); 123 if (bestOutOfBagRmsError > outOfBagRmsError) { 124 lock (bestParameters) { 124 125 lock (locker) { 126 if (bestOutOfBagRmsError > outOfBagRmsError) { 125 127 bestOutOfBagRmsError = outOfBagRmsError; 126 128 bestParameters = (RFParameter)parameters.Clone(); … … 147 149 } 148 150 CrossValidate(problemData, partitions, (int)parameters.n, parameters.r, parameters.m, seed, out testMSE); 149 if (testMSE < mse.Value) { 150 lock (mse) { 151 152 lock (locker) { 153 if (testMSE < mse.Value) { 151 154 mse.Value = testMSE; 152 155 bestParameter = (RFParameter)parameters.Clone(); … … 173 176 } 174 177 CrossValidate(problemData, partitions, (int)parameters.n, parameters.r, parameters.m, seed, out testAccuracy); 175 if (testAccuracy > accuracy.Value) { 176 lock (accuracy) { 178 179 lock (locker) { 180 if (testAccuracy > accuracy.Value) { 177 181 accuracy.Value = testAccuracy; 178 182 bestParameter = (RFParameter)parameters.Clone();
Note: See TracChangeset
for help on using the changeset viewer.