class_docstr: Tests for BFGS optimization algorithm.
class_docstr_tok: ["Tests","for","BFGS","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, 3
      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(
          bfgs.minimize(
              neg_log_likelihood, initial_position=start, tolerance=1e-6
          )
      )
      expected_minima = np.array(
          [-0.020460034354, 0.171708568111, 0.021200423717],
          dtype="float64",
      )
      expected_evals = 18
      self.assertArrayNear(results.position, expected_minima, 1e-6)
      self.assertEqual(
          results.num_objective_evaluations, expected_evals
      )
  
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
  from tensorflow_probability.python.optimizer import bfgs_utils
label_desc: Use image node_id 16 for calling the BfgsTest obj's underlying member method code with example usage: obj.test_data_fitting() and returns: tf