docstr: Tests that the loss during training includes graph regularization.
docstr_tok: ["Tests","that","the","loss","during","training","includes","graph","regularization","."]
code: def test_graph_reg_wrapper_one_neighbor_with_training(self):
      """Tests that the loss during training includes graph regularization."""
      # Base model: y = w*x+b = 4*x1 + 3*x2 + 2
      weight = np.array([[4.0], [3.0]], dtype=np.float32)
      bias = np.array([2.0], dtype=np.float32)
      # Expected y value.
      x0, y0 = np.array([[1.0, 1.0]]), np.array([8.0])
      neighbor0 = np.array([[0.5, 1.5]])
  
      example = """
                  features {
                    feature {
                      key: "x"
                      value: { float_list { value: [ 1.0, 1.0 ] } }
                    }
                    feature {
                      key: "NL_nbr_0_x"
                      value: { float_list { value: [ 0.5, 1.5 ] } }
                    }
                    feature {
                      key: "NL_nbr_0_weight"
                      value: { float_list { value: 1.0 } }
                    }
                    feature {
                      key: "y"
                      value: { float_list { value: 8.0 } }
                    }
                  }
                """
  
      # Compute the gradients on the original example using the updated loss term,
      # which includes the supervised loss as well as the graph loss.
      orig_pred = np.dot(x0, weight) + bias  # [9.0]
  
      # Based on the implementation of embedding_fn inside
      # _train_and_check_params.
      x0_embedding = np.dot(x0, weight)
      neighbor0_embedding = np.dot(neighbor0, weight)
  
      # The graph loss term is (x0_embedding - neighbor0_embedding)^2
      orig_grad_w = (
          2 * (orig_pred - y0) * x0.T
          + 2
          * (x0_embedding - neighbor0_embedding)
          * (x0 - neighbor0).T
      )  # [[2.5], [1.5]]
      orig_grad_b = 2 * (orig_pred - y0).reshape((1,))  # [2.0]
  
      self._train_and_check_params(
          example, 1, weight, bias, orig_grad_w, orig_grad_b
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import shutil
  import tempfile
  import neural_structured_learning.configs
  import neural_structured_learning.estimator
  import numpy
  import tensorflow
  from tensorflow import estimator
  from google.protobuf import text_format
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 6 for calling the GraphRegularizationTest obj's underlying member method code with example usage: obj.test_graph_reg_wrapper_one_neighbor_with_training() without return types