code: def bfgs_inverse_hessian(
      *,
      updates_of_position_differences,
      updates_of_gradient_differences,
  ):
      """Estimate the inverse hessian from the position updates."""
      dim, history = jnp.shape(updates_of_position_differences)
      inverse_outer = jnp.linalg.inv(
          jnp.tril(
              jnp.einsum(
                  "ji,jk->ik",
                  updates_of_position_differences,
                  updates_of_gradient_differences,
              )
          )
      )
      if history == 0:
          diagonal_scale = 1.0
      else:
          diagonal_scale = jnp.linalg.norm(
              updates_of_gradient_differences[:, -1], ord=2
          ) / (
              updates_of_position_differences[:, -1]
              @ updates_of_gradient_differences[:, -1]
          )
      diagonal_estimate = diagonal_scale * jnp.ones(dim)
      eta = jnp.einsum(
          "ij,ij->j",
          updates_of_position_differences,
          updates_of_gradient_differences,
      )
      thin_factors = jnp.concatenate(
          (
              diagonal_scale * updates_of_gradient_differences,
              updates_of_position_differences,
          ),
          axis=-1,
      )
      scaling_outer_product = jnp.block(
          [
              [jnp.zeros((history, history)), -inverse_outer],
              [
                  -jnp.transpose(inverse_outer),
                  jnp.transpose(inverse_outer)
                  @ (
                      jnp.diag(eta)
                      + diagonal_scale
                      * jnp.transpose(updates_of_gradient_differences)
                      @ updates_of_gradient_differences
                  )
                  @ inverse_outer,
              ],
          ]
      )
      return diagonal_estimate, thin_factors, scaling_outer_product
  
file_path: probability/discussion/pathfinder/pathfinder.py
imports: from typing import Tuple, List, Sequence, Callable
  import jax
  import jax.numpy
  import numpy
label_desc: Use image node_id 7 for calling a global function with example usage: bfgs_inverse_hessian() and returns: diagonal_estimate,  thin_factors,  scaling_outer_product