Plotting credal sets on the simplex

The plot_credal_set() function visualises 3-class credal sets on a ternary simplex. It automatically picks the right renderer for each credal set type:

Each batch element is drawn in a distinct colour so that multiple sets can be compared on one plot.

Singleton credal set

The simplest case: each instance is a single probability distribution.

singleton = create_singleton_credal_set(
    np.array([[0.5, 0.3, 0.2], [0.2, 0.5, 0.3], [0.1, 0.2, 0.7]]),
)
plot_credal_set(singleton, title="Singleton")
plt.show()
Singleton

Probability intervals

Each class has independent lower and upper probability bounds. The feasible region on the simplex is the set of all distributions that respect every bound.

lower_bounds = np.array([[0.1, 0.2, 0.3], [0.3, 0.1, 0.1]])
upper_bounds = np.array([[0.4, 0.5, 0.6], [0.6, 0.3, 0.7]])
intervals = create_probability_intervals_from_lower_upper_array(
    np.concatenate([lower_bounds, upper_bounds], axis=-1),
)
plot_credal_set(intervals, title="Probability Intervals")
plt.show()
Probability Intervals

Distance-based credal set

Defined by a nominal distribution and a radius (total-variation distance). The filled polygon shows all distributions within that distance; the marker highlights the nominal.

distance_based = create_distance_based_credal_set_from_center_and_radius(
    create_categorical_distribution(np.array([[0.5, 0.3, 0.2], [0.2, 0.6, 0.2]])),
    np.array([0.1, 0.1]),
)
plot_credal_set(distance_based, title="Distance-Based")
plt.show()
Distance-Based

Convex credal set

Given explicitly as a set of vertex distributions. The convex hull is drawn as a filled polygon with markers at each vertex.

# Each vertex is given for both instances.
vertices = [
    create_categorical_distribution(np.array([[0.7, 0.2, 0.1], [0.5, 0.4, 0.1]])),
    create_categorical_distribution(np.array([[0.1, 0.7, 0.2], [0.3, 0.3, 0.4]])),
    create_categorical_distribution(np.array([[0.1, 0.1, 0.8], [0.4, 0.2, 0.4]])),
]
convex = create_convex_credal_set(create_sample(vertices, sample_axis=0))
plot_credal_set(convex, title="Convex")
plt.show()
Convex

Discrete credal set

Identical representation to the convex case but semantically represents a finite set of distributions rather than their convex hull.

# Each member is given for both instances.
members = [
    create_categorical_distribution(np.array([[0.6, 0.3, 0.1], [0.4, 0.4, 0.2]])),
    create_categorical_distribution(np.array([[0.2, 0.5, 0.3], [0.3, 0.2, 0.5]])),
]
discrete = create_discrete_credal_set(create_sample(members, sample_axis=0))
plot_credal_set(discrete, title="Discrete")
plt.show()
Discrete

Custom configuration

Pass a PlotConfig to adjust colours, line widths, or other styling parameters.

config = PlotConfig(fill_alpha=0.5, line_width=2.5, marker_size=60)
plot_credal_set(convex, title="Custom styling", config=config)
plt.show()
Custom styling

Total running time of the script: (0 minutes 1.851 seconds)

Gallery generated by Sphinx-Gallery