deel-ai / influenciae

👋 Influenciae is a Tensorflow Toolbox for Influence Functions
https://deel-ai.github.io/influenciae
Other
55 stars 3 forks source link

[Bug]: Magic constants in boundary tests #24

Open Agustin-Picard opened 1 year ago

Agustin-Picard commented 1 year ago

Module

None

Contact Details

agustin-martin.picard@irt-saintexupery.com

Current Behavior

There are constants in the tests for the boundary_based module whose origin is not clear.

Ex: the influence_computed_expected variable in the following test.

def test_compute_influence_values():
    model = Sequential()
    model.add(Input(shape=(3,)))
    model.add(Dense(2, kernel_initializer=tf.constant_initializer([[1, 1, 1], [0, 0, 0]]),
                    bias_initializer=tf.constant_initializer([4.0, 0.0])))

    calculator = WeightsBoundaryCalculator(model)

    inputs_train = tf.zeros((1, 3))
    targets_train = tf.one_hot(tf.zeros((1,), dtype=tf.int32), 2)
    train_set = tf.data.Dataset.from_tensor_slices((inputs_train, targets_train)).batch(1)

    influence_computed_score = calculator._compute_influence_values(train_set)

    # modify the bias term to get equal logits
    influence_computed_expected = tf.convert_to_tensor([[-np.sqrt(2.0) * 2.0]], dtype=tf.float32)

    assert tf.reduce_max(tf.abs(influence_computed_expected - influence_computed_score)) < 1E-6

The same happens in the test for the other boundary method.

Expected Behavior

We expect tests to be clear to maximize maintainability in the long term. This sometimes means explaining how the expected value is calculated.

Version

v0.1.0

Environment

- OS:
- Python version:
- Tensorflow version:
- Packages used version:

Relevant log output

No response

To Reproduce

N/A