code: def test_weights_to_handle_outliers(self):
      true_parameters = np.array([[0.04, 0.15, 0.5, 0.3, 0.3]])
  
      forwards = np.array([5.0])
      expiries = np.array([1.0])
  
      strikes = np.array(
          [
              [
                  0.24893534,
                  0.35810619,
                  0.51515402,
                  0.74107533,
                  1.06607467,
                  1.53360279,
                  2.20616584,
                  3.17368209,
                  4.56550358,
                  6.56770979,
                  9.44798554,
                  13.59140914,
              ],
          ]
      )
  
      volatilities = np.array(
          [
              [
                  0.53809037,
                  0.51236712,
                  0.48535488,
                  0.45686258,
                  0.42666483,
                  0.39451975,
                  0.3602712,
                  0.32435877,
                  0.29085295,
                  0.28834027,
                  0.3644639,
                  0.45468296,
              ],
          ]
      )
      weights = np.ones_like(volatilities)
  
      (model_parameters, converged, _) = self.evaluate(
          tff.experimental.svi.calibration(
              forwards=forwards,
              expiries=expiries,
              strikes=strikes,
              volatilities=volatilities,
              weights=weights,
              optimizer_fn=tfp.optimizer.bfgs_minimize,
          )
      )
  
      with self.subTest("Model without outliers converged"):
          self.assertTrue(converged.all())
      with self.subTest(
          "Parameters correct for model without outliers"
      ):
          self.assertAllClose(
              model_parameters, true_parameters, atol=1e-4, rtol=1e-3
          )
  
      # introduce outliers - changes tail volatilities to much higher values
      volatilities[0, 0] = 0.7
      volatilities[0, 0] = 0.8
  
      (model_parameters, converged, _) = self.evaluate(
          tff.experimental.svi.calibration(
              forwards=forwards,
              expiries=expiries,
              strikes=strikes,
              volatilities=volatilities,
              weights=weights,
              optimizer_fn=tfp.optimizer.bfgs_minimize,
          )
      )
      with self.subTest("Model with outliers did not converge"):
          self.assertFalse(converged.all())
      with self.subTest("Parameters incorrect for model with outliers"):
          self.assertNotAllClose(
              model_parameters, true_parameters, atol=1e-4, rtol=1e-3
          )
  
      # zero out optimization weights, corresponding to outliers
      weights[0, 0] = 0
      weights[0, -1] = 0
  
      (model_parameters, converged, _) = self.evaluate(
          tff.experimental.svi.calibration(
              forwards=forwards,
              expiries=expiries,
              strikes=strikes,
              volatilities=volatilities,
              weights=weights,
              optimizer_fn=tfp.optimizer.bfgs_minimize,
          )
      )
  
      with self.subTest("Model with weighted out outliers converged"):
          self.assertTrue(converged.all())
      with self.subTest(
          "Parameters correct for model with weighted out outliers"
      ):
          self.assertAllClose(
              model_parameters, true_parameters, atol=1e-4, rtol=1e-3
          )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/svi/calibration_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 3 for calling the SimulatedDataCalibrationTest obj's underlying member method code with example usage: obj.test_weights_to_handle_outliers() without return types