class_docstr: Tests for LBFGS optimization algorithm.
class_docstr_tok: ["Tests","for","LBFGS","optimization","algorithm","."]
docstr: Tests MLE estimation for a simple geometric GLM.
docstr_tok: ["Tests","MLE","estimation","for","a","simple","geometric","GLM","."]
code: def test_data_fitting(self):
      """Tests MLE estimation for a simple geometric GLM."""
      n, dim = 100, 30
      dtype = tf.float64
      np.random.seed(234095)
      x = np.random.choice([0, 1], size=[dim, n])
      s = 0.01 * np.sum(x, 0)
      p = 1.0 / (1 + np.exp(-s))
      y = np.random.geometric(p)
      x_data = tf.convert_to_tensor(x, dtype=dtype)
      y_data = tf.convert_to_tensor(y, dtype=dtype)[..., tf.newaxis]
  
      @_make_val_and_grad_fn
      def neg_log_likelihood(state):
          state_ext = tf.expand_dims(state, 0)
          linear_part = tf.matmul(state_ext, x_data)
          linear_part_ex = tf.stack(
              [tf.zeros_like(linear_part), linear_part], axis=0
          )
          term1 = tf.squeeze(
              tf.matmul(
                  tf.reduce_logsumexp(linear_part_ex, axis=0), y_data
              ),
              -1,
          )
          term2 = 0.5 * tf.reduce_sum(
              state_ext * state_ext, axis=-1
          ) - tf.reduce_sum(linear_part, axis=-1)
          return tf.squeeze(term1 + term2)
  
      start = tf.ones(shape=[dim], dtype=dtype)
  
      results = self.evaluate(
          lbfgs.minimize(
              neg_log_likelihood, initial_position=start, tolerance=1e-6
          )
      )
      self.assertTrue(results.converged)
  
imports: from absl.testing import parameterized
  import numpy
  from scipy.stats import special_ortho_group
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.optimizer import bfgs_utils
  from tensorflow_probability.python.optimizer import lbfgs
label_desc: Use image node_id 13 for calling the LBfgsTest obj's underlying member method code with example usage: obj.test_data_fitting() and returns: tf