code: def test_ewma(alpha, NS=10000, D=1):
      ewma_log = EwmaLog(alpha=alpha)
      sigma = torch.tensor(1.0, requires_grad=True)
  
      for k in range(1000):
          exponent = torch.randn(NS, D) * sigma
          s, _ = torch.max(exponent, dim=0)
          log_eT = s + ewma_log((exponent - s).exp().mean(dim=0), s)
          log_eT.backward()
          sigma_grad = sigma.grad.clone().cpu().numpy()
          sigma.grad.zero_()
          if k % 100 == 0:
              error = math.fabs(sigma_grad - 1.0)
              assert error < 0.07
  
file_path: pyro/tests/contrib/oed/test_ewma.py
imports: import math
  import pytest
  import torch
  from pyro.contrib.oed.eig import EwmaLog
  from tests.common import assert_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_ewma(alpha, NS, D) without return types