DOI: 10.5061/dryad.pk0p2ngrv
title: Data from: Precise control of neural activity using dynamically optimized electrical stimulation

description: Neural implants have the potential to restore lost sensory function by
 electrically evoking the complex naturalistic activity patterns of neural
 populations. However, it can be difficult to predict and control evoked
 neural responses to simultaneous multi-electrode stimulation due to
 nonlinearity of the responses. We present a solution to this problem and
 demonstrate its utility in the context of a bi-directional retinal implant
 for restoring vision. A dynamically optimized stimulation approach encodes
 incoming visual stimuli into a rapid, greedily chosen, temporally dithered
 and spatially multiplexed sequence of simple stimulation patterns. Stimuli
 are selected to optimize the reconstruction of the visual stimulus from
 the evoked responses. Temporal dithering exploits the slow time scales of
 downstream neural processing, and spatial multiplexing exploits the
 independence of responses generated by distant electrodes. The approach
 was evaluated using an experimental laboratory prototype of a retinal
 implant: large-scale, high-resolution multi-electrode stimulation and
 recording of macaque and rat retinal ganglion cells ex vivo. The
 dynamically optimized stimulation approach substantially enhanced
 performance compared to existing approaches based on static mapping
 between visual stimulus intensity and current amplitude. The modular
 framework enabled parallel extensions to naturalistic viewing conditions,
 incorporation of perceptual similarity measures, and efficient
 implementation for an implantable device. A direct closed-loop test of the
 approach supported its potential use in vision restoration.
description: # Data from: Precise control of neural activity using dynamically
 optimized electrical stimulation --- We provide the code and data to
 reproduce figures from the paper. ## Description of the data and file
 structure The folder contains: 1. Recorded cells, with their visual and
 electrical response properties. 2. Output of the greedy temporal dithering
 algorithm for static white noise images and natural scenes. 3. Scripts for
 generating the shown figures in the paper and the required utility
 functions. Some empty folders in the repository store intermediate or
 final results of code execution. To understand what the different data
 files contain, it is recommended to refer to scripts `figure2_3_6.m` and
 `figure7_video1.m`. Other matlab files (`analyse_used_electrodes.mat`,
 `assemble_nsem`, `compute_mse`, `get_cell_indices`,
 `getElectrodeCoords512`, `nums_from_ids`, `plot_rf_fit`, `rmatrix2`,
 `set_up_fig_or_axes`) are utility functions used in these scripts. --- ###
 Data Files for `figure2_3_6.m` File `2015-11-09-3_data000_test.mat`
 contains electrical and visual response properties of a recording. The
 variables are: * `cellID_list` : List of cell IDs * `eis` : Electrical
 Images, or spike waveforms. (# cells x # electrodes x # time-points) *
 `elec_loc` : Location of the electrode grid (# electrodes x 2) * `stas` :
 Receptive fields of cells (# cells x pixels) * `full_stas_clipped` :
 Spatio-temporal STAs (List of # cells, with each element of size stimulus
 dim. 1 x stimulus dim. 2 x RGB x # time-points at 120Hz sampling rate) *
 `ttf_log` : STA time courses (# time points x cells) * `mask` : Mask of
 the receptive field of cells (stimulus dim. 1 x stimulus dim. 2 x # cells)
 * `sigmoid_params1` : slope of sigmoid curve for single electrode
 activation (# cells x # electrodes) * `sigmoid_params2` : threshold of
 sigmoid curve for single electrode activation (# cells x # electrodes)
 Further details of the visual stimulus responses are in `datarun.mat` File
 `2015-11-09-3-fr3.3.mat` contains the variables for running the greedy
 temporal dithering algorithm. The variables are: * `A`: Decoder [# pixels
 x # cells] * `D`: Dictionary (# dictionary elements x # cells) * `S`: Test
 visual stimulus (# pixels x # samples) File
 `stimulation_results_detail_mn3.3_orig_target_stix32_2.mat` contains the
 output of greedy algorithm. The vairables are: * `EA_ex_log` : Greedily
 chosen electrode and amplitude (2 x sequence length x # test images) *
 `EA_final` : The final dictionary (# dictionary elements x 2,
 corresponding to the electrode and amplitude) * `cell_prob_ex_log` : Cell
 activiation probability for the greedy output (# cells x sequence length x
 # test images ) * `decoder` : The decoder (# pixels x # cells) *
 `dictionary_final` : The activation probability of cells for the final
 dictionary (# dictionary elements x # cells) * `dictsz_ex_log` : The size
 of dictionary over the course of temporal dithering sequence (sequence
 length x # test images) * `error_ex_log` : MSE over the course of temporal
 dithering sequence (# test images x sequence length) * `targets` : Test
 visual stimulus (# pixels x # samples) Other datafiles
 (`2015_10_29_3_fig_2_lb1.mat`, `ed_from_STA.mat`, `elec_rotated.mat`,
 `grd_stim.mat`) are output of the analysis in script `figure2_3_6.m`. ---
 ### Data files for `figure7_video1.m` This data is presented in the
 folder: `GA_paper_fig1_changes_dict_constrains` The file
 `2015-11-09-3_data000_test.mat` is identical to the one described above.
 File `2015-11-09-3-SafeZone_Indices.mat` constains the index of the
 maximum current (`SafeZone_Indices`) that can be passed through each
 electrode without activating off-array cells via axonal stimulation. File
 `face_movie_0_rand_ms.mat` contains the data for applying temporal
 dithering algorithm for natural stimulus. This converts a static visual
 stimulus into a dynamic stimulus, as seen by the retina after saccades and
 microsaccades. * `image` : Target image. Celebrity image, publicly
 available on the internet. * `entire_path` / `microsacc_traj` : Eye
 movement path. List of cells, with each cell containing the microsaccade
 trajectory (Time points x 2 dimensions)for each saccade. * `saccade_log` :
 Saccade locations (# saccades x 2) * `saccade_duration_log` : Duration of
 saccades (# saccades) * `sacacde_bin_log` : Number of bins for each
 saccade (# saccades) * `stimulus`: Dynamic stimulus movie seen by the
 retina, during eye movements (# pixels x # time points) File
 `face_movie_0_rand.mat`. Same as `face_movie_0_rand_ms.mat`, but generates
 the dynamic stimulus with saccaades only (no microsaccades). Other
 variables same as `face_movie_0_rand_ms.mat`. File `Dec_dynamic.mat`
 contains the parameters for a rank 1 decoder of stimulus using
 spatio-temporal responses. Variables: * `decoder_spatial` : Spatial-only
 parameters (# cells x # pixels) * `decoder_temporal` : Temporal-only
 parameters (# time points) Output of greedy temporal dithering found in
 two types of files: summary outputs (`stim_dyn_0_rand_ms.mat`,
 `stim_dyn_detail_0_rand.mat`) or detailed outputs
 (`stim_dyn_detail_0_rand_ms.mat`, `stim_dyn_detail_0_rand.mat`). The
 variables are same as
 `stimulation_results_detail_mn3.3_orig_target_stix32_2.mat` listed above.
 Other files (`stimulation_results_detail_mn1_orig_target_2.mat`,
 `stimulation_results_detail_mn3.3_orig_target_stix32_2.mat`,
 `stimulation_results_mn1_orig_target_2.mat`,
 `stimulation_results_mn3.3_orig_target_stix32_2.mat`, `stim-resp.mat`)
 contain intermediate outputs and are in the same format to the ones listed
 above. The folder `current_response` is empty and will contain
 intermediate output of analysis scripts. ## Sharing/Access information
 Data was collected in the laboratory of Prof. EJ Chichilnisy at Stanford
 University between 2014-2024. The data required for the paper are included
 in the folder. ## Code/Software The best way to start from scripts for
 Figures 2, 3 and 6 (figure2_3_6.m) and Figures 7 and Video 1
 (figure7_video1.m). These scripts load the appropriate data sources and
 create the figures from the paper. The scripts run in MATLAB, and require
 the CVX package ([https://cvxr.com/cvx/](https://cvxr.com/cvx/)).