API Reference
Frame
- class evidencelib.Frame(atoms, *, empty=(), exclusive=False, model='hybrid')[source]
A finite frame of discernment.
The internal representation uses Venn regions. This lets the same proposition algebra represent Shafer’s exclusive DST model, the free DSmT model, and constrained hybrid DSm models.
- Parameters:
atoms (Sequence[str]) – Names of the elementary hypotheses.
empty (Iterable[str | Proposition]) – Propositions that are constrained to be empty in a hybrid model.
exclusive (bool | Iterable[Sequence[str]]) – If
True, all atom pairs are mutually exclusive. An iterable of atom groups may be supplied to mark only selected intersections as empty.model (str) – Descriptive model name stored on the frame.
- atom(name)[source]
Return the singleton proposition for an atom name.
- Parameters:
name (str)
- Return type:
- elements(*, max_count=100000)[source]
Generate the model’s closure under union and intersection.
The result is the power set for DST and the hyper-power set for the free DSm model. DSmT cardinality grows very quickly; pass
max_count=Noneonly when you really want the full closure.- Parameters:
max_count (int | None)
- Return type:
tuple[Proposition, …]
- format(prop)[source]
Format a proposition as a compact expression using frame atom names.
- Parameters:
prop (Proposition)
- Return type:
- mass(values, **kwargs)[source]
Create a mass function on this frame.
- Parameters:
values (Mapping[Any, float]) – Mapping from propositions, proposition expressions, or iterables of atom names to assigned masses.
**kwargs (Any) – Additional options passed to
evidencelib.MassFunction.
- Return type:
- property model_signature: tuple[int, ...]
Stable structural signature of the model’s possible Venn regions.
- proposition(value)[source]
Coerce a string, proposition, or iterable of atoms into a proposition.
- Parameters:
value (str | Proposition | Iterable[str])
- Return type:
- symbols(names=None)[source]
Return atom propositions.
namesmay be omitted to return all frame atoms, or supplied as a whitespace/comma-separated subset.- Parameters:
names (str | None)
- Return type:
tuple[Proposition, …]
MassFunction
- class evidencelib.MassFunction(frame, values, *, validate=True, tolerance=1e-09)[source]
A basic belief assignment over a frame.
- Parameters:
frame (Frame) – Frame of discernment that owns all propositions in the assignment.
values (Mapping[Any, float]) – Mapping from propositions, proposition expressions, or iterables of atom names to assigned masses.
validate (bool) – Validate that masses are non-negative and sum to one.
tolerance (float) – Numerical tolerance used when cleaning and validating masses.
- belief(key)[source]
Return belief, the mass of propositions contained in
key.- Parameters:
key (str | Proposition | Iterable[str])
- Return type:
- commonality(key)[source]
Return commonality, the mass of propositions containing
key.- Parameters:
key (str | Proposition | Iterable[str])
- Return type:
- conjunctive(*others, model=None)[source]
Unnormalized conjunctive rule.
On a free DSm frame this is the classic DSm rule (DSmC). On Shafer’s DST model, contradictory intersections are accumulated on
empty.- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
- dempster(*others, model=None)[source]
Dempster’s normalized rule of combination.
- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
- dsmc(*others)[source]
Alias for the classic conjunctive DSm rule.
- Parameters:
others (MassFunction)
- Return type:
- dsmh(*others, model=None)[source]
Apply the hybrid DSm rule, including its S1, S2, and S3 terms.
For a dynamic model change, create the source assignments on their original frame and pass the constrained target frame as
model. This preserves each focal proposition andu(X)until constraints are applied. With no explicit model, the rule operates statically on the sources’ existing frame and rejects mass already collapsed onto empty.- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
- dubois_prade(*others, model=None)[source]
Apply the static Dubois-Prade conflict-transfer rule.
Dubois-Prade is a static rule. Passing a distinct target
modeldenotes a dynamic model change and is rejected rather than silently returning a DSmH result.- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
- focal()[source]
Return propositions with non-zero assigned mass.
- Return type:
tuple[Proposition, …]
- classmethod from_csv(frame, text, *, has_header=True, **kwargs)[source]
Create a mass function from CSV text with proposition and mass columns.
- Parameters:
- Return type:
- classmethod from_dict(frame, data, **kwargs)[source]
Create a mass function from a plain or schema-wrapped dictionary.
datamay be a direct mapping such as{"A": 0.2, "A|B": 0.8}or the object produced byto_json()after JSON decoding.- Parameters:
frame (Frame)
data (Mapping[Any, Any])
kwargs (Any)
- Return type:
- classmethod from_json(frame, text, **kwargs)[source]
Create a mass function from JSON produced by
to_json().- Parameters:
- Return type:
- items()[source]
Return focal propositions and masses sorted by proposition label.
- Return type:
tuple[tuple[Proposition, float], …]
- mass(key)[source]
Return the direct mass assigned to a proposition.
- Parameters:
key (str | Proposition | Iterable[str])
- Return type:
- normalization_tolerance = 1e-06
- pcr5(other)[source]
PCR5 for two sources.
- Parameters:
other (MassFunction)
- Return type:
- pcr6(*others)[source]
PCR6 proportional conflict redistribution for two or more sources.
- Parameters:
others (MassFunction)
- Return type:
- pignistic(*, normalize_conflict=True)[source]
Return pignistic scores for singleton hypotheses.
This is the classical pignistic transformation on DST frames. On free or hybrid DSmT frames, singleton hypotheses can overlap, so the returned event scores are useful for decisions but do not have to sum to one.
If
normalize_conflictis true, mass assigned to the empty proposition is ignored and the remaining scores are rescaled by1 - conflict. This makes TBM/Smets results usable for pignistic decisions while still allowing raw unnormalized scores withnormalize_conflict=False.
- pignistic_of(key, *, normalize_conflict=True)[source]
Return the generalized pignistic probability of one proposition.
This implements
C_M(X & A) / C_M(X)for arbitraryAin the frame’s hyper-power set. Empty-set conflict is normalized consistently withpignistic()andpignistic_regions().
- pignistic_regions(*, normalize_conflict=True)[source]
Return a probability distribution over model Venn regions.
If
normalize_conflictis true, empty-set conflict is excluded and the non-empty region probabilities are rescaled by1 - conflict.
- plausibility(key)[source]
Return plausibility, the mass of propositions intersecting
key.- Parameters:
key (str | Proposition | Iterable[str])
- Return type:
- plot(*, ax=None, **kwargs)[source]
Plot this mass assignment as a horizontal bar chart.
This method requires the optional plotting dependency. Install it with
pip install 'evidencelib[plot]'.
- plot_belief_plausibility(*, ax=None, **kwargs)[source]
Plot belief-plausibility intervals for this mass assignment.
- plot_comparison(*others, labels=None, ax=None, **kwargs)[source]
Plot a heatmap comparing this mass assignment with other sources.
- plot_pignistic_decision(*, ax=None, **kwargs)[source]
Plot the pignistic decision ranking for this mass assignment.
- plot_venn(*, ax=None, **kwargs)[source]
Plot pignistic or direct mass values over disjoint Venn regions.
- smets(*others, model=None)[source]
Smets/TBM unnormalized rule, keeping conflict on the empty set.
- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
- to_csv(*, include_header=True, float_format=None)[source]
Serialize this mass assignment to CSV text.
The CSV has two columns:
propositionandmass. It is intended for data exchange and round trips, not for presentation tables.
- to_dict(*, string_keys=True)[source]
Return the mass assignment as a plain dictionary.
- Parameters:
string_keys (bool)
- Return type:
dict[str | Proposition, float]
- to_json(*, indent=2)[source]
Serialize this mass function to a JSON string.
The JSON stores the mass assignment and lightweight frame metadata for validation. Import still requires the caller to provide the target frame, because hybrid DSm constraints are model semantics rather than just mass data.
- to_latex(*, columns=('mass',), rows='focal', caption=None, label=None, float_format='.4f', booktabs=True, position='htbp')[source]
Export this mass function as a LaTeX table string.
- Parameters:
columns (Sequence[str]) – Any of
mass,belief,plausibility, orcommonality. Short aliasesm,bel,pl, andqare accepted.rows (str) –
"focal"for stored non-zero masses, or"all"for every proposition generated by the frame."all"can be large for DSmT frames.caption (str | None) – Optional LaTeX table metadata.
label (str | None) – Optional LaTeX table metadata.
float_format (str | None) – Python format specifier such as
".4f". Percent-style formats such as"%0.4f"are also accepted.booktabs (bool) – Use
toprule/midrule/bottomruleinstead ofhline.position (str) – LaTeX table position specifier.
- Return type:
- yager(*others, model=None)[source]
Yager’s rule: transfer total conflict to total ignorance.
- Parameters:
others (MassFunction)
model (Frame | None)
- Return type:
Proposition
- class evidencelib.Proposition(frame, regions)[source]
A canonical proposition represented by possible Venn regions.
Users normally create propositions through a
evidencelib.Frameand combine them with|for union and&for intersection.- intersects(other)[source]
Return whether two propositions share at least one model region.
- Parameters:
other (Proposition)
- Return type:
Plotting
Matplotlib-based visualizations for belief mass functions.
- evidencelib.plotting.plot_belief_plausibility(mass, *, hypotheses=None, ax=None, title=None, show_pignistic=True, show_decision=True, sort_by='pignistic', annotate_intervals=False, interval_color='#1F77B4', decision_color='#1F77B4', pignistic_color='#FF7F0E', show_legend=True)[source]
Draw belief-plausibility intervals for singleton hypotheses.
The interval for each hypothesis starts at belief and ends at plausibility. When enabled, pignistic scores are drawn as point markers.
- Parameters:
interval_color (str) – Matplotlib colors for support intervals, selected-decision interval, and pignistic markers.
decision_color (str) – Matplotlib colors for support intervals, selected-decision interval, and pignistic markers.
pignistic_color (str) – Matplotlib colors for support intervals, selected-decision interval, and pignistic markers.
show_legend (bool) – Display the compact explanation legend.
mass (MassFunction)
hypotheses (Sequence[str | Proposition | Iterable[str]] | None)
ax (Any)
title (str | None)
show_pignistic (bool)
show_decision (bool)
sort_by (SortBy)
annotate_intervals (bool)
- Return type:
Any
- evidencelib.plotting.plot_mass(mass, *, ax=None, title=None, sort=True, top_n=None, min_mass=None, show_other=True, colors=None, show_kind_legend=False, annotate=True)[source]
Draw a horizontal bar plot for one mass assignment.
- Parameters:
mass (MassFunction) – Mass function to visualize.
ax (Any) – Optional matplotlib axes. If omitted, a new figure and axes are created.
title (str | None) – Optional custom title.
sort (bool) – Sort focal propositions by descending mass.
top_n (int | None) – Keep only the largest
top_nvisible propositions.min_mass (float | None) – Hide propositions below this direct mass threshold.
show_other (bool) – Aggregate hidden propositions into an
Other propositionsbar.colors (ColorSpec) – Optional color override. Pass a single matplotlib color for all bars, a sequence to cycle through bars, or a mapping keyed by proposition kind (
singleton,union,compound,empty,total,other) or displayed label. By default all regular bars use one color, and the aggregatedotherbar is muted.show_kind_legend (bool) – Display a legend for proposition kinds. Disabled by default to keep plots compact.
annotate (bool) – Draw numeric mass labels at the end of bars.
- Returns:
Axes containing the plot.
- Return type:
matplotlib.axes.Axes
- evidencelib.plotting.plot_mass_comparison(masses, *, labels=None, ax=None, title=None, sort=True, top_n=None, min_total_mass=None, annotate=True, vmax=None, cmap=None, colorbar=True, annotation_text_colors=('#222222', '#FFFFFF'), annotation_threshold=0.45)[source]
Draw a heatmap comparing mass assignments across sources.
Rows represent mass functions, columns represent propositions that appear in at least one source, and cell values are assigned masses.
- Parameters:
cmap (Any) – Optional matplotlib colormap name/object or a sequence of colors used to build a linear colormap.
colorbar (bool) – Draw the assigned-mass colorbar.
annotation_text_colors (Sequence[str]) – Pair of matplotlib colors used for annotated values on light and dark heatmap cells.
annotation_threshold (float) – Normalized cell intensity, from 0 to 1, where annotations switch from the first text color to the second text color.
masses (Sequence[MassFunction])
labels (Sequence[str] | None)
ax (Any)
title (str | None)
sort (bool)
top_n (int | None)
min_total_mass (float | None)
annotate (bool)
vmax (float | None)
- Return type:
Any
- evidencelib.plotting.plot_pignistic_decision(mass, *, ax=None, title=None, top_n=None, colors=None, highlight_decision=True, decision_color='#1F77B4', annotate=True, show_legend=False)[source]
Draw a horizontal ranking of pignistic decision scores.
- Parameters:
colors (ColorSpec) – Optional color override. Pass a single matplotlib color for all bars, a sequence to cycle through bars, or a mapping keyed by hypothesis label,
decision,hypothesis, ordefault.highlight_decision (bool) – Emphasize the top pignistic score. Disable for a neutral ranking plot.
decision_color (str) – Matplotlib color for the selected decision when highlighting is active.
annotate (bool) – Draw numeric pignistic scores at the end of bars.
show_legend (bool) – Display a legend for the decision highlight.
mass (MassFunction)
ax (Any)
title (str | None)
top_n (int | None)
- Return type:
Any
- evidencelib.plotting.plot_venn(mass, *, ax=None, title=None, labels=None, values='pignistic', colors=None, alpha=0.32, annotate=True, show_zero_values=True, show_region_labels=False, value_formatter=None)[source]
Draw a compact Venn-style diagram for one to three hypotheses.
The diagram labels disjoint model regions, so it is most useful for DSmT and hybrid DSm frames where overlaps are meaningful. By default, region values come from the pignistic transformation over Venn regions. Pass
values="mass"to show only direct mass assigned to each elementary region.- Parameters:
labels (Sequence[str] | None) – Optional display labels for the frame atoms.
values (VennValues) –
"pignistic"for distributed pignistic region probabilities, or"mass"for direct mass assigned to elementary Venn regions.colors (ColorSpec) – Optional circle color override. Pass a single Matplotlib color, a sequence cycled across circles, or a mapping keyed by atom label.
alpha (float) – Circle fill opacity.
annotate (bool) – Draw region values inside the diagram.
show_zero_values (bool) – Display zero-valued possible regions as
0.00. Disable to hide them.show_region_labels (bool) – Include the region name above each numeric value.
value_formatter (Callable[[float], str] | None) – Optional callable used to format region values.
mass (MassFunction)
ax (Any)
title (str | None)
- Return type:
Any
Exceptions
Package-specific exceptions.