class_docstr: Testing rig.
class_docstr_tok: ["Testing","rig","."]
docstr: Numerically validates the max score gradient.
docstr_tok: ["Numerically","validates","the","max","score","gradient","."]
code: def testMaximumSpanningTreeGradientError(self):
      """Numerically validates the max score gradient."""
      with self.test_session():
          # The maximum-spanning-tree-score function, as a max of linear functions,
          # is piecewise-linear (i.e., faceted).  The numerical gradient estimate
          # may be inaccurate if the epsilon ball used for the estimate crosses an
          # edge from one facet to another.  To avoid spurious errors, we manually
          # set the sample point so the epsilon ball fits in a facet.  Or in other
          # words, we set the scores so there is a non-trivial margin between the
          # best and second-best trees.
          scores_raw = [
              [[0, 0, 0, 0], [1, 0, 0, 0], [1, 2, 0, 0], [1, 2, 3, 4]],
              [[4, 3, 2, 9], [0, 0, 2, 9], [0, 0, 0, 9], [9, 9, 9, 9]],
          ]  # pyformat: disable
  
          # Use 64-bit floats to reduce numerical error.
          scores = constant_op.constant(scores_raw, dtypes.float64)
          init_scores = np.array(scores_raw)
  
          num_nodes = constant_op.constant([4, 3], dtypes.int32)
          max_scores = mst_ops.max_spanning_tree(
              num_nodes, scores, forest=False
          )[0]
  
          gradient_error = test.compute_gradient_error(
              scores, [2, 4, 4], max_scores, [2], init_scores
          )
          self.assertIsNot(gradient_error, None)
  
file_path: text/tensorflow_text/python/ops/mst_ops_test.py
imports: import numpy
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import test
  from tensorflow_text.python.ops import mst_ops
label_desc: Use image node_id 3 for calling the MstOpsTest obj's underlying member method code with example usage: obj.testMaximumSpanningTreeGradientError() without return types