class_docstr: Tests for `pairwise_distance_lib.PairwiseDistance`.
class_docstr_tok: ["Tests","for","`","pairwise_distance_lib.PairwiseDistance","`","."]
docstr: Tests that weights are propagated to the distance function.
docstr_tok: ["Tests","that","weights","are","propagated","to","the","distance","function","."]
code: def testWeights(self):
      """Tests that weights are propagated to the distance function."""
      regularizer = pairwise_distance_lib.PairwiseDistance(
          configs.DistanceConfig(
              distance_type=configs.DistanceType.KL_DIVERGENCE,
              sum_over_axis=-1,
          ),
          name="weighted_kl_loss",
      )
      example = np.array([0.1, 0.4, 0.5])
      neighbors = np.array([[0.6, 0.2, 0.2], [0.9, 0.01, 0.09]])
      neighbor_weight = 0.5
      loss = self.evaluate(
          regularizer(example, neighbors, neighbor_weight)
      )
      self.assertAllClose(
          loss,
          neighbor_weight
          * np.mean(np.sum(special.kl_div(example, neighbors), -1)),
          _ERR_TOL,
      )
  
file_path: neural-structured-learning/neural_structured_learning/keras/layers/pairwise_distance_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import neural_structured_learning.configs
  from neural_structured_learning.keras.layers import pairwise_distance
  import numpy
  from scipy import special
  import tensorflow
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 3 for calling the PairwiseDistanceTest obj's underlying member method code with example usage: obj.testWeights() without return types