code: def compute_preconditioning_matrix(
      dir,
      egs_dir,
      num_lda_jobs,
      run_opts,
      max_lda_jobs=None,
      rand_prune=4.0,
      lda_opts=None,
      use_multitask_egs=False,
  ):
      """Function to estimate and write LDA matrix from cegs
  
      This function is exactly similar to the version in module
      libs.nnet3.train.frame_level_objf.common except this uses cegs instead of
      egs files.
      """
      if max_lda_jobs is not None:
          if num_lda_jobs > max_lda_jobs:
              num_lda_jobs = max_lda_jobs
      multitask_egs_opts = common_train_lib.get_multitask_egs_opts(
          egs_dir,
          egs_prefix="cegs.",
          archive_index="JOB",
          use_multitask_egs=use_multitask_egs,
      )
      scp_or_ark = "scp" if use_multitask_egs else "ark"
      egs_rspecifier = (
          "ark:nnet3-chain-copy-egs {multitask_egs_opts} "
          "{scp_or_ark}:{egs_dir}/cegs.JOB.{scp_or_ark} ark:- |"
          "".format(
              egs_dir=egs_dir,
              scp_or_ark=scp_or_ark,
              multitask_egs_opts=multitask_egs_opts,
          )
      )
  
      # Write stats with the same format as stats for LDA.
      common_lib.execute_command(
          """{command} JOB=1:{num_lda_jobs} {dir}/log/get_lda_stats.JOB.log \
                  nnet3-chain-acc-lda-stats --rand-prune={rand_prune} \
                  {dir}/init.raw "{egs_rspecifier}" \
                  {dir}/JOB.lda_stats""".format(
              command=run_opts.command,
              num_lda_jobs=num_lda_jobs,
              dir=dir,
              egs_rspecifier=egs_rspecifier,
              rand_prune=rand_prune,
          )
      )
  
      # the above command would have generated dir/{1..num_lda_jobs}.lda_stats
      lda_stat_files = [
          "{0}/{1}.lda_stats".format(dir, x)
          for x in range(1, num_lda_jobs + 1)
      ]
  
      common_lib.execute_command(
          """{command} {dir}/log/sum_transform_stats.log \
                  sum-lda-accs {dir}/lda_stats {lda_stat_files}""".format(
              command=run_opts.command,
              dir=dir,
              lda_stat_files=" ".join(lda_stat_files),
          )
      )
  
      for file in lda_stat_files:
          try:
              os.remove(file)
          except OSError:
              raise Exception(
                  "There was error while trying to remove "
                  "lda stat files."
              )
      # this computes a fixed affine transform computed in the way we described
      # in Appendix C.6 of http://arxiv.org/pdf/1410.7455v6.pdf; it's a scaled
      # variant of an LDA transform but without dimensionality reduction.
  
      common_lib.execute_command(
          """{command} {dir}/log/get_transform.log \
                  nnet-get-feature-transform {lda_opts} {dir}/lda.mat \
                  {dir}/lda_stats""".format(
              command=run_opts.command,
              dir=dir,
              lda_opts=lda_opts if lda_opts is not None else "",
          )
      )
  
      common_lib.force_symlink(
          "../lda.mat", "{0}/configs/lda.mat".format(dir)
      )
  
file_path: espnet/egs2/portmedia_lang/asr1/steps/libs/nnet3/train/chain_objf/acoustic_model.py
imports: from __future__ import division
  from __future__ import print_function
  import logging
  import math
  import os
  import sys
  import libs.common
  import libs.nnet3.train.common
label_desc: Use image node_id 7 for calling a global function with example usage: compute_preconditioning_matrix(dir, egs_dir, num_lda_jobs, run_opts, max_lda_jobs, rand_prune, lda_opts, use_multitask_egs) without return types