code: def testRegularizationWithPenaltyFactor(self):
      n = int(1e4)
      [
          model_matrix,
          response,
          _,  # model_coefficients_true
          _,  # linear_response_true
      ] = self.make_dataset(n=n, d=2, link="linear")
      # Really strong regularization should bring all regularized coefficients to
      # approximately 0.
      l2_regularizer = np.array(
          1e9 * n, dtype_util.as_numpy_dtype(model_matrix.dtype)
      )
  
      (
          model_coefficients_uniform_penalty,
          _,
          is_converged_uniform_penalty,
          _,
      ) = fisher_scoring.fit(
          model_matrix,
          response,
          family.Normal(),
          l2_regularizer=l2_regularizer,
          fast_unsafe_numerics=self.fast,
          maximum_iterations=10,
      )
  
      (
          model_coefficients_penalty_factor,
          _,
          is_converged_penalty_factor,
          _,
      ) = fisher_scoring.fit(
          model_matrix,
          response,
          family.Normal(),
          l2_regularizer=l2_regularizer,
          # only penalize (apply regularization to) second coefficient
          l2_regularization_penalty_factor=[0.0, 1.0],
          fast_unsafe_numerics=self.fast,
          maximum_iterations=10,
      )
  
      [
          model_coefficients_uniform_penalty_,
          is_converged_uniform_penalty_,
          model_coefficients_penalty_factor_,
          is_converged_penalty_factor_,
      ] = self.evaluate(
          [
              model_coefficients_uniform_penalty,
              is_converged_uniform_penalty,
              model_coefficients_penalty_factor,
              is_converged_penalty_factor,
          ]
      )
  
      self.assertTrue(is_converged_uniform_penalty_)
      self.assertTrue(is_converged_penalty_factor_)
      # When regularization is applied to all coefficients, they should all be
      # close to 0.
      self.assertAllClose(
          [0.0, 0.0],
          model_coefficients_uniform_penalty_,
          rtol=1e-6,
          atol=1e-6,
      )
      # When regularization is applied only to second coefficient, only it should
      # be close to 0.
      self.assertGreater(
          np.abs(model_coefficients_penalty_factor_[0]), 1e-6
      )
      self.assertNear(
          0.0, model_coefficients_penalty_factor_[1], err=1e-6
      )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.glm import family
  from tensorflow_probability.python.glm import fisher_scoring
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 6 for calling the FitTestFast obj's underlying member method code with example usage: obj.testRegularizationWithPenaltyFactor() without return types