Logic explanation metrics
- torch_explain.logic.metrics.complexity(formula: str, to_dnf: bool = False) float
Estimates the complexity of the formula.
- Parameters:
formula – logic formula.
to_dnf – whether to convert the formula in disjunctive normal form.
- Returns:
The complexity of the formula.
- torch_explain.logic.metrics.concept_consistency(formula_list: List[str]) dict
Computes the frequency of concepts in a list of logic formulas.
- Parameters:
formula_list – list of logic formulas.
- Returns:
Frequency of concepts.
- torch_explain.logic.metrics.formula_consistency(formula_list: List[str]) float
Computes the average frequency of concepts in a list of logic formulas.
- Parameters:
formula_list – list of logic formulas.
- Returns:
Average frequency of concepts.
- torch_explain.logic.metrics.test_explanation(formula: str, x: Tensor, y: Tensor, target_class: int, mask: Optional[Tensor] = None, threshold: float = 0.5, material: bool = False) Tuple[float, Tensor]
Tests a logic formula.
- Parameters:
formula – logic formula
x – input data
y – input labels (MUST be one-hot encoded)
target_class – target class
mask – sample mask
threshold – threshold to get concept truth values
- Returns:
Accuracy of the explanation and predictions
- torch_explain.logic.metrics.test_explanations(formulas: List[str], x: Tensor, y: Tensor, mask: Optional[Tensor] = None, threshold: float = 0.5, material: bool = False) Tuple[float, Tensor]
Tests all together the logic formulas of different classes. When a sample fires more than one formula, consider the sample wrongly predicted. :param formulas: list of logic formula, one for each class :param x: input data :param y: input labels (MUST be one-hot encoded) :param mask: sample mask :param threshold: threshold to get concept truth values :return: Accuracy of the explanation and predictions