pulse2percept.models.cortex.scoreboard

ScoreboardSpatial, ScoreboardModel

Classes

ScoreboardModel(implant, *[, rho, regions, ...])

Cortical adaptation of scoreboard model from [Beyeler2019] (standalone model)

ScoreboardSpatial(implant, *[, rho, ...])

Cortical adaptation of scoreboard model from [Beyeler2019]

class pulse2percept.models.cortex.scoreboard.ScoreboardSpatial(implant, *, rho=200, regions=None, meridian_blend=0.1, xrange=(-5, 5), yrange=(-5, 5), step=0.1, grid_type='rect', thresh_percept=0, min_current_spread=1e-08, visual_field_map=None, n_gray=None, implant_position=(0, 0), implant_rotation=0, implant_depth=0, location_noise=None, verbose=True, ndim=None, n_threads=None, n_jobs=None)[source]

Cortical adaptation of scoreboard model from [Beyeler2019]

Implements the scoreboard model described in [Beyeler2019], where percepts from each electrode are Gaussian blobs. The percepts resulting from different cortical regions (e.g. v1/v2/v3) are added linearly. The rho parameter modulates phosphene size.

Note

Use this class if you want to combine the spatial model with a temporal model. Use ScoreboardModel if you want a a standalone model.

Warning

rho is fixed: this model does not predict pulse-dependent phosphene size. Doubling amplitude doubles brightness and leaves the phosphene exactly as wide. Use DynaphosModel for a cortical model whose phosphene size follows the stimulus current.

Parameters:
  • implant (Implant) –

    The implant whose stimulation this model predicts.

    Added in version 0.11.0.

  • rho (double, optional) – Exponential decay constant describing phosphene size (microns).

  • min_current_spread (float, optional) – An electrode is skipped at grid points where its Gaussian current spread has decayed below this fraction of its peak. The default (1e-8, about 6.1 rho away) drops the Gaussian times the stimulus amplitude, summed over the skipped electrodes, so the error at a point is bounded by min_current_spread times the summed amplitude across electrodes.

  • regions (list of str, optional) – The regions to simulate. Options are ‘v1’, ‘v2’, or ‘v3’. Default: [‘v1’]

  • xrange ((x_min, x_max), optional) – A tuple indicating the range of x values to simulate (in degrees of visual angle). Negative x values lie left of fixation, positive x values right of it.

  • yrange (tuple, (y_min, y_max), optional) – A tuple indicating the range of y values to simulate (in degrees of visual angle). Negative y values lie below fixation, positive y values above it.

  • step (int, double, tuple, optional) – Step size for the range of (x,y) values to simulate (in degrees of visual angle). For example, to create a grid with x values [0, 0.5, 1] use xrange=(0, 1) and step=0.5. Pass a tuple to give the x and y axes different step sizes.

  • grid_type ({'rect', 'hex'}, optional) – Whether to simulate points on a rectangular or hexagonal grid

  • meridian_blend (float, optional) –

    Gaussian standard deviation (dva) for smoothing across the vertical meridian. Default: 0.1. Set to 0 to disable.

    Added in version 0.10.0.

  • visual_field_map (VisualFieldMap, optional) – An instance of a VisualFieldMap object that provides retinotopic mappings. By default, Polimeni2006Map is used.

  • n_gray (int, optional) – The number of gray levels to use. If an integer is given, k-means clustering is used to compress the color space of the percept into n_gray bins. If None, no compression is performed.

  • implant_position ((x, y) or Quantity, optional) –

    Position of the device-local origin, in tissue coordinates or dva.

    Added in version 0.11.0.

  • implant_rotation (float or Quantity, optional) –

    In-plane rotation (deg), positive counter-clockwise.

    Added in version 0.11.0.

  • implant_depth (float or Quantity, optional) –

    Signed offset (um) along the normal of a 2D tissue map.

    Added in version 0.11.0.

  • location_noise (float or None, optional) –

    Standard deviation of fixed electrode-specific phosphene offsets, in dva. Requires an invertible 2D visual_field_map. None or 0 disables it. Location-dependent models may also change phosphene shape or size.

    Added in version 0.11.0.

  • n_threads (int, optional) – Number of CPU threads to use during parallelization using OpenMP. Defaults to max number of user CPU cores.

  • n_jobs (int, optional) – Alias for n_threads; None or -1 uses every core.

  • :: (.. important) – Changing a model parameter outside the constructor (e.g., by directly setting model.xrange = (-10, 10)) invalidates the build, and the next predict_percept builds it again.

get_default_params()[source]

Returns all settable parameters of the scoreboard model

get_param_units()[source]

Return a dict of the units that parameters are stored in

build(**build_params)[source]

Build the spatial model.

Applies any supplied parameters, validates the implant, visual-field map and implant placement, builds the sampling grid, then runs _build.

Parameters:

**build_params (keyword arguments) – Declared model parameters to set before building.

Return type:

self

extra_stimulus_units = ()

Additional stimulus units accepted by this model

property implant

The prosthesis system whose geometry this model uses.

Rebinding invalidates the spatial build.

Added in version 0.11.0.

property is_built

A read-only flag indicating whether the model has been built

property n_jobs

both names read and write the same value.

Type:

Number of OpenMP threads to use during parallelization. An alias for n_threads

plot(use_dva=False, style=None, autoscale=True, ax=None, figsize=None, fc=None, show_implant=False, **kwargs)[source]

Plot the model

Parameters:
  • use_dva (bool, optional) – Plot points in visual field. If false, simulated points will be plotted in cortex

  • style ({'hull', 'scatter', 'cell'}, optional) –

    Grid plotting style:

    • ’hull’: Show the convex hull of the grid (that is, the outline of the smallest convex set that contains all grid points).

    • ’scatter’: Scatter plot all grid points

    • ’cell’: Show the outline of each grid cell as a polygon. Note that this can be costly for a high-resolution grid.

  • autoscale (bool, optional) – Whether to adjust the x,y limits of the plot to fit the implant

  • ax (matplotlib.axes._subplots.AxesSubplot, optional) – A Matplotlib axes object. If None, will either use the current axes (if exists) or create a new Axes object.

  • figsize ((float, float), optional) – Desired (width, height) of the figure in inches

  • fc (matplotlib color, optional) – Face color for the grid cells. If None, will use the default matplotlib color cycle.

  • show_implant (bool, optional) –

    Draw the implant at its model-side placement. Requires use_dva=False.

    Added in version 0.11.0.

  • kwargs (dict, optional) – Additional keyword arguments are passed on to Grid2D.plot()

Returns:

ax – Returns the axis object of the plot

Return type:

matplotlib.axes.Axes

predict_percept(source, t_percept=None)[source]

Predict the spatial response.

Parameters:
  • source (stimulus source) – Anything accepted by prepare_stim().

  • t_percept (float or array-like, optional) – Output times in time_unit. If omitted, use the source time points. Unitful times are accepted.

Returns:

percept – Percept with shape Y x X x T, or None for an empty source.

Return type:

Percept or None

Notes

For an encoded image or video, a spatial-only model uses frame-level modulation rather than the delivered pulse train. In a composite Model with a temporal stage, the spatial stage receives the delivered train so the temporal model can integrate it.

Changed in version 0.11.0: Takes the stimulus source rather than an implant carrying a stimulus.

set_params(**params)[source]

Set the parameters of this object

space_unit = um[source]

The unit spatial coordinates are expressed in

stimulus_unit = uA[source]

The unit stimulus values are expressed in

time_unit = ms[source]

The unit time is expressed in

class pulse2percept.models.cortex.scoreboard.ScoreboardModel(implant, *, rho=200, regions=None, meridian_blend=0.1, xrange=(-5, 5), yrange=(-5, 5), step=0.1, grid_type='rect', thresh_percept=0, min_current_spread=1e-08, visual_field_map=None, n_gray=None, implant_position=(0, 0), implant_rotation=0, implant_depth=0, location_noise=None, verbose=True, ndim=None, n_threads=None, n_jobs=None)[source]

Cortical adaptation of scoreboard model from [Beyeler2019] (standalone model)

Implements the scoreboard model described in [Beyeler2019], where percepts from each electrode are Gaussian blobs. The percepts resulting from different cortical regions (e.g. v1/v2/v3) are added linearly. The rho parameter modulates phosphene size.

Note

Use ScoreboardSpatial to combine the spatial model with a temporal model.

Note

For this spatial-only model, dimensionless image and video values are treated as relative electrode amplitudes, so an implant encoder is not required. Physical or pulse-dependent models still require encoded stimulation.

Warning

rho is fixed: this model does not predict pulse-dependent phosphene size. Doubling amplitude doubles brightness and leaves the phosphene exactly as wide. Use DynaphosModel for a cortical model whose phosphene size follows the stimulus current.

Parameters:
  • implant (Implant) –

    The implant whose stimulation this model predicts.

    Added in version 0.11.0.

  • rho (double, optional) – Exponential decay constant describing phosphene size (microns).

  • min_current_spread (float, optional) – An electrode is skipped at grid points where its Gaussian current spread has decayed below this fraction of its peak. The default (1e-8, about 6.1 rho away) drops the Gaussian times the stimulus amplitude, summed over the skipped electrodes, so the error at a point is bounded by min_current_spread times the summed amplitude across electrodes.

  • regions (list of str, optional) – The regions to simulate. Options are ‘v1’, ‘v2’, or ‘v3’. Default: [‘v1’]

  • xrange ((x_min, x_max), optional) – A tuple indicating the range of x values to simulate (in degrees of visual angle). Negative x values lie left of fixation, positive x values right of it.

  • yrange (tuple, (y_min, y_max), optional) – A tuple indicating the range of y values to simulate (in degrees of visual angle). Negative y values lie below fixation, positive y values above it.

  • step (int, double, tuple, optional) – Step size for the range of (x,y) values to simulate (in degrees of visual angle). For example, to create a grid with x values [0, 0.5, 1] use xrange=(0, 1) and step=0.5. Pass a tuple to give the x and y axes different step sizes.

  • grid_type ({'rect', 'hex'}, optional) – Whether to simulate points on a rectangular or hexagonal grid

  • meridian_blend (float, optional) –

    Gaussian standard deviation (dva) for smoothing across the vertical meridian. Default: 0.1. Set to 0 to disable.

    Added in version 0.10.0.

  • visual_field_map (VisualFieldMap, optional) – An instance of a VisualFieldMap object that provides retinotopic mappings. By default, Polimeni2006Map is used.

  • n_gray (int, optional) – The number of gray levels to use. If an integer is given, k-means clustering is used to compress the color space of the percept into n_gray bins. If None, no compression is performed.

  • implant_position ((x, y) or Quantity, optional) –

    Position of the device-local origin, in tissue coordinates or dva.

    Added in version 0.11.0.

  • implant_rotation (float or Quantity, optional) –

    In-plane rotation (deg), positive counter-clockwise.

    Added in version 0.11.0.

  • implant_depth (float or Quantity, optional) –

    Signed offset (um) along the normal of a 2D tissue map.

    Added in version 0.11.0.

  • location_noise (float or None, optional) –

    Standard deviation of fixed electrode-specific phosphene offsets, in dva. Requires an invertible 2D visual_field_map. None or 0 disables it. Location-dependent models may also change phosphene shape or size.

    Added in version 0.11.0.

  • n_threads (int, optional) – Number of CPU threads to use during parallelization using OpenMP. Defaults to max number of user CPU cores.

  • n_jobs (int, optional) – Alias for n_threads; None or -1 uses every core.

  • :: (.. important) – Changing a model parameter outside the constructor (e.g., by directly setting model.xrange = (-10, 10)) invalidates the build, and the next predict_percept builds it again.

build()[source]

Build all model components.

Unlike prediction-time auto-building, this rebuilds every component. To set parameters while building, call the component’s build method, e.g. model.spatial.build(rho=250).

Return type:

self

property extra_stimulus_units

Additional stimulus units accepted by the active component

property has_space

Returns True if the model has a spatial component

property has_time

Returns True if the model has a temporal component

property implant

The implant the spatial model is bound to.

Returns None for temporal-only models. Assignment forwards to model.spatial.implant and invalidates the spatial build.

Added in version 0.11.0.

property is_built

Returns True if the build model has been called

plot(*args, **kwargs)[source]

Plot the spatial model.

Parameters and return value are those of plot().

predict_percept(source, t_percept=None, gaze=None)[source]

Predict a percept.

Parameters:
  • source (stimulus source or Scene) – What is presented to the device: anything accepted by prepare_stim(), or a visual scene.

  • t_percept (float or array-like, optional) – Output times in time_unit. Unitful times are accepted.

  • gaze ((x, y), (n_frames, 2), or Gaze, optional) – Scene location falling on the fovea, in degrees of visual angle, so that scene = eye-centered visual field + gaze. Requires source to be a scene. A Gaze is resolved against the scene’s frame times, not against t_percept. Gaze decides which part of the scene reaches the electrodes unless the implant’s scene_input_frame is 'head'; the percept itself stays on the model’s eye-centered grid either way.

Returns:

  • percept (Percept or None) – Perceived brightness on the model’s spatial grid, for a scene as for any other source. A scene’s scotoma describes residual native vision and does not enter the model response; draw the two together with plot() or render().

  • .. versionchanged:: 0.11.0 – source is now the presented stimulus or scene rather than an implant carrying a stimulus. Scene prediction returns the model percept; vmin and vmax moved to Scene.plot and Scene.render.

property space_unit

The unit spatial coordinates are expressed in

The temporal model never sees a coordinate.

property stimulus_unit

The unit stimulus values are expressed in

The stimulus goes to the spatial model if there is one, and straight to the temporal model otherwise.

property time_unit

Time unit used by the final model stage.

t_percept and the returned percept use the temporal model’s unit when present, otherwise the spatial model’s unit.