briann.GUI package

Submodules

briann.GUI.model_explorer module

class briann.GUI.model_explorer.Animator(*args: Any, **kwargs: Any)[source]

Bases: CTk

This class can be used to animate BrIANN’s. The animator displays a graph for the different Area’s and Connections’s. The layout of the graph can be adjusted with mouse-clicks inside the animator. It is also possible to add visualisations for area states by right-clicking the areas. When stepping through the simulation, the animator indicates with a color-code which area is currently processing its inputs and updates to their states are displayed in the corresponding visualizers.

Parameters:
  • briann (BrIANN) – The briann instance to be animated.

  • data_iterator (Iterator) – An iterator that provides the data (X, y (ignored)) to be streamed to the briann model during the simulation.

_on_window_close() None[source]

Ensures the animator closes all visualizations properly before quitting the app. :rtype: None

property briann
Returns:

The briann instance that is being animated.

Return type:

Animator

on_current_simulation_time_update(obj, name, value) None[source]
class briann.GUI.model_explorer.Area(bpnc_area: Area, canvas: Canvas, briann: BrIANN, x: float, y: float, size: float)[source]

Bases: DraggableWidget

A visual representation of a BrIANN that can be placed onto the Canvas. It is represented by a button that can be moved around. The button changes color to indicate whether the corresponding BrIANN area is currently being updated. When right-clicking the button, an option menu unfolds that allows to add a visualizer for the state of the area.

Parameters:
  • bpnc_area (Area) – The BrIANN area to be visualized.

  • canvas (Canvas) – The canvas on which the area shall be visualized.

  • briann (BrIANN) – The BrIANN that is being simulated.

  • x (float, optional, defaults to 0) – The x-coordinate of the visualizer’s center in Cartesian space (inches).

  • y (float, optional, defaults to 0) – The y-coordinate of the visualizer’s center in Cartesian space (inches).

_add_state_visualizer(option: str, popup: customtkinter.CTkToplevel) None[source]

Maps the user’s selection for the preferred AreaStateVisualizer to the actual visualizer to be displayed on screen.

Parameters:
  • option (str) – The name of the chosen visualizer. Options are [“Line Chart”].

  • popup (customtkinter.CTkTopLevel) – The pop-up that allowed the users to make a choice. This pop-up will be deleted by the current method.

Return type:

None

_on_right_click(event: tkinter.Event) None[source]

Displays a pop-up window that allow to choose a AreaStateVisualizer.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

on_current_simulation_time_update(obj, name, value) None[source]
on_update_count_update(obj, name, value) None[source]
property size: float
Returns:

The size of this area in inches.

Return type:

float

property state_visualizers: List[AreaStateVisualizer]
Returns:

The list of state visualizers that are currently attached to this area.

Return type:

List[AreaStateVisualizer]

class briann.GUI.model_explorer.AreaStateVisualizer(area: Area, canvas: Canvas, current_simulation_time: float, initial_x: float, initial_y: float, width: float, height: float)[source]

Bases: DraggableWidget

Superclass for a set of classes that create 2D visualizations of a state() on a 1x1 unit square

_update_plot(time_frame: TimeFrame = None) None[source]
on_forward_call(caller) None[source]
on_reset_call(caller) None[source]
class briann.GUI.model_explorer.Canvas(*args: Any, **kwargs: Any)[source]

Bases: Canvas

This class creates a canvas on which network components will be displayed. The canvas can be dragged around and has a reference grid in the background.

_on_drag_motion(event: tkinter.Event) None[source]

Performs a step of the drag operation.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

_on_drag_start(event: tkinter.Event) None[source]

Prepares the drag operation

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

static canvas_to_cartesian(x: int, y: int) Tuple[float, float][source]

Converts from this canvas’s coordinate system to a cartesian coordinate system. - The cartesian coordinate system has its origin in the center of the canvas, with the x-axis pointing to the right and the y-axis pointing upwards and its units are inches. - The canvas coordinate system has its origin in the top left corner of the canvas, with the x-axis pointing to the right and the y-axis pointing downwards and its units are pixels.

Parameters:
  • x (int) – The x-coordinate in canvas coordinates.

  • y (int) – The y-coordinate in canvas coordinates.

Returns:

The x and y coordinates in cartesian space.

Return type:

Tuple[float, float]

static cartesian_to_canvas(x: float, y: float) Tuple[int, int][source]

Converts from a cartesian coordinate system to this canvas’s coordinate system. - The cartesian coordinate system has its origin in the center of the canvas, with the x-axis pointing to the right and the y-axis pointing upwards and its units are inches. - The canvas coordinate system has its origin in the top left corner of the canvas, with the x-axis pointing to the right and the y-axis pointing downwards and its units are pixels.

Parameters:
  • x (float) – The x-coordinate in cartesian coordinates.

  • y (float) – The y-coordinate in cartesian coordinates.

Returns:

The x and y coordinates in canvas space.

Return type:

Tuple[int, int]

center_scroll_region(event: tkinter.Event) None[source]

Centers the scroll region of the canvas.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

create_reference_grid(x_min: float, x_max: float, y_min: float, y_max: float, spacing: float = 1.0, color: str = 'lightgray') None[source]

Creates a reference grid on the canvas with the given parameters.

Parameters:
  • x_min (float) – The minimum x-coordinate of the grid in cartesian space (inches).

  • x_max (float) – The maximum x-coordinate of the grid in cartesian space (inches).

  • y_min (float) – The minimum y-coordinate of the grid in cartesian space (inches).

  • y_max (float) – The maximum y-coordinate of the grid in cartesian space (inches).

  • spacing (float) – The spacing between the grid lines in cartesian space (inches).

  • color (str) – The color of the grid lines.

Return type:

None

class briann.GUI.model_explorer.Connection(from_area: Area, to_area: Area, canvas: Canvas, width: int = 2, bend_by: float = 0.0)[source]

Bases: LocationSubscriber

A visual representation of a Connection. The connection is automatically redraws itself when the area is repositioned.

Parameters:
  • from_area (Area) – The area from which the connection starts.

  • to_area (Area) – The area at which the connection ends.

  • width (int, optional, default to 2.) – The thickness of the line representing this connection on screen.

  • bend_by (float, optional, defaults to 0.0.) – The extend by which the connection should be bent (in inches) relative to the mid-point between the from_area and the to_area.

Canvas:

The canvas on which the connection shall be drawn.

_abc_impl = <_abc._abc_data object>
draw() None[source]

Draws self on the canvas as two segments. The first segment goes from the from-area to the mid-point with an arrow-head. The second segment goes from the mid-point to the to-area.

Return type:

None

on_location_update(draggable_widget: DraggableWidget) None[source]

This method will be called every time the DraggableWidget’s x() or y() are updated.

Parameters:

draggable_widget (DraggableWidget) – The draggable widget that was updated.

Return type:

None

class briann.GUI.model_explorer.ControllerFrame(*args: Any, **kwargs: Any)[source]

Bases: CTkFrame

A frame that holds the different buttons used to control the animation.

Parameters:
  • briann (BrIANN) – The briann instance for which the animation shall be controlled.

  • network_visualizer (NetworkVisualizer) – The visualizer that displays the current state of briann.

_on_pause_button_click() None[source]

Halts the animation, in case it is currently running. :rtype: None

_on_play_button_click() None[source]

Starts a loop that steps through the animation until stopped via _on_pause_button_click(). :rtype: None

_play() None[source]

Steps through the animation for as long as _is_playing is True. :rtype: None

on_next_stimulus_button_click() None[source]

Loads the next stimulus into the BrIANN model. :rtype: None

on_next_time_frame_button_click() None[source]

Loads the next TimeFrame into the BrIANN model. :rtype: None

class briann.GUI.model_explorer.DraggableWidget(canvas: Canvas, widget: tkinter.Widget, x: float = 0, y: float = 0)[source]

Bases: object

Creates a visualizer that visualizes data in a rectangle whose center is at (x,`y`). The visualizer will be drawn on top of all previously drawn elements on the canvas and it can be dragged around with the mouse.

Parameters:
  • canvas (Canvas) – The canvas to draw the visualizer on.

  • widget (py:class:tkinter.Widget) – The widget to be placed on the canvas.

  • x (float, optional, defaults to 0) – The x-coordinate of the visualizer’s center in Cartesian space (inches).

  • y (float, optional, defaults to 0) – The y-coordinate of the visualizer’s center in Cartesian space (inches).

class LocationSubscriber[source]

Bases: ABC

An abstract base class for subscribers that want to receive the location of a DraggableWidget every time it is updated. Subscribers must implement the on_location_update() method.

_abc_impl = <_abc._abc_data object>
abstractmethod on_location_update(draggable_widget: DraggableWidget) None[source]

This method will be called every time the DraggableWidget’s x() or y() are updated.

Parameters:

draggable_widget (DraggableWidget) – The draggable widget that was updated.

Return type:

None

_on_drag_end(event: tkinter.Event) None[source]

Ends a drag operation.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

_on_drag_motion(event: tkinter.Event) None[source]

Begins a drag operation.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

_on_drag_start(event: tkinter.Event) None[source]

Begins a drag operation.

Parameters:

event (tkinter.Event) – The event that triggered the function call.

Return type:

None

add_location_subscriber(subscriber: LocationSubscriber) None[source]

Adds a subscriber that will be notified once the location of this DraggableWidget changes.

Parameters:

subscriber (LocationSubscriber) – The subscriber to be added to the subscription list.

Return type:

None

property x: float
Returns:

The x-position of the center of self in cartesian space (inches).

Return type:

float

property y: float
Returns:

The y-position of the center of self in cartesian space (inches)f.

Return type:

float

class briann.GUI.model_explorer.NetworkVisualizer(briann: BrIANN, canvas: Canvas, initial_x: float, initial_y: float, width: float, height: float, area_size: float)[source]

Bases: object

Visualizes the network structure of a given briann instance in a rectangle whose center is at (initial_x,`initial_y`) with provided width and height. The visualizer will be drawn on top of all previously drawn elements on the canvas and it can be dragged around with the mouse.

Parameters:
  • briann (bpnc.BrIANN) – The BrIANN instance to visualize.

  • canvas (Canvas) – The canvas to draw the visualizer on.

  • x (float) – The x-coordinate of the visualizer’s center in Cartesian space (inches).

  • y (float) – The y-coordinate of the visualizer’s center in Cartesian space (inches).

  • width (float) – The width of the visualizer in inches.

  • height (float) – The height of the visualizer in inches.

property briann: BrIANN
Returns:

The BrIANN instance that is visualized by this visualizer.

Return type:

bpnc.BrIANN

class briann.GUI.model_explorer.StateVisualizerHeatMap(area: Area, canvas: Canvas, current_simulation_time: float, initial_x: numpy.ndarray, initial_y: float, width: float, height: float)[source]

Bases: AreaStateVisualizer

Plots a series of TimeFrame’s in an evolving heatmap where the x-axis represents width, the y-axis represents height and the heatmap represents values. It assumes that the input state has a shape of (batch-size, channels, height, width) where channels is 1 or 3 (grayscale or RGB) or any other number of channels which will then be averaged across. An alternative accepted shape is (batch-size, height, width) for single-channel data. The visualizer always plots only the first instance of the batch (index 0).

NAME_TAG = 'Heatmap'
_update_plot(time_frame: TimeFrame = None) None[source]
classmethod is_compatible_with_state(input_shape: List[int]) bool[source]

Checks whether the given input shape is compatible with this visualizer.

Parameters:

input_shape (List[int]) – The time-frame’s state’s shape to be checked.

Returns:

True if the shae is compatible with this visualizer, False otherwise.

Return type:

bool

class briann.GUI.model_explorer.StateVisualizerLineChart(area: Area, canvas: Canvas, current_simulation_time: float, initial_x: float, initial_y: float, width: float, height: float)[source]

Bases: AreaStateVisualizer

Plots a series of TimeFrame’s in a line-plot where the x-axis represents time, the y-axis represents deflection and there will be one line per channel. This class assumes that the time-series is streamed to py:meth:~briann.GUI.StateVisualizerLineChart._update_plot_ one time-frame at a time. Each such time-frame is expected to be of shape (batch-size, channel-count).

NAME_TAG = 'Line Chart'
_update_plot(time_frame: TimeFrame = None) None[source]
classmethod is_compatible_with_state(input_shape: List[int]) bool[source]

Checks whether the given input shape is compatible with this visualizer.

Parameters:

input_shape (List[int]) – The time-frame’s state’s shape to be checked.

Returns:

True if the shae is compatible with this visualizer, False otherwise.

Return type:

bool

Module contents