torchtsetlin.viz¶
torchtsetlin.viz ¶
Visualisation helpers (matplotlib is an optional dependency).
Every function returns the matplotlib Axes it drew on, so figures can be composed.
plot_history ¶
Plot metric curves of a :class:~torchtsetlin.train.History.
Source code in src/torchtsetlin/viz.py
plot_confusion_matrix ¶
plot_confusion_matrix(cm, class_names: Optional[Sequence[str]] = None, normalize: bool = False, ax=None, cmap='Blues')
Heat-map of a confusion matrix (rows = true, columns = predicted).
Source code in src/torchtsetlin/viz.py
plot_clause_memory ¶
Book-style memory plot of one clause: the automaton state of every literal with the include boundary drawn as a dashed line (states above it are memorized).
Source code in src/torchtsetlin/viz.py
plot_ta_states ¶
Heat-map of all automata states (clauses x literals), centred on the include boundary.
Source code in src/torchtsetlin/viz.py
plot_literal_frequency ¶
plot_literal_frequency(model, feature_names: Optional[Sequence[str]] = None, top_k: Optional[int] = 30, ax=None)
Bar plot of how many clauses include each literal.
Source code in src/torchtsetlin/viz.py
plot_feature_importance ¶
plot_feature_importance(importance, names: Optional[Sequence[str]] = None, top_k: Optional[int] = 20, ax=None, title: str = 'feature importance')
Horizontal bar plot of a (n,) importance vector.
Source code in src/torchtsetlin/viz.py
plot_conv_clause ¶
plot_conv_clause(model, clause: int, plane: int = 0, ax=None, show_region: bool = True, depth: Optional[int] = None)
Draw the patch pattern of a convolutional clause: black = pixel must be on, white = must be off, gray = don't care. The title reports the allowed patch-position range.
For 3D models (:class:~torchtsetlin.models.Conv3dTsetlinMachine) the kd depth
slices of the window are drawn side by side, separated by a blank column; pass
depth to draw a single slice instead.
Source code in src/torchtsetlin/viz.py
plot_conv_clauses ¶
plot_conv_clauses(model, clauses: Sequence[int], ncols: int = 8, plane: int = 0, figsize_per: float = 1.6, depth: Optional[int] = None)
Grid of :func:plot_conv_clause panels. Returns the figure.
For 3D models each panel shows the kd depth slices side by side (or only depth).
Source code in src/torchtsetlin/viz.py
plot_votes ¶
Histogram of the winning-class vote sums, split by correct / incorrect if y given.
Source code in src/torchtsetlin/viz.py
plot_trustworthiness ¶
Plot accuracy vs confidence level (see :func:torchtsetlin.metrics.trustworthiness_curve).
Source code in src/torchtsetlin/viz.py
plot_clause_weights ¶
Weights of a weighted / coalesced model as an image (clauses x outputs) or bars.
Source code in src/torchtsetlin/viz.py
segmentation_palette ¶
(n, 3) float RGB palette for label maps, indexable by class id.
Uses matplotlib's qualitative tab10/tab20 so neighbouring classes stay
distinguishable, and paints ignore_index mid-grey. Index it with a label map:
palette[labels] gives an (H, W, 3) image.
Source code in src/torchtsetlin/viz.py
plot_segmentation ¶
plot_segmentation(image=None, target=None, pred=None, palette=None, class_names: Optional[Sequence[str]] = None, n_classes: Optional[int] = None, ignore_index: Optional[int] = None, titles: Optional[Sequence[str]] = None, figsize_per: float = 3.0)
Row of panels for one example: input image, ground truth, prediction and the error map.
Any of image / target / pred may be omitted. image may be a (3, H, W)
or (H, W) array (floats in [0, 1] or ints in [0, 255]); target and
pred are (H, W) label maps. When both are given a fourth panel marks the
mispredicted pixels, which is usually where the interesting failures are.
Returns the figure.
Source code in src/torchtsetlin/viz.py
plot_vote_map ¶
plot_vote_map(votes, class_index: int = 0, class_name: Optional[str] = None, ax=None, cmap='RdBu_r')
Heat map of one class's per-pixel vote sums (K, H, W) or (B, K, H, W).
Vote sums are the model's confidence surface: a class boundary sits where the winning margin collapses, so this shows where a label map is decided and where it is a coin flip.