Fix and optimize how progress is displayed while training trees
This commit is contained in:
parent
ea176cff9a
commit
50b4a3cd89
1 changed files with 31 additions and 14 deletions
|
@ -71,20 +71,19 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
final Random random = new Random();
|
||||
|
||||
for(int j=0; j<ntree; j++){
|
||||
if(displayProgress){
|
||||
System.out.print("\rFinished tree " + j + "/" + ntree + " trees");
|
||||
}
|
||||
|
||||
trees.add(trainTree(bootstrapper, random));
|
||||
}
|
||||
|
||||
if(displayProgress){
|
||||
if(j==0) {
|
||||
System.out.println();
|
||||
}
|
||||
System.out.print("\rFinished tree " + (j+1) + "/" + ntree);
|
||||
if(j==ntree-1){
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
System.out.println("\rFinished tree " + ntree + "/" + ntree + " trees");
|
||||
System.out.println("Finished");
|
||||
}
|
||||
|
||||
|
||||
return Forest.<TO, FO>builder()
|
||||
.treeResponseCombiner(treeResponseCombiner)
|
||||
.trees(trees)
|
||||
|
@ -117,7 +116,8 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
}
|
||||
|
||||
if(displayProgress){
|
||||
System.out.println("\nFinished");
|
||||
System.out.println("\rFinished tree " + ntree + "/" + ntree + " trees");
|
||||
System.out.println("Finished");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,10 +136,12 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
}
|
||||
|
||||
executorService.shutdown();
|
||||
|
||||
int prevNumberTreesSet = -1;
|
||||
while(!executorService.isTerminated()){
|
||||
|
||||
try{
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// do nothing; who cares?
|
||||
}
|
||||
|
@ -152,7 +154,13 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
}
|
||||
}
|
||||
|
||||
// Only output trees set on screen if there was a change
|
||||
// In some environments where standard output is streamed to a file this method below causes frequent writes to output
|
||||
if(numberTreesSet != prevNumberTreesSet){
|
||||
System.out.print("\rFinished " + numberTreesSet + "/" + ntree + " trees");
|
||||
prevNumberTreesSet = numberTreesSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -188,6 +196,8 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
}
|
||||
|
||||
executorService.shutdown();
|
||||
|
||||
int prevNumberTreesSet = -1;
|
||||
while(!executorService.isTerminated()){
|
||||
|
||||
try{
|
||||
|
@ -197,8 +207,15 @@ public class ForestTrainer<Y, TO, FO> {
|
|||
}
|
||||
|
||||
if(displayProgress) {
|
||||
int numberTreesSet = treeCount.get();
|
||||
|
||||
// Only output trees set on screen if there was a change
|
||||
// In some environments where standard output is streamed to a file this method below causes frequent writes to output
|
||||
if(numberTreesSet != prevNumberTreesSet){
|
||||
System.out.print("\rFinished " + numberTreesSet + "/" + ntree + " trees");
|
||||
prevNumberTreesSet = numberTreesSet;
|
||||
}
|
||||
|
||||
System.out.print("\rFinished " + treeCount.get() + "/" + ntree + " trees");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue