Schematic of the Closed-Loop Feedback Training System (CLoPy) for Neurofeedback and Specified Movement Feedback.

A) The components of CLoPy are presented in a block diagram. Modular components such as the configuration file, camera factory, audio tone generator, and reward delivery system are displayed and are utilized by both the Closed-Loop Neurofeedback (CLNF) and Closed-Loop Movement Feedback (CLMF) systems. The configuration file (config.ini) stored all configurable parameters of the system, including camera settings, feedback parameters, reward thresholds, number of trials, and the duration of trial and rest periods, under an experiment-specific section. The camera factory was an abstract class that provided a unified interface for a programmable camera to the CLNF and CLMF systems. This abstraction allowed the core system to remain independent of the specific camera libraries required for image streaming. Camera-specific routines were implemented in separate “brain_camera_stream” or “behavior_camera_stream” classes, which inherited functions from the “camera_factory” superclass and ran in independent thread processes. The Region of Interest (ROI) manager was used by the CLNF core to maintain a list of ROIs, as well as routines to perform rule-specific operations on them, as specified in config.ini. An ROI could be defined as a rectangle (with the upper-left corner coordinates, height, and width) or as a circle (with center coordinates and radius). The audio tone generator mapped the target activity (ΔF/F0 in CLNF, and control-point speed in CLMF) to graded audio tone frequencies. It generated audio signals at 44.1 kHz sampling based on the specified frequency and sent the signal to the audio output. Reward delivery was controlled by opening a solenoid valve for a specified duration, which was managed in a separate process thread. The CLNF core was the main program responsible for running the CLNF system. It utilized config.ini, the camera factory, the ROI manager, and integrated the audio tone generator and reward delivery functions. The system also saved the recorded data and configuration parameters with unique identifiers. The CLMF core, similarly, was the primary program responsible for operating the CLMF system. It utilized config.ini, the camera factory, and DeepLabCut-Live, integrating the audio tone generator and reward delivery functions. This module also saved the data and configuration parameters with unique identifiers.

Setup of Real-time Feedback for GCaMP6 Cortical Activity and Movements

A) GCaMP-based Closed-loop Feedback and Reward System: Mice with transcranial windows were head-fixed beneath an imaging camera, with the cortical window illuminated using 440 nm (for reflectance) and 470 nm (for GCaMP excitation) light. i) Epifluorescence at 520 nm and reflectance at 440 nm were captured at 15 fps using a bandpass filter, integrated within the cortical imaging system. ii) The captured images were simultaneously saved and processed to compute ΔF/F0 in real-time using a Raspberry Pi 4B model. Pre-selected regions of interest (ROIs) were continuously monitored, and rule-specific activation was calculated based on the ΔF/F0 signal. The left panel displayed wide-field cortical GCaMP6 fluorescence (green) and reflectance (blue), while the right panel showed the real-time calculated and corrected ΔF/F0 map, generated using a moving average of the captured images. The target ROIs were marked as green (R1) and red (R2), although a single ROI could also be selected for monitoring. iii) For example, as shown on the ΔF/F0 map, ROIs R1 and R2 were continuously monitored, and the average activity across these ROIs was calculated. iv) When the task rule was defined as “R1 - R2 > threshold”, the difference between R1 and R2 activities was mapped to a non-linear function that generated graded audio tone frequencies (ranging from 1 kHz to 22 kHz), as illustrated in the figure. Task rules could be modified within the setup on any given day, and the corresponding activation levels were automatically mapped to the audio frequencies. The “threshold”, expressed in ΔF/F0 units, was adjustable based on the experimental design. v) Upon reaching the rule-specific threshold for activity, in addition to the increase in audio tone frequency, a water reward was delivered to the head-fixed mouse. Mice expressing GCaMP6, with surgically implanted cortical windows and a head-bar, were positioned beneath the imaging camera, with GCaMP6 excitation light at 470 nm. A secondary wavelength of 440 nm was used for continuous reflectance signals to measure hemodynamic changes, which were then applied to correct the fluorescence signal. The RGB camera was equipped with bandpass filters that allowed only 520 nm epifluorescence and 440 nm reflectance to be simultaneously collected.

B) Closed-loop Behavior Feedback and Reward Setup: A specialized transparent head-fixation chamber was custom-designed using 3mm-thick plexiglass material (3D model available) to enable multi-view behavioral imaging and real-time tracking of body parts. The rectangular chamber was equipped with two strategically positioned mirrors—one at the bottom, angled at 45 degrees, and one at the front, angled at 30 degrees—facilitating multi-view imaging of the head-fixed mouse with a single camera. i) A Dalsa CCD camera was connected to a PC for widefield cortical imaging during the session. ii) Auditory feedback was provided using a non-linear function mapping paw speeds to corresponding audio tone frequencies. iii) The head-fixed mouse, positioned in the transparent chamber, was able to freely move its body parts, while its behavior was continuously recorded. This setup allowed for the capture of three distinct views of the mouse—side, front, and bottom profiles—and enabled the real-time tracking of multiple body parts, including the snout, left and right forelimbs, left and right hindlimbs, and the base of the tail. iv) Video frames of the behavior were processed in real-time on a GPU (Nvidia Jetson Orin), which tracked the body parts using a custom pre-trained model.

Experimental Protocol and Trial Structure

A) Experimental Protocol (detailed in Methods): In brief, 90-day-old transgenic male and female mice were implanted with a transcranial window and allowed to recover for a minimum of 7 days. Following recovery, the mice were placed in the experimental rig for approximately 45 minutes per day, for a minimum of 3 days, to undergo habituation. One day before the start of the experiment, the mice were placed on a water-restriction protocol (as detailed in Methods). Closed-loop experiment training commenced on day 1, during which mice were required to modulate either their target brain activity (GCaMP signals in regions of interest) or target behavior (tracked paw-speed) during daily sessions of approximately 45 minutes over the course of 10 days. Throughout this period, both cortical and behavioral activities were recorded. Body weight was monitored daily, and supplementary water was provided to any mouse that lost more than 1% of its body weight. After the final experimental session on day 10, the mice were removed from the water-restriction protocol.

B) Trial Structure of Cortical GCaMP-based Feedback Sessions: Each trial was preceded by a minimum of 10 seconds of rest, which was extended if the mouse was not stable. Once the mouse remained stable and refrained from moving its limbs, the trial began with a basal audio tone of 1 kHz. The mice then had 30 seconds to increase rule-based activations (in the selected ROI) up to a threshold value to receive a water reward. A trial ended as soon as the activation reached the threshold, triggering a reward delivery, or timed out after 30 seconds with an overhead buzzer serving as a negative signal. Both the reward and the negative signal were delivered within 1 second after the audio ceased at the end of each trial.

C) Dorsal Cortical ΔF/F0 Activity: Dorsal cortical ΔF/F0 activity was recorded and overlaid with a subset of Allen CCF coordinates, which could be selected as the center of candidate regions of interest (ROIs).

D) Trial Structure of Behavior Feedback Sessions: The behavioral feedback trials followed a similar structure to the cortical feedback trials, with each trial preceded by at least 10 seconds of rest. The trial began with a basal tone of 1 kHz, which increased in frequency as the mouse’s paw speed increased.

E) Forelimb Tracking during Feedback Sessions: Forelimb tracking was performed in both the left (blue) and right (green) forelimbs using a camera coordinate system on day 4 of training with mouse FM2, which received feedback based on left forelimb speed. The forelimbs were tracked in 3D, leveraging multiple camera views captured using mirrors positioned at the bottom and front of the setup (Figure 2B).

Closed-loop feedback helped mice learn the task and achieve superior performance in CLNF and CLMF in both experiments.

A) Mice (in Table 4) were able to learn the CLNF task over several sessions, with performance above 70% by the 10th session (RM ANOVA p=2.83e-5). The rule change (in pink, day 11) led to a sharp decline in performance (ANOVA, p=8.7e-9), but the mice were able to adapt and learn the task rule change (RM ANOVA p=8.3e-10; see Table 4 for different rule changes). The method to determine the ROI(s) used in the changed task rule is described in the methods section.

B) Three groups were employed for CLMF experiments. The “Rule-change” group (n=8, received feedback, in pink) was trained with task rule mapping auditory feedback to the speed of the left forelimb and was able to perform above a 70% success rate in four days. The task rule mapping was changed from the left to the right forelimb on day 5, so the rewards as well as audio frequencies would now be controlled by the right forelimb. Surprisingly, the “Rule-change” mice were able to discover the change in rule and started performing above 70% within a day of the rule change, on day 6. The “No-rule-change” group (n=4, received audio feedback, no rule change, in green) and the “No-feedback” group (n=4, no graded audio feedback, no rule change, in blue) were control groups to investigate the role of audio feedback. The performance of the “No-feedback” mice, who did not receive the graded feedback, was never on par (RM-ANOVA p=0.49) with the “No-rule-change” group that received the feedback (RM-ANOVA p=9.6e-7).

C) Task latencies in each group follow the trend of their performance. Rule change (n=8) and no rule change (n=4) task latencies gradually came down, with an exception on day 5 for rule change when the task rule was changed. No feedback (n=4) task latencies are never on par with the groups that received feedback.

D) CLMF Rule-change (n=8) behavior, we looked at the maximum speeds of the left and right forelimbs. The paw with the maximum speed follows the task rule and switches with the change in the task rule. It is worth noting that the task was not restrictive on other body parts; i.e., they were free to move other body parts along with the control point.

E) Reward-aligned average (n=4) ΔF/F0 signals associated with the target rule on day1 and day9 (top plot). Kernel density estimate (KDE) of target ΔF/F0 values during the whole session on day1 and day9 of 1-ROI experiments (bottom plot).

F) Reward-aligned average (n=4) target paw speed on day1 and day10 (top plot). Kernel density estimate (KDE) of target paw speeds on day1 and day10 (bottom plot).

G) In the context of CLNF 2-ROI experiments, bivariate distribution of ROI1 and ROI2 ΔF/F0 values during whole sessions on day9 and day19, with densities projected on the marginal axes. The task rule on day9 was “ROI1-ROI2 > thresh.” as opposed to “ROI2-ROI1 > thresh.” on day19. The bivariate distribution is significantly different (Multivariate two-sample permutation test, p=2.3e-12) on these days, indicating a robust change in activity within these brain regions.

H) Joint (bivariate) distribution of left and right paw speeds during whole session on day4 and day10 of CLMF. Left and right forelimbs were control-point (CP) on day4 and day10 respectively. There is a visible bias in the bivariate distribution towards the CP on respective days.

CLNF: Cortical activity during the closed-loop-neurofeedback training.

A) Target-rule-based ΔF/F0 traces in green on day 1 with rule-1 (top row), on day 10 with rule-1 (second row), on day 11 with new rule-2 (third row), and on day 19 with rule-2 (fourth row). Shared regions are trial periods and regions between grey areas are rest periods. The grey horizontal line depicts the threshold above which mice would receive a reward. Golden stars show the rewards received, and short vertical lines in black show the spout licks.

B) Representative reward-centered average cortical responses of the 2ROI experiment on labeled days. ROI1 (green) and ROI2 (pink) are overlaid on the brain maps. The task rule on day 1 and day 4 was “ROI1-ROI2 > thresh,” as opposed to “ROI2-ROI1 > thresh” on day 11 and day 19.

C) Linear regression on ROI1 and ROI2 ΔF/F0 during whole sessions. The regression fit inclines towards ROI1 in sessions where rule was “ROI1-ROI2 > thresh.” (day1 slope=0.44, day6 slope=0.32) while it leans towards ROI2 after the task rule switch to “ROI2-ROI1 > thresh.” (day11 slope=0.76, day17 slope=0.80).

CLMF: Speed of the tracked target body part and cortical activity.

A) Left forelimb speed (black), target threshold (grey line), and rewards (golden stars) during a sample period in a session on day 1 of the closed-loop training (top row). Shaded regions are trial periods with interspersed rest periods in white. Left forelimb speed, and rewards on day4 (second row). The target body part was changed from the left forelimb to the right forelimb on day5 (third row). Thus, day5 is the first training day with the new rule. Right forelimb speed, and rewards on day 10 of the training (fourth row).

B) Reward-centered average cortical responses on days corresponding to rows in A. The target threshold was crossed at -1 s, and the reward was delivered at 0 s. Notice the task rule change on day 5.

C) Correlation matrix showing pairwise correlations of left and right forelimb speed profiles. Top row: During rewarded trials, over the training sessions of CLMF Rule-change (left), No-rule-change (middle), and No-feedback (right). High correlations (dark cells) between speed profiles of CP indicate a unilateral bias in the movement. It is worth noting the drastic changes in correlations as the control-point was changed from left forelimb to right forelimb in Rule-change mice on day4. Bottom row: During rest periods, over the training sessions of CLMF Rule-change (left), No-rule-change (middle), and No-feedback (right).

Cortical dynamics and network changes during longitudinal CLMF training.

A) Reward-centered average responses in the olfactory bulb decrease over the days as performance increases.

B) Cortical responses become focal and closely aligned to the paw movement (green line) and reward (cyan line) events on day 10 for group-1 (received feedback) as compared to group-3 (no-feedback).

C) ΔF/F0 peak values during successful trials (pink) and during rest (cyan) over the ten-day training period in the olfactory bulb (OB) (left, day 1-day 4 p-value=0.025, day 4-day 5 p-value=0.008), forelimb area (FL) (center, day 1-day 4 p-value=0.008, day 4-day 5 p-value=0.04), and primary visual cortex (right, day 1-day 4 p-value=0.04, day 4-day 5 p-value=0.002). Statistical significance was assessed using the Mann-Whitney test and corrected for multiple comparisons with the Benjamini-Hochberg procedure.

D) Average movement (mm) of different tracked body-parts during trials in CLMF Rule-change (left), No-rule-change (center), No-feedback (right).

E) Correlations between cortical activation on each training session in barrel-cortex (BC, top left), anterolateral motor cortex (ALM, top right), secondary motor cortex (M2, bottom left), and retrosplenial cortex (RS, bottom right).

CLMF cortex-wide seed pixel correlation maps. Pairwise correlations between activity at cortical locations (also referred to as seed pixel locations).

A) Top row: No-rule-change average seed pixel correlation map during trial periods (left), during rest periods (middle), and difference of average correlation map during trial and rest (right). Bottom row: No-feedback average seed pixel correlation map during trial periods (left), during rest periods (middle), and difference of average correlation map during trial and rest (right).

B) Significant increase in pairwise seed pixel correlations as RM-ANOVA p-value (Bonferroni corrected) matrix between training sessions over the days (left) and between trial vs rest periods (right) for CLMF No-rule-change mice.

C) Significant increase in pairwise seed pixel correlations as RM-ANOVA p-value (Bonferroni corrected) matrix between training sessions over the days (left) and between trial vs rest periods (right) for CLMF No-feedback mice.

List of statistical tests performed

List of CLNF task rules with their description

List of CLMF task rules with their description

List of mice – CLNF

List of mice – CLMF