def test_relu_layer_deepliftshap_wo_mutliplying_by_inputs(self) -> None: model = ReLULinearModel() ( inputs, baselines, ) = _create_inps_and_base_for_deepliftshap_neuron_layer_testing() layer_dl_shap = LayerDeepLiftShap(model, model.relu, multiply_by_inputs=False) attributions = layer_dl_shap.attribute( inputs, baselines, attribute_to_layer_input=True, ) assertTensorAlmostEqual(self, attributions[0], [[0.0, 1.0]])
def test_linear_layer_deepliftshap(self): model = ReLULinearDeepLiftModel(inplace=True) ( inputs, baselines, ) = _create_inps_and_base_for_deepliftshap_neuron_layer_testing() layer_dl_shap = LayerDeepLiftShap(model, model.l3) attributions, delta = layer_dl_shap.attribute( inputs, baselines, attribute_to_layer_input=True, return_convergence_delta=True, ) assertTensorAlmostEqual(self, attributions[0], [[0.0, 15.0]]) assert_delta(self, delta) attributions, delta = layer_dl_shap.attribute( inputs, baselines, attribute_to_layer_input=False, return_convergence_delta=True, ) assertTensorAlmostEqual(self, attributions, [[15.0]]) assert_delta(self, delta)
def test_relu_layer_deepliftshap(self) -> None: model = ReLULinearModel() ( inputs, baselines, ) = _create_inps_and_base_for_deepliftshap_neuron_layer_testing() layer_dl_shap = LayerDeepLiftShap(model, model.relu) attributions, delta = layer_dl_shap.attribute( inputs, baselines, attribute_to_layer_input=True, return_convergence_delta=True, ) assertTensorAlmostEqual(self, attributions[0], [0.0, 15.0]) assert_delta(self, delta)
def test_relu_layer_deepliftshap_multiple_output(self): model = BasicModel_MultiLayer(multi_input_module=True) ( inputs, baselines, ) = _create_inps_and_base_for_deepliftshap_neuron_layer_testing() layer_dl = LayerDeepLiftShap(model, model.relu) attributions, delta = layer_dl.attribute( inputs[0], baselines[0], target=0, attribute_to_layer_input=False, return_convergence_delta=True, ) assertTensorTuplesAlmostEqual( self, attributions, ([[0.0, -1.0, -1.0, -1.0]], [[0.0, -1.0, -1.0, -1.0]])) assert_delta(self, delta)