pulse2percept.models.base
BaseModel,
Model,
SpatialModel,
TemporalModel
Classes
|
Abstract base class for computational models. |
|
Composite computational model. |
|
Abstract base class for spatial models. |
|
Abstract base class for temporal models. |
- class pulse2percept.models.base.BaseModel(**params)[source]
Abstract base class for computational models.
Adds build state to
Parametrized. Changing a declared model parameter invalidates the build; prediction rebuilds automatically when needed.Changed in version 0.11.0:
predict_perceptbuilds automatically after construction or a parameter change.- extra_stimulus_units = ()
Additional stimulus units accepted by this model
- build(**build_params)[source]
Build the model.
Runs expensive one-time setup after applying any supplied model parameters.
predict_perceptbuilds automatically when needed.- Parameters:
**build_params (keyword arguments) – Declared model parameters to set before building.
- Return type:
self
Notes
Subclasses should override
_build, not this method.
- property is_built
A read-only flag indicating whether the model has been built
- class pulse2percept.models.base.SpatialModel(implant, **params)[source]
Abstract base class for spatial models.
Spatial models map electrode stimulation to brightness on a sampled visual-field grid. Subclasses implement
_predict_spatialand may override_buildfor precomputation.- Parameters:
implant (
Implant) –Implant whose electrode geometry is modeled.
Added in version 0.11.0.
implant_position ((x, y) or Quantity, optional) –
Position of the device-local origin. A bare pair or length is a tissue position in microns; a dva position is resolved through a single-region
visual_field_map. Placement is rigid and distinct fromlocation_noise.Added in version 0.11.0.
implant_rotation (float or Quantity, optional) –
In-plane rotation (deg), positive counter-clockwise about the device-local origin. Applied before
implant_position.Added in version 0.11.0.
implant_depth (float or Quantity, optional) –
Signed offset (um) along the tissue-plane normal; positive is away from the tissue. Only models that use electrode
zrespond to it.Added in version 0.11.0.
note:: (..) – These parameters define a 2D tissue-plane pose. A 3D
visual_field_mapsuch asNeuropythyMapaccepts only identity model-side placement; construct the implant directly in the map’s 3D frame instead.xrange ((float, float) or Quantity, optional) – Horizontal visual-field extent in degrees of visual angle.
yrange ((float, float) or Quantity, optional) – Vertical visual-field extent in degrees of visual angle.
step (float, (float, float), or Quantity, optional) –
Grid spacing in degrees of visual angle. A pair specifies separate x and y spacing.
Changed in version 0.10.0: Renamed from
xystep;xystepwas removed in 0.11.0.grid_type ({'rect', 'hex'}, optional) – Sampling lattice used for the visual-field grid.
thresh_percept (float, optional) – Brightness values below this threshold are set to zero.
min_current_spread (float, optional) – Fraction of peak Gaussian current spread below which an electrode may be skipped at a grid point. Set to 0 to disable the cutoff.
visual_field_map (VisualFieldMap, optional) – Map between visual-field and tissue coordinates.
Noneuntil an anatomy-specific subclass such asRetinalSpatialsupplies one; building without a map raises.n_gray (int or None, optional) – Number of gray levels in the returned percept.
Nonedisables gray-level quantization.location_noise (float or None, optional) –
Standard deviation of fixed electrode-specific phosphene offsets, in dva. Requires an invertible 2D
visual_field_map. Moving the effective stimulation location may also change phosphene shape or size in location-dependent models. This phenomenological parameter is not empirically calibrated and does not model trial-to-trial or gaze effects.Added in version 0.11.0.
verbose (bool, optional) – Whether to print status messages.
ndim (list of int, optional) – Dimensionalities of
visual_field_mapaccepted by the model.n_threads (int, optional) – Number of OpenMP threads.
n_jobs (int or None, optional) – Alias for
n_threads.Noneand -1 use all available CPU cores.
Notes
xrange,yrangeandstepdescribe the simulated visual field and are stored in degrees of visual angle. This class is anatomy-neutral: it supplies no defaultvisual_field_mapand reads no physical length as a visual-field extent.Added in version 0.6.
Changed in version 0.11.0: Retinal defaults and the physical-extent shorthand moved to
RetinalSpatial.- property n_jobs
n_jobsis an alias forn_threads; see_n_jobs_alias.
- property implant
The prosthesis system whose geometry this model uses.
Rebinding invalidates the spatial build.
Added in version 0.11.0.
- 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
- 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
Nonefor an empty source.- Return type:
Perceptor 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
Modelwith 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.
- plot(use_dva=False, style='hull', autoscale=True, ax=None, figsize=None, show_implant=False)[source]
Plot the model
- Parameters:
use_dva (bool, optional) – Uses degrees of visual angle (dva) if True, else tissue coordinates (microns)
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
show_implant (bool, optional) –
Draw the implant at its model-side placement. Requires
use_dva=False.Added in version 0.11.0.
- Returns:
ax – Returns the axis object of the plot
- Return type:
matplotlib.axes.Axes
- extra_stimulus_units = ()
Additional stimulus units accepted by this model
- property is_built
A read-only flag indicating whether the model has been built
- class pulse2percept.models.base.TemporalModel(**params)[source]
Abstract base class for temporal models.
Temporal models map a time-varying stimulus or percept to brightness over time. Subclasses implement
_predict_temporaland may override_buildfor precomputation.- Parameters:
dt (float or Quantity, optional) – Simulation time step. Plain values are interpreted as milliseconds.
thresh_percept (float, optional) – Brightness values below this threshold are set to zero.
reduce ({'last', 'peak'}, optional) – How automatically selected output intervals are summarized.
'last'reports brightness at the interval endpoint;'peak'reports the maximum brightness reached in the interval. Explicitt_perceptvalues always request those exact instants.verbose (bool, optional) – Whether to print status messages.
n_threads (int, optional) – Number of OpenMP threads.
n_jobs (int or None, optional) – Alias for
n_threads.Noneand -1 use all available CPU cores.
Notes
Models with
_reduces_intervals = Truecompute'peak'within the integrator. Other temporal models approximate it by subsampling each output interval.Added in version 0.6.
Changed in version 0.10.0: Added
reduce.- property n_jobs
n_jobsis an alias forn_threads; see_n_jobs_alias.
- predict_percept(stim, t_percept=None)[source]
Predict the temporal response.
- Parameters:
stim (Stimulus or Percept) – Time-varying input. The temporal model is applied independently at each spatial location.
t_percept (float or array-like, optional) – Output times in
time_unit. Unitful times are accepted. If omitted, encoded video frame times are used when available; otherwise output is sampled every 20 ms, with at least one frame for a shorter stimulus.
- Returns:
percept – Percept with shape Y x X x T, or
NoneifstimisNone.- Return type:
Perceptor None
Notes
Explicit
t_perceptvalues sample brightness at those instants. Otherwisereducedetermines whether each output interval reports its endpoint or peak. Requested times are sorted and must lie on thedtgrid.Changed in version 0.10.0: Automatically selected output times may summarize intervals via
reduce.
- build(**build_params)[source]
Build the model.
Runs expensive one-time setup after applying any supplied model parameters.
predict_perceptbuilds automatically when needed.- Parameters:
**build_params (keyword arguments) – Declared model parameters to set before building.
- Return type:
self
Notes
Subclasses should override
_build, not this method.
- extra_stimulus_units = ()
Additional stimulus units accepted by this model
- property is_built
A read-only flag indicating whether the model has been built
- class pulse2percept.models.base.Model(spatial=None, temporal=None)[source]
Composite computational model.
Combines a spatial model with a temporal model. Both are given as already constructed instances, and at least one is required.
model = Model(ScoreboardSpatial(ArgusII()), Nanduri2012Temporal())
Modeldoes not forward component parameters. Access them throughmodel.spatialormodel.temporal, asmodel.spatial.rhoandmodel.temporal.tau.- Parameters:
spatial (
SpatialModel, optional) – Spatial model instance, already bound to its implant.temporal (
TemporalModel, optional) – Temporal model instance.versionadded: (..) – 0.6:
versionchanged: (..) – 0.11.0: Takes component instances only, requires at least one of them, and no longer forwards component parameters.
- 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 extra_stimulus_units
Additional stimulus units accepted by the active component
- property space_unit
The unit spatial coordinates are expressed in
The temporal model never sees a coordinate.
- property time_unit
Time unit used by the final model stage.
t_perceptand the returned percept use the temporal model’s unit when present, otherwise the spatial model’s unit.
- property implant
The implant the spatial model is bound to.
Returns
Nonefor temporal-only models. Assignment forwards tomodel.spatial.implantand invalidates the spatial build.Added in version 0.11.0.
- build()[source]
Build all model components.
Unlike prediction-time auto-building, this rebuilds every component. To set parameters while building, call the component’s
buildmethod, e.g.model.spatial.build(rho=250).- Return type:
self
- 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 byprepare_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 thatscene = eye-centered visual field + gaze. Requiressourceto be a scene. AGazeis resolved against the scene’s frame times, not againstt_percept. Gaze decides which part of the scene reaches the electrodes unless the implant’sscene_input_frameis'head'; the percept itself stays on the model’s eye-centered grid either way.
- Returns:
percept (
Perceptor 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 withplot()orrender()... versionchanged:: 0.11.0 –
sourceis now the presented stimulus or scene rather than an implant carrying a stimulus. Scene prediction returns the model percept;vminandvmaxmoved toScene.plotandScene.render.
- 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 is_built
Returns True if the
buildmodel has been called