Skip to main content

NeuroGym: Gymnasium-style Cognitive Neuroscience Tasks

Project description

NeuroGym

Badges
fairness OpenSSF Best Practices fair-software.eu
package PyPI version
docs Documentation RSD DOI
tests build sonarcloud linkspector cffconvert linting static-typing workflow scq badge workflow scc badge
running on ubuntu
license github license badge

NeuroGym is a curated collection of neuroscience tasks with a common interface. The goal is to facilitate the training of neural network models on neuroscience tasks.

NeuroGym inherits from the machine learning toolkit Gymnasium, a maintained fork of OpenAI’s Gym library. It allows a wide range of well established machine learning algorithms to be easily trained on behavioral paradigms relevant for the neuroscience community. NeuroGym also incorporates several properties and functions (e.g. continuous-time and trial-based tasks) that are important for neuroscience applications. The toolkit also includes various modifier functions that allow easy configuration of new tasks.

Please see our extended project documentation for additional details.

alt tag

Installation

Step 1: Create a virtual environment

Create and activate a virtual environment to install the current package, e.g. using conda (please refer to their site for questions about creating the environment):

conda activate # ensures you are in the base environment
conda create -n neurogym python=3.11 -y
conda activate neurogym

Step 2: Install neurogym

Then install the latest version of neurogym as follows:

pip install neurogym
Step 2b: Install editable package

Alternatively, get the latest updates by cloning the repo and installing the editable version of neurogym, by replacing step 2 above by:

git clone https://github.com/neurogym/neurogym.git
cd neurogym
pip install -e .

Step 3 (Optional): Psychopy installation

NOTE: psycohopy installation is currently not working

If you need psychopy for your project, additionally run

pip install psychopy

Tasks

Currently implemented tasks can be found here.

Wrappers

Wrappers (see list) are short scripts that allow introducing modifications the original tasks. For instance, the Random Dots Motion task can be transformed into a reaction time task by passing it through the reaction_time wrapper. Alternatively, the combine wrapper allows training an agent in two different tasks simultaneously.

Examples

NeuroGym is compatible with most packages that use gymnasium. In this example jupyter notebook we show how to train a neural network with reinforcement learning algorithms using the Stable-Baselines3 toolbox.

Custom tasks

Creating custom new tasks should be easy. You can contribute tasks using the regular gymnasium format. If your task has a trial/period structure, this template provides the basic structure that we recommend a task to have:

from gymnasium import spaces
import neurogym as ngym

class YourTask(ngym.PeriodEnv):
    metadata = {}

    def __init__(self, dt=100, timing=None, extra_input_param=None):
        super().__init__(dt=dt)


    def new_trial(self, **kwargs):
        """
        new_trial() is called when a trial ends to generate the next trial.
        Here you have to set:
        The trial periods: fixation, stimulus...
        Optionally, you can set:
        The ground truth: the correct answer for the created trial.
        """

    def _step(self, action):
        """
        _step receives an action and returns:
            a new observation, obs
            reward associated with the action, reward
            a boolean variable indicating whether the experiment has terminated, terminated
                See more at https://gymnasium.farama.org/tutorials/gymnasium_basics/handling_time_limits/#termination
            a boolean variable indicating whether the experiment has been truncated, truncated
                See more at https://gymnasium.farama.org/tutorials/gymnasium_basics/handling_time_limits/#truncation
            a dictionary with extra information:
                ground truth correct response, info['gt']
                boolean indicating the end of the trial, info['new_trial']
        """

        return obs, reward, terminated, truncated, {'new_trial': new_trial, 'gt': gt}

Acknowledgements

For the authors of the package, please refer to the zenodo DOI at the top of the page.

Other contributors (listed in chronological order)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neurogym-1.0.5.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neurogym-1.0.5-py3-none-any.whl (115.9 kB view details)

Uploaded Python 3

File details

Details for the file neurogym-1.0.5.tar.gz.

File metadata

  • Download URL: neurogym-1.0.5.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for neurogym-1.0.5.tar.gz
Algorithm Hash digest
SHA256 3f23a390d5d7cd65ec9f7a1bafa26dca5eeb73fd5b7166a622de5af57c365915
MD5 5996749a77793378e5c0f471bddc70b0
BLAKE2b-256 e514ed040f35c3048de66d827d42357b75d282c3481166df8992e5d1292719ca

See more details on using hashes here.

File details

Details for the file neurogym-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: neurogym-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 115.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for neurogym-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a1ff341db65f4998559eaf76d5e09086bf963fa95b49d05c53041b8e8f172a8f
MD5 6c59418bcec4e2e72a20afaf1e836367
BLAKE2b-256 4681e14a5a5c4912bab32059e3196bab21e80f03fc19f9415a39a810cc103206

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page