1. yanchuan sim
  2. ark-sage

Commits

yanchuan sim  committed 8fb5326

repeatedly open/close likelihood file to avoid stale file handles.

  • Participants
  • Parent commits efd8363
  • Branches master

Comments (0)

Files changed (1)

File src/edu/cmu/cs/ark/sage/apps/SupervisedSAGE.java

View file
  • Ignore whitespace
       System.out.println();
     }
 
-    // create the log likelihood file
-    BufferedWriter bw_ll = null;
-    if (result.getFile("save-ll") != null)
-      bw_ll = new BufferedWriter(new FileWriter(result.getFile("save-ll"), true));
-
     System.out.format("Will optimize for %s iterations...\n", result.contains("iterations") ? result.getInt("iterations") : "inifinite");
 
     double best_ll = -Double.MAX_VALUE;
       ll_prev = ll;
 
       // write out log likelihood
-      if (bw_ll != null)
+      if (result.getFile("save-ll") != null)
       {
+        BufferedWriter bw_ll = new BufferedWriter(new FileWriter(result.getFile("save-ll"), true));
         bw_ll.write(String.format("%d\t%f\n", iter, ll));
         bw_ll.flush();
+        bw_ll.close();
       }
 
       System.out.format(" done! (took %.2f seconds)\n  log-likelihood=%.2f (delta=%.3f%%, best so far=%.2f)", (System.nanoTime() - start_time) * 1e-9, ll, ll_delta * 100.0, best_ll);
       System.out.println();
       System.out.println();
     }
-
-    if (bw_ll != null)
-      bw_ll.close();
   }
 
   /**