Population activity measurement by calcium imaging can be combined with cellular
resolution optogenetic activity perturbations to enable the mapping of neural
connectivity in vivo. This requires accurate inference of perturbed and unperturbed
neural activity from calcium imaging measurements, which are noisy and
indirect, and can also be contaminated by photostimulation artifacts. We have
developed a new fully Bayesian approach to jointly inferring spiking activity and
neural connectivity from in vivo all-optical perturbation experiments. In contrast
to standard approaches that perform spike inference and analysis in two separate
maximum-likelihood phases, our joint model is able to propagate uncertainty in
spike inference to the inference of connectivity and vice versa. We use the framework
of variational autoencoders to model spiking activity using discrete latent
variables, low-dimensional latent common input, and sparse spike-and-slab generalized
linear coupling between neurons. Additionally, we model two properties
of the optogenetic perturbation: off-target photostimulation and photostimulation
transients. Using this model, we were able to fit models on 30 minutes of data
in just 10 minutes. We performed an all-optical circuit mapping experiment in
primary visual cortex of the awake mouse, and use our approach to predict neural
connectivity between excitatory neurons in layer 2/3. Predicted connectivity is
sparse and consistent with known correlations with stimulus tuning, spontaneous
correlation and distance