docstr: Test that distribution works as layer and in gradient optimization.
docstr_tok: ["Test","that","distribution","works","as","layer","and","in","gradient","optimization","."]
code: def testWorksInDistributionLayerAndNegloglik(self):
      """Test that distribution works as layer and in gradient optimization."""
      x = np.random.uniform(size=(100, 1))
      y = 2 + -1 * x
      lwn = lambertw_f.LambertWNormal(
          tailweight=0.5, loc=0.2, scale=1.0
      )
      eps = self.evaluate(
          lwn.sample(x.shape, seed=test_util.test_seed())
      )
      y += eps
  
      def dist_lambda(t):
          return lambertw_f.LambertWNormal(
              loc=t[..., :1],
              scale=1e-3 + tf.math.softplus(t[..., 1:2]),
              tailweight=1e-3 + tf.math.softplus(t[..., 2:]),
          )
  
      from tensorflow_probability.python.layers import (
          distribution_layer,
      )  # pylint:disable=g-import-not-at-top
  
      dist_layer = distribution_layer.DistributionLambda(dist_lambda)
      model = tf_keras.Sequential(
          [
              tf_keras.layers.Dense(10, "relu"),
              tf_keras.layers.Dense(5, "selu"),
              tf_keras.layers.Dense(1 + 1 + 1),
              dist_layer,
          ]
      )
      negloglik = lambda y, p_y: -p_y.log_prob(y)
      if tf.__internal__.tf2.enabled() and tf.executing_eagerly():
          optimizer = tf_keras.optimizers.Adam(learning_rate=0.01)
      else:
          optimizer = tf_keras.optimizers.legacy.Adam(
              learning_rate=0.01
          )
  
      model.compile(optimizer=optimizer, loss=negloglik)
  
      model.fit(
          x,
          y,
          epochs=1,
          verbose=True,
          batch_size=32,
          validation_split=0.2,
      )
      self.assertGreater(model.history.history["val_loss"][0], -np.Inf)
  
imports: import math
  from absl.testing import parameterized
  import numpy
  from scipy import stats
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import lambertw_transform
  from tensorflow_probability.python.distributions import lambertw_f
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal import tf_keras
label_desc: Use image node_id 10 for calling the LambertWNormalTest obj's underlying member method code with example usage: obj.testWorksInDistributionLayerAndNegloglik() and returns: lambertw_f