code: def test_ig_saliency_map():
      graph = example_graph_1(feature_size=4)
      (
          base_model,
          keras_model_gcn,
          generator,
          train_gen,
      ) = create_GCN_model_dense(graph)
      (
          base_model_sp,
          keras_model_gcn_sp,
          generator_sp,
          train_gen_sp,
      ) = create_GCN_model_sparse(graph)
  
      keras_model_gcn.compile(
          optimizer=Adam(lr=0.1),
          loss=categorical_crossentropy,
          weighted_metrics=["acc"],
      )
  
      keras_model_gcn_sp.compile(
          optimizer=Adam(lr=0.1),
          loss=categorical_crossentropy,
          weighted_metrics=["acc"],
      )
  
      weights = [
          np.array(
              [
                  [0.43979216, -0.205199],
                  [0.774606, 0.9521842],
                  [-0.7586646, -0.41291213],
                  [-0.80931616, 0.8148985],
              ],
              dtype="float32",
          ),
          np.array([0.0, 0.0], dtype="float32"),
          np.array(
              [[1.0660936, -0.48291892], [1.2134176, 1.1863097]],
              dtype="float32",
          ),
          np.array([0.0, 0.0], dtype="float32"),
      ]
  
      keras_model_gcn.set_weights(weights)
      keras_model_gcn_sp.set_weights(weights)
  
      ig_dense = IntegratedGradients(keras_model_gcn, train_gen)
      ig_sparse = IntegratedGradients(keras_model_gcn_sp, train_gen_sp)
  
      target_idx = 0
      class_of_interest = 0
      ig_node_importance_dense = ig_dense.get_node_importance(
          target_idx, class_of_interest, steps=50
      )
      ig_node_importance_sp = ig_sparse.get_node_importance(
          target_idx, class_of_interest, steps=50
      )
  
      ig_node_importance_ref = np.array([20.91, 18.29, 11.98, 5.98, 0])
      assert pytest.approx(
          ig_node_importance_dense, ig_node_importance_ref
      )
      assert pytest.approx(
          ig_node_importance_dense, ig_node_importance_sp
      )
  
      ig_link_importance_nz_ref = np.array(
          [
              0.2563,
              0.2759,
              0.2423,
              0.0926,
              0.1134,
              0.0621,
              0.0621,
              0.0621,
          ]
      )
  
      ig_link_importance_dense = ig_dense.get_integrated_link_masks(
          target_idx, class_of_interest, adj_baseline=None, steps=50
      )
      ig_link_importance_dense_nz = ig_link_importance_dense[
          np.nonzero(ig_link_importance_dense)
      ]
      ig_link_importance_sp = ig_sparse.get_integrated_link_masks(
          target_idx, class_of_interest, adj_baseline=None, steps=50
      )
      ig_link_importance_sp_nz = ig_link_importance_sp[
          np.nonzero(ig_link_importance_sp)
      ]
  
      assert pytest.approx(
          ig_link_importance_dense_nz, ig_link_importance_nz_ref
      )
  
      assert pytest.approx(
          ig_link_importance_dense_nz, ig_link_importance_sp_nz
      )
  
file_path: stellargraph/tests/interpretability/test_saliency_maps_gcn.py
imports: import pytest
  from stellargraph.interpretability.saliency_maps import *
  import numpy
  from stellargraph.layer import GCN
  from stellargraph.mapper import FullBatchNodeGenerator
  from tensorflow.keras import Model, regularizers
  from tensorflow.keras.optimizers import Adam
  from tensorflow.keras.losses import categorical_crossentropy
  from ..test_utils.graphs import example_graph_1_saliency_maps
label_desc: Use image node_id 3 for calling a global function with example usage: test_ig_saliency_map() without return types