boofun.visualization

Visualization module for Boolean function analysis.

This module provides comprehensive plotting and visualization tools for Boolean functions, including influence plots, Fourier spectrum visualization, and interactive analysis tools.

Functions

plot_function_comparison(functions[, ...])

Compare multiple Boolean functions side by side.

plot_hypercube(f[, figsize, save_path, show])

Plot Boolean function on a hypercube graph (n ≤ 5).

plot_sensitivity_heatmap(f[, figsize, ...])

Plot sensitivity at each input as a heatmap.

Classes

BooleanFunctionVisualizer(function[, backend])

Comprehensive visualization toolkit for Boolean functions.

class boofun.visualization.BooleanFunctionVisualizer(function: BooleanFunction, backend: str = 'matplotlib')[source]

Comprehensive visualization toolkit for Boolean functions.

Provides static and interactive plots for Boolean function analysis, including influences, Fourier spectra, truth tables, and more.

__init__(function: BooleanFunction, backend: str = 'matplotlib')[source]

Initialize visualizer.

Parameters:
  • function – Boolean function to visualize

  • backend – Plotting backend (“matplotlib”, “plotly”)

plot_influences(figsize: Tuple[int, int] = (10, 6), save_path: str | None = None, show: bool = True) Any[source]

Plot variable influences.

Parameters:
  • figsize – Figure size for matplotlib

  • save_path – Path to save the plot

  • show – Whether to display the plot

Returns:

Figure object

plot_fourier_spectrum(max_degree: int | None = None, figsize: Tuple[int, int] = (12, 8), save_path: str | None = None, show: bool = True) Any[source]

Plot Fourier spectrum grouped by degree.

Parameters:
  • max_degree – Maximum degree to plot (None for all)

  • figsize – Figure size for matplotlib

  • save_path – Path to save the plot

  • show – Whether to display the plot

Returns:

Figure object

plot_truth_table(figsize: Tuple[int, int] = (10, 8), save_path: str | None = None, show: bool = True) Any[source]

Plot truth table as a heatmap.

Parameters:
  • figsize – Figure size for matplotlib

  • save_path – Path to save the plot

  • show – Whether to display the plot

Returns:

Figure object

plot_noise_stability_curve(rho_range: ndarray | None = None, figsize: Tuple[int, int] = (10, 6), save_path: str | None = None, show: bool = True) Any[source]

Plot noise stability as a function of correlation ρ.

Parameters:
  • rho_range – Range of ρ values to plot

  • figsize – Figure size for matplotlib

  • save_path – Path to save the plot

  • show – Whether to display the plot

Returns:

Figure object

create_dashboard(save_path: str | None = None, show: bool = True) Any[source]

Create comprehensive analysis dashboard.

Parameters:
  • save_path – Path to save the dashboard

  • show – Whether to display the dashboard

Returns:

Dashboard figure

boofun.visualization.plot_function_comparison(functions: Dict[str, BooleanFunction], metric: str = 'influences', backend: str = 'matplotlib', **kwargs) Any[source]

Compare multiple Boolean functions side by side.

Parameters:
  • functions – Dictionary mapping names to BooleanFunction objects

  • metric – Metric to compare (“influences”, “fourier”, “noise_stability”)

  • backend – Plotting backend

  • **kwargs – Additional plotting arguments

Returns:

Comparison plot

boofun.visualization.plot_hypercube(f: BooleanFunction, figsize: Tuple[int, int] = (10, 10), save_path: str | None = None, show: bool = True) Any[source]

Plot Boolean function on a hypercube graph (n ≤ 5).

Shows the hypercube with vertices colored by function output. Edges connect inputs differing in one bit.

Parameters:
  • f – Boolean function (n ≤ 5)

  • figsize – Figure size

  • save_path – Optional path to save

  • show – Whether to display

Returns:

Figure object

boofun.visualization.plot_sensitivity_heatmap(f: BooleanFunction, figsize: Tuple[int, int] = (10, 8), save_path: str | None = None, show: bool = True) Any[source]

Plot sensitivity at each input as a heatmap.

Parameters:
  • f – Boolean function (n ≤ 8 recommended)

  • figsize – Figure size

  • save_path – Optional path to save

  • show – Whether to display

Returns:

Figure object

class boofun.visualization.GrowthVisualizer(backend: str = 'matplotlib')[source]

Specialized visualizer for asymptotic behavior of Boolean function families.

Features: - Plot properties vs n with theoretical overlays - Compare multiple families - Visualize convergence rates - Show phase transitions

__init__(backend: str = 'matplotlib')[source]

Initialize growth visualizer.

Parameters:

backend – “matplotlib” or “plotly”

plot_growth(tracker: GrowthTracker, marker_name: str, show_theory: bool = True, show_error: bool = True, log_x: bool = False, log_y: bool = False, figsize: Tuple[int, int] = (10, 6), title: str | None = None, ax=None, **kwargs)[source]

Plot a single tracked property vs n.

Parameters:
  • tracker – GrowthTracker with computed results

  • marker_name – Which marker to plot

  • show_theory – Show theoretical prediction

  • show_error – Show error bars/ribbon (if available)

  • log_x – Use log scale

  • log_y – Use log scale

  • figsize – Figure size

  • title – Custom title

  • ax – Matplotlib axes (optional)

Returns:

Figure/axes

plot_family_comparison(trackers: Dict[str, GrowthTracker], marker_name: str, show_theory: bool = True, log_x: bool = False, log_y: bool = False, figsize: Tuple[int, int] = (12, 6), title: str | None = None)[source]

Compare a property across multiple function families.

Parameters:
  • trackers – Dict mapping family names to GrowthTrackers

  • marker_name – Property to compare

  • show_theory – Show theoretical predictions

  • log_x – Use log scale

  • log_y – Use log scale

  • figsize – Figure size

  • title – Custom title

Returns:

Figure

plot_convergence_rate(tracker: GrowthTracker, marker_name: str, reference: str = 'sqrt_n', figsize: Tuple[int, int] = (10, 6))[source]

Plot ratio of computed value to theoretical reference.

Useful for seeing convergence rates and constant factors.

Parameters:
  • tracker – GrowthTracker with results

  • marker_name – Property to analyze

  • reference – Reference function (“sqrt_n”, “n”, “log_n”, “constant”)

  • figsize – Figure size

Returns:

Figure

plot_multi_property_growth(tracker: GrowthTracker, marker_names: List[str] | None = None, figsize: Tuple[int, int] = (14, 4))[source]

Plot multiple properties side by side.

Parameters:
  • tracker – GrowthTracker with results

  • marker_names – Which markers to plot (None = all)

  • figsize – Figure size (per subplot)

Returns:

Figure

class boofun.visualization.LTFVisualizer(backend: str = 'matplotlib')[source]

Specialized visualizations for Linear Threshold Functions.

__init__(backend: str = 'matplotlib')[source]
plot_weight_distribution(weights: ndarray, figsize: Tuple[int, int] = (10, 6), title: str | None = None)[source]

Plot weight distribution of an LTF.

Parameters:
  • weights – LTF weight vector

  • figsize – Figure size

  • title – Custom title

Returns:

Figure

plot_influence_vs_weight(f: BooleanFunction, figsize: Tuple[int, int] = (8, 8))[source]

Scatter plot comparing |weight| vs influence.

Parameters:
  • f – Boolean function (should be LTF)

  • figsize – Figure size

Returns:

Figure

class boofun.visualization.ComplexityVisualizer(backend: str = 'matplotlib')[source]

Visualize query complexity measures and their relationships.

__init__(backend: str = 'matplotlib')[source]
plot_complexity_relations(f: BooleanFunction, figsize: Tuple[int, int] = (12, 5))[source]

Plot relationships between different complexity measures.

Shows s(f), bs(f), deg(f), C(f) and their bounds.

Parameters:
  • f – Boolean function

  • figsize – Figure size

Returns:

Figure

boofun.visualization.quick_growth_plot(family_name: str, properties: List[str] = ['total_influence', 'noise_stability'], n_values: List[int] | None = None, **kwargs)[source]

Quick way to visualize asymptotic behavior of a built-in family.

Parameters:
  • family_name – “majority”, “parity”, “tribes”, “and”, “or”, “dictator”

  • properties – Which properties to track

  • n_values – List of n values (default: odd 3-15)

Returns:

Figure

class boofun.visualization.DecisionTreeNode(is_leaf: bool = False, value: int | None = None, variable: int | None = None, left: DecisionTreeNode | None = None, right: DecisionTreeNode | None = None, depth: int = 0)[source]

Node in a decision tree for a Boolean function.

Can be either: - Internal node: queries a variable, has left (0) and right (1) children - Leaf node: outputs a constant value (0 or 1)

__init__(is_leaf: bool = False, value: int | None = None, variable: int | None = None, left: DecisionTreeNode | None = None, right: DecisionTreeNode | None = None, depth: int = 0)[source]

Create a decision tree node.

Parameters:
  • is_leaf – True if this is a leaf node

  • value – Output value for leaf nodes (0 or 1)

  • variable – Variable index to query for internal nodes

  • left – Child for variable=0

  • right – Child for variable=1

  • depth – Depth of this node in the tree

evaluate(x: int) int[source]

Evaluate the decision tree on input x.

boofun.visualization.build_optimal_decision_tree(f: BooleanFunction, available_vars: List[int] | None = None, inputs: List[int] | None = None, depth: int = 0, max_depth: int = 20) DecisionTreeNode[source]

Build an optimal (or near-optimal) decision tree for f.

Uses a greedy algorithm based on influence to select variables.

Parameters:
  • f – BooleanFunction to build tree for

  • available_vars – Variables not yet queried (None = all)

  • inputs – Current set of inputs to distinguish (None = all)

  • depth – Current depth in the tree

  • max_depth – Maximum allowed depth

Returns:

Root of the decision tree

boofun.visualization.plot_decision_tree(f: BooleanFunction, tree: DecisionTreeNode | None = None, figsize: Tuple[int, int] = (12, 8), save_path: str | None = None, show: bool = True, node_size: int = 2000, font_size: int = 10) Any[source]

Plot a decision tree for a Boolean function.

Parameters:
  • f – BooleanFunction (used to build tree if not provided)

  • tree – Pre-built decision tree (None to build optimal)

  • figsize – Figure size

  • save_path – Path to save the plot

  • show – Whether to display

  • node_size – Size of tree nodes

  • font_size – Font size for labels

Returns:

Figure object

boofun.visualization.decision_tree_to_dict(node: DecisionTreeNode) Dict[str, Any][source]

Convert decision tree to dictionary for serialization.

class boofun.visualization.InteractiveFunctionExplorer(f: BooleanFunction)[source]

Interactive widget for exploring a single Boolean function.

Features: - View truth table - View Fourier coefficients - View influences - Noise stability curve

__init__(f: BooleanFunction)[source]

Create explorer for a Boolean function.

Parameters:

f – Boolean function to explore

display()[source]

Show the interactive widget.

class boofun.visualization.GrowthExplorer(family_func: Callable[[int], 'BooleanFunction'], name: str = 'Function', n_range: tuple = (1, 12))[source]

Interactive widget for exploring how functions grow with n.

Features: - Slider to change n - Real-time plots of properties - Compare with theoretical bounds

__init__(family_func: Callable[[int], 'BooleanFunction'], name: str = 'Function', n_range: tuple = (1, 12))[source]

Create growth explorer.

Parameters:
  • family_func – Function that takes n and returns BooleanFunction

  • name – Name of the function family

  • n_range – (min_n, max_n) range for slider

display()[source]

Show the interactive widget.

class boofun.visualization.PropertyDashboard(functions: Dict[str, 'BooleanFunction'])[source]

Dashboard comparing multiple functions side by side.

__init__(functions: Dict[str, 'BooleanFunction'])[source]

Create dashboard for multiple functions.

Parameters:

functions – Dict mapping names to BooleanFunction objects

display()[source]

Show the dashboard.

boofun.visualization.create_function_explorer(f: BooleanFunction) InteractiveFunctionExplorer[source]

Convenience function to create and display a function explorer.

Parameters:

f – Boolean function to explore

Returns:

InteractiveFunctionExplorer instance

boofun.visualization.create_growth_explorer(family_func: Callable[[int], 'BooleanFunction'], name: str = 'Function', n_range: tuple = (1, 12)) GrowthExplorer[source]

Convenience function to create and display a growth explorer.

Parameters:
  • family_func – Function that takes n and returns BooleanFunction

  • name – Name of the function family

  • n_range – (min_n, max_n) range

Returns:

GrowthExplorer instance

class boofun.visualization.GrowthAnimator(family: FunctionFamily)[source]

Create animations showing function properties as n grows.

Example

>>> animator = GrowthAnimator(MajorityFamily())
>>> animator.animate("total_influence", n_range=(3, 15, 2))
>>> animator.save("majority_growth.gif")
__init__(family: FunctionFamily)[source]

Initialize animator with a function family.

Parameters:

family – BooleanFamily to animate

animate(property_name: str, n_range: Tuple[int, int, int] = (3, 15, 2), figsize: Tuple[int, int] = (10, 6), interval: int = 500, property_func: Callable | None = None) animation.FuncAnimation[source]

Create animation of property growth.

Parameters:
  • property_name – Name of property to animate

  • n_range – (start, stop, step) for n values

  • figsize – Figure size

  • interval – Milliseconds between frames

  • property_func – Custom function to compute property (default uses builtin)

Returns:

Matplotlib animation object

animate_influences(n_range: Tuple[int, int, int] = (3, 15, 2), figsize: Tuple[int, int] = (12, 6), interval: int = 700) animation.FuncAnimation[source]

Animate influence distribution as n grows.

Shows bar chart of influences with bars growing/shrinking.

Parameters:
  • n_range – (start, stop, step) for n values

  • figsize – Figure size

  • interval – Milliseconds between frames

Returns:

Matplotlib animation object

save(filename: str, fps: int = 2, **kwargs)[source]

Save animation to file.

Parameters:
  • filename – Output filename (supports .gif, .mp4)

  • fps – Frames per second

  • **kwargs – Additional arguments to animation.save()

show()[source]

Display the animation.

boofun.visualization.animate_growth(family: FunctionFamily, property_name: str = 'total_influence', n_range: Tuple[int, int, int] = (3, 15, 2), **kwargs) animation.FuncAnimation[source]

Convenience function to create a growth animation.

Parameters:
  • family – BooleanFamily to animate

  • property_name – Property to track

  • n_range – (start, stop, step) for n values

  • **kwargs – Additional arguments to GrowthAnimator.animate()

Returns:

Matplotlib animation object

boofun.visualization.animate_influences(family: FunctionFamily, n_range: Tuple[int, int, int] = (3, 15, 2), **kwargs) animation.FuncAnimation[source]

Convenience function to animate influence distribution.

Parameters:
  • family – BooleanFamily to animate

  • n_range – (start, stop, step) for n values

  • **kwargs – Additional arguments

Returns:

Matplotlib animation object

boofun.visualization.animate_fourier_spectrum(family: FunctionFamily, n_range: Tuple[int, int, int] = (3, 9, 2), figsize: Tuple[int, int] = (12, 6), interval: int = 800) animation.FuncAnimation[source]

Animate Fourier spectrum (spectral weight by degree) as n grows.

Parameters:
  • family – BooleanFamily to animate

  • n_range – (start, stop, step) for n values

  • figsize – Figure size

  • interval – Milliseconds between frames

Returns:

Matplotlib animation object

boofun.visualization.create_growth_animation(family: FunctionFamily, properties: List[str] = None, n_range: Tuple[int, int, int] = (3, 15, 2), figsize: Tuple[int, int] = (14, 8), interval: int = 600) animation.FuncAnimation[source]

Create multi-panel animation showing multiple properties.

Parameters:
  • family – BooleanFamily to animate

  • properties – List of properties to show (default: influence, degree, variance)

  • n_range – (start, stop, step) for n values

  • figsize – Figure size

  • interval – Milliseconds between frames

Returns:

Matplotlib animation object

Modules

animation

Animation utilities for Boolean function visualization.

decision_tree

Decision tree visualization for Boolean functions.

decision_tree_export

Decision Tree Export Utilities.

growth_plots

Growth and asymptotic visualization for Boolean function families.

interactive

Interactive visualizations using Plotly.

latex_export

LaTeX/TikZ Export for Boolean Function Visualizations.

widgets

Interactive Jupyter widgets for Boolean function exploration.