Skip to content

Commit

Permalink
add missing docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
aaarrti committed Aug 30, 2023
1 parent 6989748 commit 4d1d25e
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 11 deletions.
15 changes: 5 additions & 10 deletions quantus/metrics/faithfulness/monotonicity_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def evaluate_batch(
Parameters
----------
model: ModelInterface
A ModelInterface that is subject to explanation.
A model that is subject to explanation.
x_batch: np.ndarray
The input to be evaluated on a batch-basis.
y_batch: np.ndarray
Expand All @@ -412,19 +412,14 @@ def evaluate_batch(
List[float]
The evaluation results.
"""
# Asserts.
asserts.assert_features_in_step(
features_in_step=self.features_in_step,
input_shape=x_batch.shape[2:],
)

# Evaluate explanations.
return [
self.evaluate_instance(
model=model,
x=x,
y=y,
a=a,
model,
x,
y,
a,
)
for x, y, a in zip(x_batch, y_batch, a_batch)
]
15 changes: 15 additions & 0 deletions quantus/metrics/faithfulness/sufficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,22 @@ def evaluate_batch(
self, *, i_batch, a_sim_vector_batch, y_pred_classes, **_
) -> List[float]:
"""
TODO: write meaningful docstring about what does it compute.
Parameters
----------
i_batch:
The index of the current instance.
a_sim_vector_batch:
The custom input to be evaluated on an instance-basis.
y_pred_classes:
The class predictions of the complete input dataset.
_:
unused.
Returns
-------
"""

return [
Expand Down
15 changes: 15 additions & 0 deletions quantus/metrics/localisation/auc.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,20 @@ def custom_preprocess(
def evaluate_batch(
self, *, a_batch: np.ndarray, s_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
s_batch:
A np.ndarray which contains segmentation masks that matches the input.
_:
unused.
Returns
-------
"""
# TODO: for performance reasons replace for-loop with vectorized dispatch.
return [self.evaluate_instance(a, s) for a, s in zip(a_batch, s_batch)]
14 changes: 14 additions & 0 deletions quantus/metrics/localisation/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,18 @@ def quadrant_bottom_right(self, a: np.ndarray) -> np.ndarray:
def evaluate_batch(
self, *, a_batch: np.ndarray, c_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
c_batch:
The custom input to be evaluated on an batch-basis.
_:
unused.
Returns
-------
"""
return [self.evaluate_instance(a, c) for a, c in zip(a_batch, c_batch)]
15 changes: 15 additions & 0 deletions quantus/metrics/localisation/pointing_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,19 @@ def custom_preprocess(
def evaluate_batch(
self, *, a_batch: np.ndarray, s_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
s_batch:
A np.ndarray which contains segmentation masks that matches the input.
_:
unused.
Returns
-------
"""
return [self.evaluate_instance(a, s) for a, s in zip(a_batch, s_batch)]
14 changes: 14 additions & 0 deletions quantus/metrics/localisation/relevance_mass_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,18 @@ def custom_preprocess(
def evaluate_batch(
self, *, a_batch: np.ndarray, s_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
s_batch:
A np.ndarray which contains segmentation masks that matches the input.
_:
unused.
Returns
-------
"""
return [self.evaluate_instance(a, s) for a, s in zip(a_batch, s_batch)]
15 changes: 15 additions & 0 deletions quantus/metrics/localisation/relevance_rank_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,20 @@ def custom_preprocess(
def evaluate_batch(
self, *, a_batch: np.ndarray, s_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
s_batch:
A np.ndarray which contains segmentation masks that matches the input.
_:
unused.
Returns
-------
"""
# TODO: for performance reasons, this method should be vectorized.
return [self.evaluate_instance(a, s) for a, s in zip(a_batch, s_batch)]
15 changes: 15 additions & 0 deletions quantus/metrics/localisation/top_k_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,19 @@ def custom_preprocess(
def evaluate_batch(
self, *, a_batch: np.ndarray, s_batch: np.ndarray, **_
) -> List[float]:
"""
Parameters
----------
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
s_batch:
A np.ndarray which contains segmentation masks that matches the input.
_:
unused.
Returns
-------
"""
return [self.evaluate_instance(a, s) for a, s in zip(a_batch, s_batch)]
20 changes: 19 additions & 1 deletion quantus/metrics/randomisation/random_logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,25 @@ def evaluate_batch(
a_batch: np.ndarray,
**_,
) -> List[float]:
# TODO: for performance reasons vectorize this for-loop
"""
Parameters
----------
model:
A model that is subject to explanation.
x_batch:
A np.ndarray which contains the input data that are explained.
y_batch:
A np.ndarray which contains the output labels that are explained.
a_batch:
A np.ndarray which contains pre-computed attributions i.e., explanations.
_:
unused.
Returns
-------
"""
return [
self.evaluate_instance(model, x, y, a)
for x, y, a in zip(x_batch, y_batch, a_batch)
Expand Down
17 changes: 17 additions & 0 deletions quantus/metrics/robustness/continuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,21 @@ def evaluate_batch(
y_batch: np.ndarray,
**_,
) -> List[Dict[str, int]]:
"""
Parameters
----------
model:
A model that is subject to explanation.
x_batch:
A np.ndarray which contains the input data that are explained.
y_batch:
A np.ndarray which contains the output labels that are explained.
_:
unused.
Returns
-------
"""
return [self.evaluate_instance(model, x, y) for x, y in zip(x_batch, y_batch)]

0 comments on commit 4d1d25e

Please sign in to comment.