code: public void writeInferredDistributions(InstanceList instances, 
                                             File distributionsFile,
                                             int numIterations, int thinning, int burnIn,
                                             double threshold, int max) throws IOException {
  
          PrintWriter out = new PrintWriter(distributionsFile);
          
          out.print ("#doc source topic proportion ...\n");
  
          IDSorter[] sortedTopics = new IDSorter[ numTopics ];
          for (int topic = 0; topic < numTopics; topic++) {
              // Initialize the sorters with dummy values
              sortedTopics[topic] = new IDSorter(topic, topic);
          }
  
          if (max < 0 || max > numTopics) {
              max = numTopics;
          }
  
          int doc = 0;
  
          for (Instance instance: instances) {
              
              double[] topicDistribution =
                  getSampledDistribution(instance, numIterations,
                                         thinning, burnIn);
              out.print (doc); out.print (' ');
  
              // Print the Source field of the instance
              if (instance.getSource() != null) {
                  out.print (instance.getSource());
              }
              else {
                  out.print ("null-source");
              }
              out.print (' ');
  
              for (int topic = 0; topic < numTopics; topic++) {
                  sortedTopics[topic].set(topic, topicDistribution[topic]);
              }
              Arrays.sort(sortedTopics);
  
              for (int i = 0; i < max; i++) {
                  if (sortedTopics[i].getWeight() < threshold) { break; }
  
                  out.print (sortedTopics[i].getID() + " " +
                             sortedTopics[i].getWeight() + " ");
              }
              out.print (" \n");
              doc++;
          }
  
          out.close();
      }
docs: Infer topics for the provided instances and
  write distributions to the provided file.
  
  @param instances
  @param distributionsFile
  @param numIterations The total number of iterations of sampling per document
  @param thinning      The number of iterations between saved samples
  @param burnIn        The number of iterations before the first saved sample
  @param threshold     The minimum proportion of a given topic that will be written
  @param max           The total number of topics to report per document]