desdeo_brb.models¶
Pydantic data models for BRB state and inference results.
models
¶
Pydantic models for BRB data structures.
Defines the core data containers used throughout the BRB system: rule bases, inference results, and trainable parameter containers.
RuleBase
¶
Bases: BaseModel
Holds the complete specification of a Belief Rule Base.
Attributes:
| Name | Type | Description |
|---|---|---|
precedent_referential_values |
list[ndarray]
|
List of 1D sorted arrays, one per attribute. Arrays may have varying lengths. |
consequent_referential_values |
ndarray
|
1D sorted array of consequent values. |
belief_degrees |
ndarray
|
Shape |
rule_weights |
ndarray
|
Shape |
attribute_weights |
ndarray
|
Shape |
rule_antecedent_indices |
ndarray
|
Shape |
describe_rule
¶
describe_rule(k: int, attribute_names: list[str] | None = None, consequent_name: str | None = None, show_zero_beliefs: bool = False) -> str
Return a human-readable description of rule k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Rule index (0-based). |
required |
attribute_names
|
list[str] | None
|
Display names for each attribute. If |
None
|
consequent_name
|
str | None
|
Display name for the consequent. If |
None
|
show_zero_beliefs
|
bool
|
If |
False
|
Source code in src/desdeo_brb/models.py
describe_all_rules
¶
describe_all_rules(attribute_names: list[str] | None = None, consequent_name: str | None = None, show_zero_beliefs: bool = False) -> str
Return a multi-line string describing every rule.
Source code in src/desdeo_brb/models.py
InferenceResult
¶
Bases: BaseModel
Container for the full trace of a BRB inference call.
Attributes:
| Name | Type | Description |
|---|---|---|
input_belief_distributions |
list[ndarray]
|
List of arrays, one per attribute, each
of shape |
activation_weights |
ndarray
|
Shape |
combined_belief_degrees |
ndarray
|
Shape |
consequent_values |
ndarray
|
1-D array of consequent referential values. |
output |
ndarray
|
Shape |
dominant_rules
¶
Return the indices of the top-k most activated rules per sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k
|
int
|
Number of dominant rules to return. |
3
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer array of shape |
ndarray
|
sorted by activation weight descending. |
Source code in src/desdeo_brb/models.py
explain
¶
explain(sample_idx: int = 0, top_k: int = 3, rule_base: RuleBase | None = None, attribute_names: list[str] | None = None, consequent_name: str | None = None, threshold: float = 0.01) -> str
Return a human-readable explanation of a single prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_idx
|
int
|
Which sample in the batch to explain. |
0
|
top_k
|
int
|
Number of top-activated rules to show. |
3
|
rule_base
|
RuleBase | None
|
The |
None
|
attribute_names
|
list[str] | None
|
Passed through to |
None
|
consequent_name
|
str | None
|
Passed through to |
None
|
threshold
|
float
|
Minimum activation weight or belief degree to display; values below this are omitted for clarity. |
0.01
|
Source code in src/desdeo_brb/models.py
to_dict
¶
Return a JSON-serializable summary of the inference result.
Numpy arrays are converted to nested Python lists.