class_docstr: Tests for get_gradient method.
  
  Since get_gradients must run in graph mode, the method is tested within
  the Estimator framework.
class_docstr_tok: ["Tests","for","get_gradient","method",".","Since","get_gradients","must","run","in","graph","mode",",","the","method","is","tested","within","the","Estimator","framework","."]
docstr: Returns a model function for a linear regressor.
code: def _make_linear_model_fn(
      self,
      optimizer_class,
      l2_norm_clip,
      noise_multiplier,
      num_microbatches,
      learning_rate,
      requires_varlist=False,
  ):
      """Returns a model function for a linear regressor."""
  
      def linear_model_fn(features, labels, mode):
          layer = tf.keras.layers.Dense(
              1,
              activation="linear",
              name="dense",
              kernel_initializer="zeros",
              bias_initializer="zeros",
          )
          preds = layer(features)
  
          vector_loss = 0.5 * tf.math.squared_difference(labels, preds)
          scalar_loss = tf.reduce_mean(input_tensor=vector_loss)
  
          # We also set the noise seed (since this is accepted by the constructor).
          if requires_varlist:
              varlist_kwarg = {
                  "var_list_or_model": layer,
                  "noise_seed": 2,
              }
          else:
              varlist_kwarg = {}
          optimizer = optimizer_class(
              l2_norm_clip=l2_norm_clip,
              noise_multiplier=noise_multiplier,
              num_microbatches=num_microbatches,
              **varlist_kwarg,
              learning_rate=learning_rate,
          )
  
          params = layer.trainable_weights
          global_step = tf.compat.v1.train.get_global_step()
          train_op = tf.group(
              optimizer.get_updates(loss=vector_loss, params=params),
              [tf.compat.v1.assign_add(global_step, 1)],
          )
          return tf_estimator.EstimatorSpec(
              mode=mode, loss=scalar_loss, train_op=train_op
          )
  
      return linear_model_fn
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras
  from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras_vectorized
label_desc: Use image node_id 1 for calling the DPOptimizerGetGradientsTest obj's underlying member method code with example usage: obj._make_linear_model_fn(optimizer_class, l2_norm_clip, noise_multiplier, num_microbatches, learning_rate, requires_varlist) and returns: linear_model_fn, tf_estimator