code: def compute_average_posterior(
      dir,
      iter,
      egs_dir,
      num_archives,
      prior_subset_size,
      run_opts,
      get_raw_nnet_from_am=True,
  ):
      """Computes the average posterior of the network"""
      for file in glob.glob("{0}/post.{1}.*.vec".format(dir, iter)):
          os.remove(file)
  
      if run_opts.num_jobs_compute_prior > num_archives:
          egs_part = 1
      else:
          egs_part = "JOB"
  
      suffix = "mdl" if get_raw_nnet_from_am else "raw"
      model = "{0}/{1}.{2}".format(dir, iter, suffix)
  
      common_lib.execute_command(
          """{command} JOB=1:{num_jobs_compute_prior} {prior_queue_opt} \
                  {dir}/log/get_post.{iter}.JOB.log \
                  nnet3-copy-egs \
                  ark:{egs_dir}/egs.{egs_part}.ark ark:- \| \
                  nnet3-subset-egs --srand=JOB --n={prior_subset_size} \
                  ark:- ark:- \| \
                  nnet3-merge-egs --minibatch-size=128 ark:- ark:- \| \
                  nnet3-compute-from-egs {prior_gpu_opt} --apply-exp=true \
                  "{model}" ark:- ark:- \| \
                  matrix-sum-rows ark:- ark:- \| vector-sum ark:- \
                  {dir}/post.{iter}.JOB.vec""".format(
              command=run_opts.command,
              dir=dir,
              model=model,
              num_jobs_compute_prior=run_opts.num_jobs_compute_prior,
              prior_queue_opt=run_opts.prior_queue_opt,
              iter=iter,
              prior_subset_size=prior_subset_size,
              egs_dir=egs_dir,
              egs_part=egs_part,
              prior_gpu_opt=run_opts.prior_gpu_opt,
          )
      )
  
      # make sure there is time for $dir/post.{iter}.*.vec to appear.
      time.sleep(5)
      avg_post_vec_file = "{dir}/post.{iter}.vec".format(
          dir=dir, iter=iter
      )
      common_lib.execute_command(
          """{command} {dir}/log/vector_sum.{iter}.log \
                  vector-sum {dir}/post.{iter}.*.vec {output_file}
          """.format(
              command=run_opts.command,
              dir=dir,
              iter=iter,
              output_file=avg_post_vec_file,
          )
      )
  
      for file in glob.glob("{0}/post.{1}.*.vec".format(dir, iter)):
          os.remove(file)
      return avg_post_vec_file
  
imports: from __future__ import print_function
  from __future__ import division
  import glob
  import logging
  import math
  import os
  import random
  import time
  import libs.common
  import libs.nnet3.train.common
label_desc: Use image node_id 11 for calling a global function with example usage: compute_average_posterior(dir, iter, egs_dir, num_archives, prior_subset_size, run_opts, get_raw_nnet_from_am) and returns: avg_post_vec_file