OSCR

Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

3 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.

The 3 matches
  1. [1] § Materials and Methods › Dataset › Shinobi videogame ↔ stage-2-genframes-bw.py, lines 116 to 173 · score 0.65 · Ninja Master, Shinobi III, gym, retro, frames · block oscr:b:D3JBZ99R3AW83-Z · Report a mismatch
  2. [2] § Materials and Methods › Dataset ↔ stage-2-genframes-bw.py, lines 75 to 113 · score 0.55 · Ninja Master, Shinobi III · block oscr:b:1SSTD0DDGWXR2-S · Report a mismatch
  3. [3] § Materials and Methods › Dataset › Data preprocessing ↔ stage-3-parcel-confounds9.py, lines 9 to 67 · score 0.55 · preprocessed, confounds, fMRIprep, FWHM, atlas, nilearn · block oscr:b:DJRZSPFNQZFQ9-W · Report a mismatch

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: 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

  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. # In[1]:
  4. import argparse
  5. from gym import wrappers
  6. import numpy as np
  7. import os
  8. import pickle
  9. import retro
  10. import sys
  11. import time
  12. import warnings
  13. from os import listdir
  14. from os.path import isfile, join
  15. import matplotlib.pyplot as plt
  16. import h5py
  17. import pandas as pd
  18. from PIL import Image, ImageOps
  19. # In[2]:
  20. ## HYPERPARAMETER CELL
  21. def main(args):
  22. subject= int(args[1])
  23. frame_skip = 5
  24. sequence_length = int(90/frame_skip)
  25. df_file_name_stage1 = '../temp_files/sub-'+str(subject)+'-stage-1-df.pkl'
  26. h5_store_name = '../data/bw-sub-'+str(subject)+'-len-'+str(sequence_length)+'.h5'
  27. runshapes_store_name = '../temp_files/sub-'+str(subject)+'-stage-2-runshapes-'+str(sequence_length)+'.pkl'
  28. bk2dir = '../data/shinobi.fmriprep/sourcedata/shinobi/'
  29. output_image_shape = (1,50,100)
  30. print('subject:',subject)
  31. def process_state(obs):
  32. obs = obs[50:-10,:,:] #crop
  33. obs = Image.fromarray(obs.astype(np.uint8))
  34. obs = ImageOps.grayscale(obs)
  35. obs = np.array(obs.resize((output_image_shape[2], output_image_shape[1])))
  36. obs = obs/255 # normalize
  37. obs = np.expand_dims(obs,2)
  38. obs = obs.transpose(2,0,1) # HWC to CHW
  39. return obs
  40. def process_action(action):
  41. '''
  42. Keys = [attack , special,?, ?, up, down, left, right, jump,?,?,?]
  43. '''
  44. # converting to 6 actions
  45. new_action = [0,0,0,0,0,0]
  46. if action[0]==True:
  47. new_action[0]=1
  48. if action[4]==True:
  49. new_action[1]=1
  50. if action[5]==True:
  51. new_action[2]=1
  52. if action[6]==True:
  53. new_action[3]=1
  54. if action[7]==True:
  55. new_action[4]=1
  56. if action[8]==True:
  57. new_action[5]=1
  58. new_action = int("".join(str(x) for x in new_action), 2)
  59. return new_action
  60. # In[3]:
  61. max_episode_length = 30000
  62. gym_folder = '/project/rrg-pbellec/ani686/env/lib/python3.6/site-packages/retro/data/stable/ShinobiIIIReturnOfTheNinjaMaster-Genesis/'
  63. # In[5]:
  64. allstates = np.empty((0,sequence_length,1, output_image_shape[1], output_image_shape[2]),dtype=np.float32)
  65. allactions = np.empty((0,sequence_length,1),dtype=np.float32)
  66. allsections = np.empty((0,1),dtype=np.float32)
  67. allruns = np.empty((0,1),dtype=np.float32)
  68. allreps = np.empty((0,1),dtype=np.float32)
  69. allrunnumber = np.empty((0,1),dtype=np.float32)
  70. hf = h5py.File(h5_store_name,'a')
  71. hf.create_dataset('state', data=allstates,chunks=True, maxshape=(None,sequence_length,1,output_image_shape[1], output_image_shape[2]))
  72. hf.create_dataset('action', data=allactions,chunks=True, maxshape=(None,sequence_length,1))
  73. hf.create_dataset('session', data=allsections,chunks=True, maxshape=(None,1))
  74. hf.create_dataset('run', data=allruns,chunks=True, maxshape=(None,1))
  75. hf.create_dataset('rep', data=allreps,chunks=True, maxshape=(None,1))
  76. hf.create_dataset('runnumber', data=allrunnumber,chunks=True, maxshape=(None,1))
  77. # In[6]:
  78. df = pd.read_pickle(df_file_name_stage1)
  79. # In[7]:
  80. all_files=[]
  81. for i in range(len(df)):
  82. t = bk2dir+df['bk2'][i]
  83. all_files.append(t)
  84. # In[ ]:
  85. cf=0
  86. all_shapes = []
  87. for f in all_files[:]:
  88. sess = df['session'][cf]
  89. run = df['run'][cf]
  90. rep = df['rep'][cf]
  91. level = df['level'][cf]
  92. runnumber = df['run_number'][cf]
  93. print(cf)
  94. cf+=1
  95. filename = f
  96. file = filename.replace('.bk2', '')
  97. key_log = retro.Movie(filename)
  98. frames=[]
  99. actions=[]
  100. times=[]
  101. if level==1:
  102. env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level1-0',scenario = gym_folder+'scenario1-0.json')
  103. if level==4:
  104. env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level4-1',scenario = gym_folder+'scenario4-1.json')
  105. if level==5:
  106. env = retro.make('ShinobiIIIReturnOfTheNinjaMaster-Genesis', state='Level5-0',scenario = gym_folder+'scenario5-0.json')
  107. state = env.reset()
  108. start_action=False
  109. for i in range(max_episode_length):
  110. if '.bk2' in filename:
  111. key_log.step()
  112. action = [key_log.get_key(i, 0) for i in range(env.num_buttons)]
  113. prev_state = process_state(state)
  114. dec_action = process_action(action)
  115. state, _, done, info = env.step( action )
  116. if True:
  117. if i%frame_skip == 0:
  118. frames.append(prev_state)
  119. actions.append(dec_action)
  120. if done:
  121. break
  122. if True:
  123. frames = np.float32(np.array(frames))
  124. actions_arr = np.float32(np.array(actions))
  125. actions_arr = actions_arr.reshape((actions_arr.shape[0],1))
  126. num_batches = int(frames.shape[0]/sequence_length)
  127. final_index = num_batches*sequence_length
  128. frames = frames[:final_index]
  129. frames = frames.reshape((-1,sequence_length,frames.shape[1],frames.shape[2],frames.shape[3]))
  130. actions_arr = actions_arr[:final_index]
  131. actions_arr = actions_arr.reshape((-1,sequence_length,1))
  132. sess_arr = np.array([sess]*actions_arr.shape[0]).reshape(-1,1)
  133. run_arr = np.array([run]*actions_arr.shape[0]).reshape(-1,1)
  134. rep_arr = np.array([rep]*actions_arr.shape[0]).reshape(-1,1)
  135. runnumber_arr = np.array([runnumber]*actions_arr.shape[0]).reshape(-1,1)
  136. hf["state"].resize((hf["state"].shape[0] + frames.shape[0]), axis = 0)
  137. hf["state"][-frames.shape[0]:] = frames
  138. hf["action"].resize((hf["action"].shape[0] + actions_arr.shape[0]), axis = 0)
  139. hf["action"][-actions_arr.shape[0]:] = actions_arr
  140. hf["session"].resize((hf["session"].shape[0] + sess_arr.shape[0]), axis = 0)
  141. hf["session"][-sess_arr.shape[0]:] = sess_arr
  142. hf["run"].resize((hf["run"].shape[0] + run_arr.shape[0]), axis = 0)
  143. hf["run"][-run_arr.shape[0]:] = run_arr
  144. hf["rep"].resize((hf["rep"].shape[0] + rep_arr.shape[0]), axis = 0)
  145. hf["rep"][-rep_arr.shape[0]:] = rep_arr
  146. hf["runnumber"].resize((hf["runnumber"].shape[0] + runnumber_arr.shape[0]), axis = 0)
  147. hf["runnumber"][-runnumber_arr.shape[0]:] = runnumber_arr
  148. print(frames.shape,sess,runnumber,run,rep,level,flush=True)
  149. all_shapes.append(frames.shape[0])
  150. del frames
  151. del actions
  152. del actions_arr
  153. env.close()
  154. hf.close()
  155. # In[ ]:
  156. with open(runshapes_store_name, 'wb') as f:
  157. pickle.dump(all_shapes, f)
  158. if __name__ == '__main__':
  159. main(sys.argv[:])

stage-2-genframes-bw.py at commit 0ef0d7c, no license · at the source

Overview

Authors: Anirudha Kemtur1,2,3, Francois Paugam1,2,3, Basile Pinsard3, Yann Harel3,4, Pravish Sainath1,2,3, Maximilien Le Clei3, Julie Boyle3, Karim Jerbi1,2,3,4, Lune Bellec1,2,3,4
  1. Computer Science Department, Université de Montréal, Montréal, Canada
  2. Mila – Quebec AI Institute, Montréal, Canada
  3. Centre de Recherche de l’Institut Universitaire de Gériatrie de Montréal, Montréal, Canada
  4. Psychology Department, Université de Montréal, Montréal, Canada
Journal: Imaging neuroscience (Cambridge, Mass.), volume 4, article IMAG.a.1286
Dates: received 24 July 2024; accepted 18 May 2026; published online 2 July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1162/imag.a.1286 · PMID 42440925 · PMCID PMC13334379 · OpenAlex W4388127747
Open access: diamond, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: fMRI (modality), human (organism)
Methods: Connectivity, Smoothing, state filtering, decompositions, Statistics, Machine learning, fMRI & imaging
Keywords: brain encoding, fMRI, imitation learning, naturalistic paradigms, personalized models
Topic: EEG and Brain-Computer Interfaces (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Citations: not cited yet (Europe PMC); 46 references in the paper

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

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 0ef0d7c7e90e6e77233d2714e0f1e96517e0341c, 14 October 2025
Languages: Jupyter (5), Python (4)
Size: 10 files, 9 scripts
Software Heritage: not archived
Found in: “Data and Code Availability”
Holds: README, 5 notebooks
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (9 files), pandas (8 files), Matplotlib (7 files), h5py (6 files), Nilearn (5 files), PyTorch (5 files), scikit-learn (5 files), NiBabel (4 files), Pillow (1 file), SciPy (1 file), seaborn (1 file), statsmodels (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
10 files

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://www.cneuromod.ca/. The code for the study can be found in a dedicated GitHub repository: https://github.com/anirudhk686/shinobi_imitation_learning.

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://doi.org/10.1162/imag.a.1286

BibTeX

@article{kemtur2026behavioral,
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/imag.a.1286},
url = {https://doi.org/10.1162/imag.a.1286},
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/07/02
VL - 4
SP - IMAG.a.1286
SN - 2837-6056
PB - MIT Press
DO - 10.1162/imag.a.1286
UR - https://doi.org/10.1162/imag.a.1286
LA - en
ER -

CSL-JSON

{
"id": "10.1162/imag.a.1286",
"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": "Imaging Neurosci (Camb)",
"volume": "4",
"page": "IMAG.a.1286",
"DOI": "10.1162/imag.a.1286",
"PMID": "42440925",
"PMCID": "PMC13334379",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://doi.org/10.1162/imag.a.1286",
"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.1162/imag_a_00525 [code]
Alignment of auditory artificial networks with massive individual fMRI brain data leads to generalisable improvements in brain encoding and downstream tasks.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Nilearn, Pillow, statsmodels, 8 other tools, fMRI, 6 references
[3] doi:10.1038/s41562-025-02252-z [code]
In silico discovery of representational relationships across visual cortex.
Journal: Nature human behaviour
In common: Nilearn, h5py, Pillow, 9 other tools, fMRI, 4 references
[4] doi:10.7554/elife.98047 [code]
Reconstructing voice identity from noninvasive auditory cortex recordings.
Journal: eLife
In common: Nilearn, NiBabel, PyTorch, 6 other tools, 6 references
[5] doi:10.1038/s41467-026-76098-y [code]
A single computational objective can produce specialization of streams in visual cortex.
Journal: Nature communications
In common: h5py, Pillow, statsmodels, 8 other tools, 4 references
[6] doi:10.7554/elife.82566 [code]
Statistical inference on representational geometries.
Journal: eLife
In common: Nilearn, h5py, Pillow, 8 other tools, 4 references
[7] doi:10.1126/sciadv.adw1464 [code]
Mind captioning: Evolving descriptive text of mental content from human brain activity.
Journal: Science advances
In common: h5py, Pillow, NiBabel, 7 other tools, 5 references
[8] doi:10.1038/s41597-024-04088-0 [code]
An fMRI dataset in response to large-scale short natural dynamic facial expression videos.
Journal: Scientific data
In common: Nilearn, h5py, Pillow, 8 other tools, fMRI, 3 references
[9] doi:10.7554/elife.107933 [code]
Modality-agnostic decoding of vision and language from fMRI.
Journal: eLife
In common: Nilearn, h5py, Pillow, 9 other tools, fMRI, 2 references
[10] doi:10.1038/s41467-024-50310-3 [code]
Modeling short visual events through the BOLD moments video fMRI dataset and metadata.
Journal: Nature communications
In common: Nilearn, Pillow, statsmodels, 7 other tools, fMRI, 4 references

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.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1162/imag.a.1286.svg)](https://openscicode.org/badge/doi/10.1162/imag.a.1286)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1162/imag.a.1286.svg
   :target: https://openscicode.org/badge/doi/10.1162/imag.a.1286
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1162/imag.a.1286"><img src="https://openscicode.org/badge/doi/10.1162/imag.a.1286.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

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: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.