hddm-devs / hddm

HDDM is a python module that implements Hierarchical Bayesian parameter estimation of Drift Diffusion Models (via PyMC).
http://ski.clps.brown.edu/hddm_docs/
Other
261 stars 117 forks source link

Introduction


:Author: Thomas V. Wiecki, Imri Sofer, Mads L. Pedersen, Alexander Fengler, Lakshmi Govindarajan, Krishn Bera, Michael J. Frank :Contact: thomas.wiecki@gmail.com, imri_sofer@brown.edu, madslupe@gmail.com, alexander_fengler@brown.edu, krishn_bera@brown.edu, michael_frank@brown.edu :Web site: https://hddm.readthedocs.io :Github: http://github.com/hddm-devs/hddm :Mailing list: https://groups.google.com/group/hddm-users/ :Copyright: This document has been placed in the public domain. :License: HDDM is released under the BSD 2 license. :Version: 1.0.1

.. image:: https://secure.travis-ci.org/hddm-devs/hddm.png?branch=master

Purpose

HDDM is a python toolbox for hierarchical Bayesian parameter estimation of the Drift Diffusion Model (via PyMC). Drift Diffusion Models are used widely in psychology and cognitive neuroscience to study decision making.

Check out the tutorial on how to get started. Further information can be found below as well as in the howto section and the documentation_.

Features

Comparison to other packages

A recent paper by Roger Ratcliff quantitatively compared DMAT, fast-dm, and EZ, and concluded: "We found that the hierarchical diffusion method [as implemented by HDDM] performed very well, and is the method of choice when the number of observations is small."

Find the paper here: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4517692/

Quick-start

The following is a minimal python script to load data, run a model and examine its parameters and fit.

::

import hddm

Load data from csv file into a NumPy structured array

data = hddm.load_csv('simple_difficulty.csv')

Create a HDDM model multi object

model = hddm.HDDM(data, depends_on={'v':'difficulty'})

Create model and start MCMC sampling

model.sample(2000, burn=20)

Print fitted parameters and other model statistics

model.print_stats()

Plot posterior distributions and theoretical RT distributions

model.plot_posteriors() model.plot_posterior_predictive()

For more information about the software and theories behind it, please see the main publication_.

Installation

For HDDM >= 0.9.0, currently in beta release, the most convenient way to install HDDM, is to directly install via github. In a fresh environment (we recommend to use python 3.7) type.

We recommend you to open a conda environment first.

::

conda create -n hddm python=3.7
conda activate hddm

If you do not have hdf5 or netcdf4 installed, you can use conda to install them.

::

conda install -c conda-forge hdf5
conda install -c conda-forge netcdf4

Then install hddm via github.

::

pip install "numpy < 1.23.0"
pip install "cython <1.0.0"
pip install pymc==2.3.8 # backend probabilistic programming framework (DO NOT USE CONDA HERE)
# pip install git+https://github.com/hddm-devs/kabuki # (Optional, the pip version as dependency of HDDM should work)
pip install hddm # main package

# Optional
pip install torch torchvision torchaudio # The LAN extension makes use of these

To make use of the LAN fuctionalities, you need to install pytorch_.

:: pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1

A common issue on new machines is that the installation of the pymc package (a necessary dependency), is hampered by problems with compiling its fortran code. Try downgrading the version of your gcc compiler. This can be done on a MAC (not the new M1/M2 versions tragically), via

::

brew install gcc@9

In case you do not have the brew command, install Homebrew <https://brew.sh/>_ first.

You usually do not run into problems with linux machines, however downgrading gcc can still be necessary.

(Previous instructions for HDDM <= 0.8.0, DISCOURAGED) As of release 0.6.0, HDDM is compatible with Python 3 which we encourage.

The easiest way to install HDDM is through Anaconda (available for Windows, Linux and OSX):

  1. Download and install Anaconda_.
  2. In a shell (Windows: Go to Start->Programs->Anaconda->Anaconda command prompt) type:

::

conda install -c pymc hddm

If you want to use pip instead of conda, type:

::

pip install pandas
pip install pymc==2.3.8
pip install kabuki
pip install hddm

This might require super-user rights via sudo. Note that this installation method is discouraged as it leads to all kinds of problems on various platforms.

If you are having installation problems please contact the mailing list_.

And if you're a mac user, check out this thread_ for advice on installation.

How to cite

If HDDM was used in your research, please cite the main publication_:

Wiecki TV, Sofer I and Frank MJ (2013). HDDM: Hierarchical Bayesian estimation of the Drift-Diffusion Model in Python. Front. Neuroinform. 7:14. doi: 10.3389/fninf.2013.00014

If you use the HDDMrl, please cite the original HDDM RL tutorial paper_:

Pedersen, M. L., & Frank, M. J. (2020). Simultaneous hierarchical bayesian parameter estimation for reinforcement learning and drift diffusion models: a tutorial and links to neural data. Computational Brain & Behavior, 3(4), 458-471.

If you use any of the HDDMnn, HDDMnnRegressor, HDDMnnStimCoding or HDDMnnRL classes, please cite the lan extension and the new tutorial paper:

Alexander Fengler, Lakshmi N Govindarajan, Tony Chen, Michael J Frank (2021). Likelihood approximation networks (LANs) for fast inference of simulation models in cognitive neuroscience. eLife 10:e65074. doi: 10.7554/eLife.65074

Fengler, A., Bera, K., Pedersen, M. L., & Frank, M. J. (2022). Beyond Drift Diffusion Models: Fitting a Broad Class of Decision and Reinforcement Learning Models with HDDM. Journal of Cognitive Neuroscience, 34(10), 1780-1805.

Published papers using HDDM

HDDM has been used in over 400 published papers_.

Testimonials

James Rowe (Cambridge University): "The HDDM modelling gave insights into the effects of disease that were simply not visible from a traditional analysis of RT/Accuracy. It provides a clue as to why many disorders including PD and PSP can give the paradoxical combination of akinesia and impulsivity. Perhaps of broader interest, the hierarchical drift diffusion model turned out to be very robust. In separate work, we have found that the HDDM gave accurate estimates of decision parameters with many fewer than 100 trials, in contrast to the hundreds or even thousands one might use for ‘traditional’ DDMs. This meant it was realistic to study patients who do not tolerate long testing sessions."

Getting started

Check out the tutorial on how to get started. Further information can be found in howto and the documentation_.

Join our low-traffic mailing list_.

.. _likelihood approximation networks: https://elifesciences.org/articles/65074 .. _pytorch: http://pytorch.org .. _HDDM: http://code.google.com/p/hddm/ .. _Python: http://www.python.org/ .. _PyMC: http://pymc-devs.github.com/pymc/ .. _Cython: http://www.cython.org/ .. _DMAT: http://ppw.kuleuven.be/okp/software/dmat/ .. _fast-dm: http://seehuhn.de/pages/fast-dm .. _documentation: https://hddm.readthedocs.io .. _tutorial: https://hddm.readthedocs.io/en/latest/tutorial_basic_hddm.html .. _howto: https://hddm.readthedocs.io/en/latest/howto.html .. _manual: http://ski.clps.brown.edu/hddm_docs/manual.html .. _kabuki: https://github.com/hddm-devs/kabuki .. _mailing list: https://groups.google.com/group/hddm-users/ .. _SciPy Superpack: http://fonnesbeck.github.com/ScipySuperpack/ .. _Anaconda: http://docs.continuum.io/anaconda/install.html .. _main publication: http://www.frontiersin.org/Journal/10.3389/fninf.2013.00014/abstract .. _lan extension: https://elifesciences.org/articles/65074 .. _new tutorial paper: https://direct.mit.edu/jocn/article/34/10/1780/112585/Beyond-Drift-Diffusion-Models-Fitting-a-Broad .. _original HDDM RL tutorial paper: https://link.springer.com/article/10.1007/s42113-020-00084-w .. _published papers: https://scholar.google.com/scholar?oi=bibs&hl=en&cites=17737314623978403194 .. _thread: https://groups.google.com/forum/#!topic/hddm-users/bdQXewfUzLs .. _ssms: https://github.com/AlexanderFengler/ssms