class_docstr: AutoCorrelation Mechanism with the following two phases:
  (1) period-based dependencies discovery
  (2) time delay aggregation
  This block can replace the self-attention family mechanism seamlessly.
class_docstr_tok: ["AutoCorrelation","Mechanism","with","the","following","two","phases",":","(","1",")","period-based","dependencies","discovery","(","2",")","time","delay","aggregation","This","block","can","replace","the","self-attention","family","mechanism","seamlessly","."]
docstr: SpeedUp version of Autocorrelation (a batch-normalization style design)
  This is for the inference phase.
docstr_tok: ["SpeedUp","version","of","Autocorrelation","(","a","batch-normalization","style","design",")","This","is","for","the","inference","phase","."]
code: def time_delay_agg_inference(self, values, corr):
      """
      SpeedUp version of Autocorrelation (a batch-normalization style design)
      This is for the inference phase.
      """
      batch = values.shape[0]
      head = values.shape[1]
      channel = values.shape[2]
      length = values.shape[3]
      # index init
      init_index = (
          torch.arange(length)
          .unsqueeze(0)
          .unsqueeze(0)
          .unsqueeze(0)
          .repeat(batch, head, channel, 1)
          .to(values.device)
      )
      # find top k
      top_k = int(self.factor * math.log(length))
      mean_value = torch.mean(torch.mean(corr, dim=1), dim=1)
      weights, delay = torch.topk(mean_value, top_k, dim=-1)
      # update corr
      tmp_corr = torch.softmax(weights, dim=-1)
      # aggregation
      tmp_values = values.repeat(1, 1, 1, 2)
      delays_agg = torch.zeros_like(values).float()
      for i in range(top_k):
          tmp_delay = init_index + delay[:, i].unsqueeze(1).unsqueeze(
              1
          ).unsqueeze(1).repeat(1, head, channel, length)
          pattern = torch.gather(tmp_values, dim=-1, index=tmp_delay)
          delays_agg = delays_agg + pattern * (
              tmp_corr[:, i]
              .unsqueeze(1)
              .unsqueeze(1)
              .unsqueeze(1)
              .repeat(1, head, channel, length)
          )
      return delays_agg
  
imports: import os
  import math
  import numpy
  from math import sqrt
  from scipy.fftpack import next_fast_len
label_desc: Use image node_id 3 for calling the AutoCorrelation obj's underlying member method code with example usage: obj.time_delay_agg_inference(values, corr) and returns: delays_agg