code: def test_tracin_regression_1D_numerical(
      self, reduction: str, tracin_constructor: Callable
  ) -> None:
      low = 1
      high = 17
      features = 1
      dataset = RangeDataset(low, high, features)
      net = CoefficientNet()
      self.assertTrue(isinstance(reduction, str))
      criterion = nn.MSELoss(reduction=cast(str, reduction))
      batch_size = 4
      weights = [0.4379, 0.1653, 0.5132, 0.3651, 0.9992]
  
      train_inputs = dataset.samples
      train_labels = dataset.labels
  
      with tempfile.TemporaryDirectory() as tmpdir:
          for i, weight in enumerate(weights):
              net.fc1.weight.data.fill_(weight)
              checkpoint_name = "-".join(
                  ["checkpoint-reg", str(i + 1) + ".pt"]
              )
              torch.save(
                  net.state_dict(),
                  os.path.join(tmpdir, checkpoint_name),
              )
  
          self.assertTrue(callable(tracin_constructor))
          tracin = tracin_constructor(
              net,
              dataset,
              tmpdir,
              batch_size,
              criterion,
          )
  
          train_scores = tracin.influence(
              (train_inputs, train_labels), k=None
          )
  
          r"""
              Derivation for gradient / resulting TracIn score:
  
              For each checkpoint: $y = Wx,$ and $loss = (y - label)^2.$ Recall for this
              test case, there is no activation on y. For this example, $label = x.$
  
              Fast Rand Proj gives $\nabla_W loss = \nabla_y loss (x^T).$ We have $x$ and
              y as scalars so we can simply multiply. So then,
  
              \[\nabla_y loss * x = 2(y-x)*x = 2(Wx -x)*x = 2x^2 (w - 1).\]
  
              And we simply multiply these for x, x'. In this case, $x, x' \in [1..16]$.
              """
          for i in range(train_scores.shape[0]):
              for j in range(len(train_scores[0])):
                  _weights = torch.Tensor(weights)
                  num = 2 * (i + 1) * (i + 1) * (_weights - 1)
                  num *= 2 * (j + 1) * (j + 1) * (_weights - 1)
                  assertTensorAlmostEqual(
                      self,
                      torch.sum(num),
                      train_scores[i][j],
                      delta=0.1,
                  )
  
file_path: captum/tests/influence/_core/test_tracin_regression.py
imports: import os
  import tempfile
  from typing import Callable, cast, Optional
  import torch
  import torch.nn
  from captum.influence._core.arnoldi_influence_function import ArnoldiInfluenceFunction
  from captum.influence._core.influence_function import NaiveInfluenceFunction
  from captum.influence._core.tracincp import TracInCP
  from captum.influence._core.tracincp_fast_rand_proj import TracInCPFast, TracInCPFastRandProj
  from parameterized import parameterized
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.influence._utils.common import _isSorted, _wrap_model_in_dataparallel, build_test_name_func, CoefficientNet, DataInfluenceConstructor, IdentityDataset, RangeDataset
label_desc: Use image node_id 3 for calling the TestTracInRegression obj's underlying member method code with example usage: obj.test_tracin_regression_1D_numerical(reduction, tracin_constructor) without return types