public void print(InstanceList docs, double limit, int num, String file) {

    assert docs.size() == D;

    try {

      PrintWriter pw = new PrintWriter(file, "UTF-8");

      pw.println("#doc source topic proportion ...");

      Probability[] probs = new Probability[T];

      for (int d=0; d<D; d++) {

        pw.print(d); pw.print(" ");
        pw.print(docs.get(d).getSource()); pw.print(" ");

        for (int j=0; j<T; j++)
          probs[j] = new Probability(j, getScore(j, d));

        Arrays.sort(probs);

        if ((num > T) || (num < 0))
          num = T;

        for (int i=0; i<num; i++) {

          // break if there are no more topics whose proportion is
          // greater than zero or limit...

          if ((probs[i].prob == 0) || (probs[i].prob < limit))
            break;

          pw.print(probs[i].index); pw.print(" ");
          pw.print(probs[i].prob); pw.print(" ");
        }

        pw.println();
      }

      pw.close();
    }
    catch (IOException e) {
      System.out.println(e);
    }
  }