mbdlyb.evidence
Evidence management for probabilistic reasoning in MBD models.
The Evidence class manages observations or sensor readings for nodes in the model, supporting both hard evidence (specific state) and soft evidence (probability distributions).
Attributes
state string, state->probability dict, or probability list. |
Classes
Container for managing evidence about node states in diagnostic reasoning. |
Module Contents
- class mbdlyb.evidence.Evidence(evidence: dict[mbdlyb.MBDNode, T_NODE_EVIDENCE] | None = None)
Container for managing evidence about node states in diagnostic reasoning.
Evidence stores probability distributions (or hard assignments) for nodes and supports callbacks when evidence is added or removed, enabling reactive updates in reasoners and other components.
Evidence can be specified in three formats: - String: A single state (hard evidence) - Dict: Mapping of state names to probabilities - List: Ordered list of probabilities matching node states
- Variables:
_evidence (dict[MBDNode, list[float]]) – Mapping of nodes to their probability distributions.
_add_cbs (list[Callable]) – Callbacks invoked when evidence is added.
_drop_cbs (list[Callable]) – Callbacks invoked when evidence is removed.
- add(evidence: Evidence | dict[mbdlyb.MBDNode, T_NODE_EVIDENCE])
Add evidence from another Evidence object or a dictionary.
Non-empty probability distributions are added to this container. Any registered callbacks are invoked with the set of affected nodes.
- Parameters:
evidence (Union[Evidence, dict[MBDNode, T_NODE_EVIDENCE]]) – Evidence to add, either from another Evidence object or as a dict mapping nodes to evidence.
- add_addition_callback(cb: Callable[[set[mbdlyb.MBDNode]], None])
Register a callback to be invoked when evidence is added.
- Parameters:
cb (Callable[[set[MBDNode]], None]) – Callback function taking a set of affected nodes.
- add_drop_callback(cb: Callable[[set[mbdlyb.MBDNode]], None])
Register a callback to be invoked when evidence is removed.
- Parameters:
cb (Callable[[set[MBDNode]], None]) – Callback function taking a set of affected nodes.
- asdict() dict[str, list[float]]
Get evidence as a dictionary mapping node FQN strings to probability lists.
- Returns:
- Dictionary with node FQN strings as keys and
probability distributions as values.
- Return type:
dict[str, list[float]]
- drop(*evs: mbdlyb.MBDNode)
Remove evidence for specified nodes.
The nodes are removed from the evidence container and registered callbacks are invoked with the affected nodes.
- Parameters:
*evs (MBDNode) – Variable number of nodes whose evidence should be removed.
- items()
Iterate over (node, probabilities) pairs.
- Returns:
Yields tuples of (MBDNode, list[float]).
- Return type:
Iterator
- reset()
Clear all evidence from this container.
This does not trigger callbacks.
- type mbdlyb.evidence.T_NODE_EVIDENCE = str | dict[str, float] | list[float]
state string, state->probability dict, or probability list.
- Type:
Type alias for evidence values