code: def robust_cca_similarity(
      acts1, acts2, threshold=0.98, epsilon=1e-6, compute_dirns=True
  ):
      """Calls get_cca_similarity multiple times while adding noise.
  
      This function is very similar to get_cca_similarity, and can be used if
      get_cca_similarity doesn't converge for some pair of inputs. This function
      adds some noise to the activations to help convergence.
  
      Args:
                acts1: (num_neurons1, data_points) a 2d numpy array of neurons by
                       datapoints where entry (i,j) is the output of neuron i on
                       datapoint j.
                acts2: (num_neurons2, data_points) same as above, but (potentially)
                       for a different set of neurons. Note that acts1 and acts2
                       can have different numbers of neurons, but must agree on the
                       number of datapoints
  
                threshold: float between 0, 1 used to get rid of trailing zeros in
                           the cca correlation coefficients to output more accurate
                           summary statistics of correlations.
  
                epsilon: small float to help stabilize computations
  
                compute_dirns: boolean value determining whether actual cca
                               directions are computed. (For very large neurons and
                               datasets, may be better to compute these on the fly
                               instead of store in memory.)
  
      Returns:
                return_dict: A dictionary with outputs from the cca computations.
                             Contains neuron coefficients (combinations of neurons
                             that correspond to cca directions), the cca correlation
                             coefficients (how well aligned directions correlate),
                             x and y idxs (for computing cca directions on the fly
                             if compute_dirns=False), and summary statistics. If
                             compute_dirns=True, the cca directions are also
                             computed.
      """
  
      for trial in range(num_cca_trials):
          try:
              return_dict = get_cca_similarity(
                  acts1, acts2, threshold, compute_dirns
              )
          except np.LinAlgError:
              acts1 = (
                  acts1 * 1e-1
                  + np.random.normal(size=acts1.shape) * epsilon
              )
              acts2 = (
                  acts2 * 1e-1
                  + np.random.normal(size=acts1.shape) * epsilon
              )
              if trial + 1 == num_cca_trials:
                  raise
  
      return return_dict
  
file_path: ecco/src/ecco/svcca_lib/cca_core.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
label_desc: Use image node_id 7 for calling a global function with example usage: robust_cca_similarity(acts1, acts2, threshold, epsilon, compute_dirns) and returns: return_dict