def _update_inv_hessian(prev_state, next_state):
<EOL>should_update = ~next_state.converged & ~next_state.failed<EOL>gradient_delta = next_state.objective_gradient - prev_state.objective_gradient<EOL>position_delta = next_state.position - prev_state.position<EOL>normalization_factor = tf.reduce_sum(<EOL>input_tensor=gradient_delta * position_delta, axis=-<NUM_LIT:1>)<EOL>should_update = should_update & ~tf.equal(normalization_factor, <NUM_LIT:0>)<EOL>def _do_update_inv_hessian():<EOL><INDENT>next_inv_hessian = _bfgs_inv_hessian_update(<EOL>gradient_delta, position_delta, normalization_factor,<EOL>prev_state.inverse_hessian_estimate)<EOL>return bfgs_utils.update_fields(<EOL>next_state,<EOL>inverse_hessian_estimate=tf.where(should_update,<EOL>next_inv_hessian,<EOL>prev_state.inverse_hessian_estimate))<EOL><DEDENT>return prefer_static.cond(<EOL>tf.reduce_any(input_tensor=should_update),<EOL>_do_update_inv_hessian,<EOL>lambda: next_state)<EOL>
Update the BGFS state by computing the next inverse hessian estimate.