code: def test_ars_optimizer(self):
      dim = 10
      n_generations = 30
      X = torch.Tensor([[i] for i in range(dim)])
      y = torch.ones(dim)
      n_pert = 100
      feature_dim = 2
      np.random.seed(seed=123456)
      ars_opt = ARSOptimizer(feature_dim, n_pert, rand_ars_params=True)
      for i in range(n_generations):
          perturbed_params = ars_opt.sample_perturbed_params()
          rewards = []
          for idx in range(0, len(perturbed_params)):
              pos_param, neg_param = perturbed_params[idx]
              pos_weight = torch.sigmoid(
                  torch.matmul(torch.column_stack((X, y)), pos_param)
              )
              # ARSOptimizer works in an ascent manner,
              # thus a neg sign for minimizing objectives.
              r_pos = -self.metric(pos_weight.numpy())
              rewards.append(r_pos)
              neg_weight = torch.sigmoid(
                  torch.matmul(torch.column_stack((X, y)), neg_param)
              )
              r_neg = -self.metric(neg_weight.numpy())
              rewards.append(r_neg)
          ars_opt.update_ars_params(torch.Tensor(rewards))
          new_weight = torch.sigmoid(
              torch.matmul(
                  torch.column_stack((X, y)),
                  torch.from_numpy(ars_opt.ars_params).float(),
              )
          )
          perf = self.metric(new_weight.numpy())
          print(f"gen {i}: perf {perf}")
      self.assertLessEqual(perf, 1e-15)
  
file_path: ReAgent/reagent/test/training/test_ars_optimizer.py
imports: import unittest
  import numpy
  import torch
  from reagent.training.gradient_free.ars_util import ARSOptimizer
label_desc: Use image node_id 2 for calling the TestARSOptimizer obj's underlying member method code with example usage: obj.test_ars_optimizer() without return types