Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/14 11:53:07 (10 years ago)
Author:
bburlacu
Message:

#2237: Fixed thread synchronisation bug. Removed unused variables in GridSearch methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestUtil.cs

    r11362 r11426  
    4343
    4444  public static class RandomForestUtil {
     45    private static readonly object locker = new object();
     46
    4547    private static void CrossValidate(IRegressionProblemData problemData, Tuple<IEnumerable<int>, IEnumerable<int>>[] partitions, int nTrees, double r, double m, int seed, out double avgTestMse) {
    4648      avgTestMse = 0;
     
    9193      Parallel.ForEach(crossProduct, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, parameterCombination => {
    9294        var parameterValues = parameterCombination.ToList();
    93         double testMSE;
    9495        var parameters = new RFParameter();
    9596        for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); }
    9697        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) {
    101102            bestOutOfBagRmsError = outOfBagRmsError;
    102103            bestParameters = (RFParameter)parameters.Clone();
     
    119120        for (int i = 0; i < setters.Count; ++i) { setters[i](parameters, parameterValues[i]); }
    120121        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,
    122123                                                                out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
    123         if (bestOutOfBagRmsError > outOfBagRmsError) {
    124           lock (bestParameters) {
     124
     125        lock (locker) {
     126          if (bestOutOfBagRmsError > outOfBagRmsError) {
    125127            bestOutOfBagRmsError = outOfBagRmsError;
    126128            bestParameters = (RFParameter)parameters.Clone();
     
    147149        }
    148150        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) {
    151154            mse.Value = testMSE;
    152155            bestParameter = (RFParameter)parameters.Clone();
     
    173176        }
    174177        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) {
    177181            accuracy.Value = testAccuracy;
    178182            bestParameter = (RFParameter)parameters.Clone();
Note: See TracChangeset for help on using the changeset viewer.