Concepts Sparsity Metrics¶
Concept sparsity metrics evaluate the sparsity of the concept-space activations.
They take in the concept_explainer
and the latent_activations
, compute the concept_activations
and then compute the sparsity of the concept_activations
.
from interpreto.concepts.metrics import MetricClass
metric = MetricClass(concept_explainer)
score = metric.compute(activations)
Sparsity¶
interpreto.concepts.metrics.Sparsity
¶
Code concepts/metrics/sparsity_metrics.py
Evaluates the sparsity of the concepts activations.
It takes in the concept_explainer
and the latent_activations
, compute the concept_activations
and then compute the sparsity of the concept_activations
.
The sparsity is defined as: $$ \sum_{x}^{X} \sum_{i=1}^{cpt} \mathbb{1} ( | t(h(x))_i | > \epsilon ) $$ TODO: make the formula work
Attributes:
Name | Type | Description |
---|---|---|
concept_explainer |
ConceptEncoderExplainer
|
The explainer used to compute concepts. |
epsilon |
float
|
The threshold used to compute the sparsity. |
Source code in interpreto/concepts/metrics/sparsity_metrics.py
compute
¶
compute(latent_activations)
Compute the metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LatentActivations | dict[str, LatentActivations]
|
The latent activations. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The metric. |
Source code in interpreto/concepts/metrics/sparsity_metrics.py
Sparsity Ratio¶
interpreto.concepts.metrics.SparsityRatio
¶
Bases: Sparsity
Code concepts/metrics/sparsity_metrics.py
Evaluates the sparsity ratio of the concepts activations.
It takes in the concept_explainer
and the latent_activations
, compute the concept_activations
and then compute the sparsity ratio of the concept_activations
.
With \(A\) latent activations obtained through \(A = h(X)\), the sparsity ratio is defined as: $$ (1 / cpt) * \sum_{a}^{A} \sum_{i=1}^{cpt} \mathbb{1} ( | t(a)_i | > \epsilon ) $$ TODO: make the formula work
Attributes:
Name | Type | Description |
---|---|---|
concept_explainer |
ConceptEncoderExplainer
|
The explainer used to compute concepts. |
epsilon |
float
|
The threshold used to compute the sparsity. |
Source code in interpreto/concepts/metrics/sparsity_metrics.py
compute
¶
compute(latent_activations)
Compute the metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LatentActivations | dict[str, LatentActivations]
|
The latent activations. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The metric. |