Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play.
The 3 matches
- [1] § Materials and Methods › Dataset › Shinobi videogame ↔ stage-2-genframes-bw.py, lines 116–173 · score 0.65 · Ninja Master, Shinobi III, gym, retro, frames
- [2] § Materials and Methods › Dataset ↔ stage-2-genframes-bw.py, lines 75–113 · score 0.55 · Ninja Master, Shinobi III
- [3] § Materials and Methods › Dataset › Data preprocessing ↔ stage-3-parcel-confounds9.py, lines 9–67 · score 0.55 · preprocessed, confounds, fMRIprep, FWHM, atlas, nilearn
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 240 lines · 6.8 KB · no license · 2 matches
- #!/usr/bin/env python
- # coding: utf-8
- # In[1]:
- import argparse
- from gym import wrappers
- import numpy as np
- import os
- import pickle
- import retro
- import sys
- import time
- import warnings
- from os import listdir
- from os.path import isfile, join
- import matplotlib.pyplot as plt
- import h5py
- import pandas as pd
- from PIL import Image, ImageOps
- # In[2]:
- ## HYPERPARAMETER CELL
- def main(args):
- subject= int(args[1])
- frame_skip = 5
- sequence_length = int(90/frame_skip)
- df_file_name_stage1 = '../temp_files/sub-'+str(subject)+'-stage-1-df.pkl'
- h5_store_name = '../data/bw-sub-'+str(subject)+'-len-'+str(sequence_length)+'.h5'
- runshapes_store_name = '../temp_files/sub-'+str(subject)+'-stage-2-runshapes-'+str(sequence_length)+'.pkl'
- bk2dir = '../data/shinobi.fmriprep/sourcedata/shinobi/'
- output_image_shape = (1,50,100)
- print('subject:',subject)
- def process_state(obs):
- obs = obs[50:-10,:,:] #crop
- obs = Image.fromarray(obs.astype(np.uint8))
- obs = ImageOps.grayscale(obs)
- obs = np.array(obs.resize((output_image_shape[2], output_image_shape[1])))
- obs = obs/255 # normalize
- obs = np.expand_dims(obs,2)
- obs = obs.transpose(2,0,1) # HWC to CHW
- return obs
- def process_action(action):
- '''
- Keys = [attack , special,?, ?, up, down, left, right, jump,?,?,?]
- '''
- # converting to 6 actions
- new_action = [0,0,0,0,0,0]
- if action[0]==True:
- new_action[0]=1
- if action[4]==True:
- new_action[1]=1
- if action[5]==True:
- new_action[2]=1
- if action[6]==True:
- new_action[3]=1
- if action[7]==True:
- new_action[4]=1
- if action[8]==True:
- new_action[5]=1
- new_action = int("".join(str(x) for x in new_action), 2)
- return new_action
- # In[3]:
- max_episode_length = 30000
- gym_folder = '/project/rrg-pbellec/ani686/env/lib/python3.6/site-packages/retro/data/stable/ShinobiIIIReturnOfTheNinjaMaster-Genesis/'
- # In[5]:
- allstates = np.empty((0,sequence_length,1, output_image_shape[1], output_image_shape[2]),dtype=np.float32)
- allactions = np.empty((0,sequence_length,1),dtype=np.float32)
- allsections = np.empty((0,1),dtype=np.float32)
- allruns = np.empty((0,1),dtype=np.float32)
- allreps = np.empty((0,1),dtype=np.float32)
- allrunnumber = np.empty((0,1),dtype=np.float32)
- hf = h5py.File(h5_store_name,'a')
- hf.create_dataset('state', data=allstates,chunks=True, maxshape=(None,sequence_length,1,output_image_shape[1], output_image_shape[2]))
- hf.create_dataset('action', data=allactions,chunks=True, maxshape=(None,sequence_length,1))
- hf.create_dataset('session', data=allsections,chunks=True, maxshape=(None,1))
- hf.create_dataset('run', data=allruns,chunks=True, maxshape=(None,1))
- hf.create_dataset('rep', data=allreps,chunks=True, maxshape=(None,1))
- hf.create_dataset('runnumber', data=allrunnumber,chunks=True, maxshape=(None,1))
- # In[6]:
- df = pd.read_pickle(df_file_name_stage1)
- # In[7]:
- all_files=[]
- for i in range(len(df)):
- t = bk2dir+df['bk2'][i]
- all_files.append(t)
- # In[ ]:
- cf=0
- all_shapes = []
- for f in all_files[:]:
- sess = df['session'][cf]
- run = df['run'][cf]
- rep = df['rep'][cf]
- level = df['level'][cf]
- runnumber = df['run_number'][cf]
- print(cf)
- cf+=1
- filename = f
- file = filename.replace('.bk2', '')
- key_log = retro.Movie(filename)
- frames=[]
- actions=[]
- times=[]
- if level==1:
- env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level1-0',scenario = gym_folder+'scenario1-0.json')
- if level==4:
- env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level4-1',scenario = gym_folder+'scenario4-1.json')
- if level==5:
- env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level5-0',scenario = gym_folder+'scenario5-0.json')
- state = env.reset()
- start_action=False
- for i in range(max_episode_length):
- if '.bk2' in filename:
- key_log.step()
- action = [key_log.get_key(i, 0) for i in range(env.num_buttons)]
- prev_state = process_state(state)
- dec_action = process_action(action)
- state, _, done, info = env.step( action )
- if True:
- if i%frame_skip == 0:
- frames.append(prev_state)
- actions.append(dec_action)
- if done:
- break
- if True:
- frames = np.float32(np.array(frames))
- actions_arr = np.float32(np.array(actions))
- actions_arr = actions_arr.reshape((actions_arr.shape[0],1))
- num_batches = int(frames.shape[0]/sequence_length)
- final_index = num_batches*sequence_length
- frames = frames[:final_index]
- frames = frames.reshape((-1,sequence_length,frames.shape[1],frames.shape[2],frames.shape[3]))
- actions_arr = actions_arr[:final_index]
- actions_arr = actions_arr.reshape((-1,sequence_length,1))
- sess_arr = np.array([sess]*actions_arr.shape[0]).reshape(-1,1)
- run_arr = np.array([run]*actions_arr.shape[0]).reshape(-1,1)
- rep_arr = np.array([rep]*actions_arr.shape[0]).reshape(-1,1)
- runnumber_arr = np.array([runnumber]*actions_arr.shape[0]).reshape(-1,1)
- hf["state"].resize((hf["state"].shape[0] + frames.shape[0]), axis = 0)
- hf["state"][-frames.shape[0]:] = frames
- hf["action"].resize((hf["action"].shape[0] + actions_arr.shape[0]), axis = 0)
- hf["action"][-actions_arr.shape[0]:] = actions_arr
- hf["session"].resize((hf["session"].shape[0] + sess_arr.shape[0]), axis = 0)
- hf["session"][-sess_arr.shape[0]:] = sess_arr
- hf["run"].resize((hf["run"].shape[0] + run_arr.shape[0]), axis = 0)
- hf["run"][-run_arr.shape[0]:] = run_arr
- hf["rep"].resize((hf["rep"].shape[0] + rep_arr.shape[0]), axis = 0)
- hf["rep"][-rep_arr.shape[0]:] = rep_arr
- hf["runnumber"].resize((hf["runnumber"].shape[0] + runnumber_arr.shape[0]), axis = 0)
- hf["runnumber"][-runnumber_arr.shape[0]:] = runnumber_arr
- print(frames.shape,sess,runnumber,run,rep,level,flush=True)
- all_shapes.append(frames.shape[0])
- del frames
- del actions
- del actions_arr
- env.close()
- hf.close()
- # In[ ]:
- with open(runshapes_store_name, 'wb') as f:
- pickle.dump(all_shapes, f)
- if __name__ == '__main__':
- main(sys.argv[:])
stage-2-genframes-bw.py at commit 0ef0d7c, no license · at the source
Overview
- Computer Science Department, Université de Montréal, Montréal, Canada
- Mila – Quebec AI Institute, Montréal, Canada
- Centre de Recherche de l’Institut Universitaire de Gériatrie de Montréal, Montréal, Canada
- Psychology Department, Université de Montréal, Montréal, Canada
Abstract
Videogames provide a promising framework to understand brain activity in a rich, engaging, and active environment, in contrast to mostly passive tasks currently dominating the field, such as image viewing. Analyzing videogames neuroimaging data is, however, challenging, and relies on time-intensive manual annotations of game events, based on somewhat arbitrary rules. Here, we introduce an innovative approach using Artificial Neural networks (ANN) and brain encoding techniques to generate activation maps associated with videogame behavior using functional magnetic resonance imaging (fMRI). As individual behavior is highly variable across subjects in complex environments, we hypothesized that ANNs need to account for subject-specific behavior to capture brain dynamics properly. In this study, we used data collected while subjects played Shinobi III: Return of the Ninja Master (an action-platformer released by Sega in 1993), an action-platformer videogame. Using imitation learning, we trained an ANN to play the game while closely replicating the unique gameplay style of individual participants. We found that hidden layers of our imitation learning model successfully encoded task-relevant neural representations, and predicted individual brain dynamics with higher accuracy than models trained on other subjects’ gameplay. Individual-specific models also outperformed several baselines to predict brain activity, such as pixel inputs, or button presses. The highest correlations between layer activations and brain signals were observed in biologically plausible brain areas, that is, somatosensory, attention, and visual networks. This work thus demonstrates that subject-specific imitation models can be trained from scratch and improve brain encoding in an active naturalistic task. Our framework builds on a commercial videogame of unprecedented complexity in the fMRI brain encoding literature. We used a flexible game emulator that supports a broad range of commercial videogames, opening new naturalistic interactive environments for cognitive neuroscience.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.
anirudhk686/shinobi_imitation_learning
0ef0d7c7e90e6e77233d2714e0f1e96517e0341c, 14 October 2025Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
10 files
- stage-1-read-tsv.ipynb, Jupyter, 125 lines
- stage-2-genframes-bw.py, Python, 240 lines, 2 matches
- stage-3-parcel-confounds
9.py , Python, 73 lines, 1 match - stage-4-train-model-othe
r.py , Python, 222 lines - stage-4-train-model-sess
.py , Python, 237 lines - stage-5-6-7-action.ipynb
, Jupyter, 358 lines - stage-5-6-7-pixel.ipynb, Jupyter, 315 lines
- stage-5-6-7-trained.ipyn
b , Jupyter, 450 lines - stage-9-signi+timelag_te
st.ipynb , Jupyter, 226 lines - README.md, Text, 3 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 9 scripts, each with its path and the digest of its content;
- 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data and Code Availability
Data used in the paper can be requested through Cneuromod website: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 9 authors, 5 keywords, 2 funders, 45 references.
Cite
This paper
Kemtur, A., Paugam, F., Pinsard, B., Harel, Y., Sainath, P., Clei, M. L., Boyle, J., Jerbi, K., & Bellec, L. (2026). Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play. Imaging neuroscience (Cambridge, Mass.), 4, IMAG.a.1286. https://
BibTeX
@article{kemtur2026behav
author = {Kemtur, Anirudha and Paugam, Francois and Pinsard, Basile and Harel, Yann and Sainath, Pravish and Clei, Maximilien Le and Boyle, Julie and Jerbi, Karim and Bellec, Lune},
title = {{Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play}},
journal = {Imaging neuroscience (Cambridge, Mass.)},
year = {2026},
month = jul,
volume = {4},
pages = {IMAG.a.1286},
publisher = {MIT Press},
issn = {2837-6056},
doi = {10.1162/
url = {https://
pmid = {42440925},
pmcid = {PMC13334379}
}
RIS
TY - JOUR
AU - Kemtur, Anirudha
AU - Paugam, Francois
AU - Pinsard, Basile
AU - Harel, Yann
AU - Sainath, Pravish
AU - Clei, Maximilien Le
AU - Boyle, Julie
AU - Jerbi, Karim
AU - Bellec, Lune
TI - Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play
T2 - Imaging neuroscience (Cambridge, Mass.)
J2 - Imaging Neurosci (Camb)
PY - 2026
DA - 2026/
VL - 4
SP - IMAG.a.1286
SN - 2837-6056
PB - MIT Press
DO - 10.1162/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1162/
"type": "article-journal",
"title": "Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play",
"container-title": "Imaging neuroscience (Cambridge, Mass.)",
"author": [
{
"family": "Kemtur",
"given": "Anirudha"
},
{
"family": "Paugam",
"given": "Francois"
},
{
"family": "Pinsard",
"given": "Basile"
},
{
"family": "Harel",
"given": "Yann"
},
{
"family": "Sainath",
"given": "Pravish"
},
{
"family": "Clei",
"given": "Maximilien Le"
},
{
"family": "Boyle",
"given": "Julie"
},
{
"family": "Jerbi",
"given": "Karim"
},
{
"family": "Bellec",
"given": "Lune"
}
],
"container-title-short":
"volume": "4",
"page": "IMAG.a.1286",
"DOI": "10.1162/
"PMID": "42440925",
"PMCID": "PMC13334379",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
2
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1162/imag.a.1256 [code]
- Gamer in the scanner: Event-related analysis of fMRI activity during retro videogame play guided by automated annotations of game content.Journal: Imaging neuroscience (Cambridge, Mass.)In common: Nilearn, Pillow, statsmodels, 8 other tools, fMRI, 14 references
- [2] doi:10.1038/s41467-026-76098-y [code]
- A single computational objective can produce specialization of streams in visual cortex.Journal: Nature communicationsIn common: h5py, Pillow, statsmodels, 8 other tools, 4 references
- [3] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: Nilearn, h5py, Pillow, 9 other tools, fMRI, 2 references
- [4] doi:10.1016/j.isci.2026.117180 [code]
- Developmental changes in similarity between neural representations of mental arithmetic and artificial neural networks.Journal: iScienceIn common: Nilearn, h5py, statsmodels, 8 other tools, fMRI, 3 references
- [5] doi:10.1167/jov.26.5.7 [code]
- Representations in vision and language converge in a shared, multidimensional space of perceived similarities.Journal: Journal of visionIn common: Nilearn, h5py, Pillow, 9 other tools, 2 references
- [6] doi:10.1038/s42003-026-10169-0 [code]
- Shared representations in brains and models reveal a two-route cortical organization during scene perception.Journal: Communications biologyIn common: h5py, Pillow, statsmodels, 8 other tools, 3 references
- [7] doi:10.1162/nol.a.271 [code]
- Compositional Complexity in Text and Images.Journal: Neurobiology of language (Cambridge, Mass.)In common: Nilearn, Pillow, NiBabel, 7 other tools, fMRI, 4 references
- [8] doi:10.1162/imag.a.1309 [code]
- Probing the content of semantic representations in body-selective regions.Journal: Imaging neuroscience (Cambridge, Mass.)In common: h5py, Pillow, statsmodels, 8 other tools, 2 references
- [9] doi:10.1007/s12021-026-09803-3 [code]
- NeuroFusion: A Unified Framework for Generalized Visual Stimulus Decoding from fMRI Across Datasets and Subjects.Journal: NeuroinformaticsIn common: Nilearn, h5py, Pillow, 7 other tools, fMRI, 2 references
- [10] doi:10.1002/agm2.70073 [code]
- Foreign Language Learning in Older Adults Modifies Resting-State Functional Connectivity Between the Subcortical Structures and the Cortex.Journal: Aging medicine (Milton (N.S.W))In common: Nilearn, h5py, Pillow, 9 other tools, fMRI
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 9 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:3c5136f38315971b…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
