From 4aac73b868c56da4f7bab1a2ed670d9d7a043e31 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Wed, 29 May 2019 15:05:48 -0700 Subject: [PATCH] Improve progress tracking to terminate when all trees are trained Instead of only checking every second --- .../randomforest/tree/ForestTrainer.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/ca/joeltherrien/randomforest/tree/ForestTrainer.java b/src/main/java/ca/joeltherrien/randomforest/tree/ForestTrainer.java index 76e91ea..04c53e5 100644 --- a/src/main/java/ca/joeltherrien/randomforest/tree/ForestTrainer.java +++ b/src/main/java/ca/joeltherrien/randomforest/tree/ForestTrainer.java @@ -153,15 +153,15 @@ public class ForestTrainer { executorService.execute(worker); } + executorService.shutdown(); + int prevNumberTreesSet = -1; - while(true){ + boolean running = true; + while(running){ try { - if (executorService.awaitTermination(1, TimeUnit.SECONDS)) break; + if (executorService.awaitTermination(1, TimeUnit.SECONDS)) running = false; } catch (InterruptedException e) { - System.err.println("There was an InterruptedException while waiting for the forest to finish training; this is unusual but on its own shouldn't be a problem."); - System.err.println("Please send a bug report about it to joelt@sfu.ca"); - e.printStackTrace(); - // do nothing; this shouldn't be an issue + // do nothing and just continue; this won't happen and if it did we'd just update the counter quicker } int numberTreesSet = 0; @@ -178,10 +178,6 @@ public class ForestTrainer { prevNumberTreesSet = numberTreesSet; } - if(numberTreesSet == ntree){ - executorService.shutdown(); - } - } if(displayProgress){ @@ -224,15 +220,15 @@ public class ForestTrainer { executorService.execute(worker); } + executorService.shutdown(); + int prevNumberTreesSet = -1; - while(true){ + boolean running = true; + while(running){ try { - if (executorService.awaitTermination(1, TimeUnit.SECONDS)) break; + if (executorService.awaitTermination(1, TimeUnit.SECONDS)) running = false; } catch (InterruptedException e) { - System.err.println("There was an InterruptedException while waiting for the forest to finish training; this is unusual but on its own shouldn't be a problem."); - System.err.println("Please send a bug report about it to joelt@sfu.ca"); - e.printStackTrace(); - // do nothing; this shouldn't be an issue + // do nothing and just continue; this won't happen and if it did we'd just update the counter quicker } int numberTreesSet = treeCount.get(); @@ -244,10 +240,6 @@ public class ForestTrainer { } - if(numberTreesSet == ntree){ - executorService.shutdown(); - } - } if(displayProgress){