Skip to main content

SSMS is a package collecting simulators and training data generators for a bunch of generative models of interest in the cognitive science / neuroscience and approximate bayesian computation communities

Project description

SSMS (Sequential Sampling Model Simulators)

Python Package which collects simulators for Sequential Sampling Models.

Find the package documentation here.

PyPI PyPI_dl Code style: black License: MIT

Quick Start

The ssms package serves two purposes.

  1. Easy access to fast simulators of sequential sampling models
  2. Support infrastructure to construct training data for various approaches to likelihood / posterior amortization

We provide two minimal examples here to illustrate how to use each of the two capabilities.

Install

Let's start with installing the ssms package.

You can do so by typing,

pip install git+https://github.com/AlexanderFengler/ssm_simulators

in your terminal.

Below you find a basic tutorial on how to use the package.

Tutorial

# Import necessary packages
import numpy as np
import pandas as pd
import ssms

Using the Simulators

Let's start with using the basic simulators. You access the main simulators through the ssms.basic_simulators.simulator function.

To get an idea about the models included in ssms, use the config module. The central dictionary with metadata about included models sits in ssms.config.model_config.

# Check included models
list(ssms.config.model_config.keys())[:10]
['ddm',
 'ddm_legacy',
 'angle',
 'weibull',
 'levy',
 'levy_angle',
 'full_ddm',
 'ornstein',
 'ornstein_angle',
 'ddm_sdv']
# Take an example config for a given model
ssms.config.model_config['ddm']
{'name': 'ddm',
 'params': ['v', 'a', 'z', 't'],
 'param_bounds': [[-3.0, 0.3, 0.1, 0.0], [3.0, 2.5, 0.9, 2.0]],
 'boundary': <function ssms.basic_simulators.boundary_functions.constant(t=0)>,
 'n_params': 4,
 'default_params': [0.0, 1.0, 0.5, 0.001],
 'hddm_include': ['z'],
 'nchoices': 2}

Note: The usual structure of these models includes,

  • Parameter names ('params')
  • Bounds on the parameters ('param_bounds')
  • A function that defines a boundary for the respective model ('boundary')
  • The number of parameters ('n_params')
  • Defaults for the parameters ('default_params')
  • The number of choices the process can produce ('nchoices')

The 'hddm_include' key concerns information useful for integration with the hddm python package, which facilitates hierarchical bayesian inference for sequential sampling models. It is not important for the present tutorial.

from ssms.basic_simulators.simulator import simulator
sim_out = simulator(model = 'ddm', 
                    theta = {'v': 0, 
                             'a': 1,
                             'z': 0.5,
                             't': 0.5,
                    },
                    n_samples = 1000)

The output of the simulator is a dictionary with three elements.

  1. rts (array)
  2. choices (array)
  3. metadata (dictionary)

The metadata includes the named parameters, simulator settings, and more.

Using the Training Data Generators

The training data generators sit on top of the simulator function to turn raw simulations into usable training data for training machine learning algorithms aimed at posterior or likelihood armortization.

We will use the data_generator class from ssms.dataset_generators. Initializing the data_generator boils down to supplying two configuration dictionaries.

  1. The generator_config, concerns choices as to what kind of training data one wants to generate.
  2. The model_config concerns choices with respect to the underlying generative sequential sampling model.

We will consider a basic example here, concerning data generation to prepare for training LANs.

Let's start by peeking at an example generator_config.

ssms.config.data_generator_config['lan']['mlp']
{'output_folder': 'data/lan_mlp/',
 'dgp_list': 'ddm',
 'nbins': 0,
 'n_samples': 100000,
 'n_parameter_sets': 10000,
 'n_parameter_sets_rejected': 100,
 'n_training_samples_by_parameter_set': 1000,
 'max_t': 20.0,
 'delta_t': 0.001,
 'pickleprotocol': 4,
 'n_cpus': 'all',
 'kde_data_mixture_probabilities': [0.8, 0.1, 0.1],
 'simulation_filters': {'mode': 20,
  'choice_cnt': 0,
  'mean_rt': 17,
  'std': 0,
  'mode_cnt_rel': 0.9},
 'negative_rt_cutoff': -66.77497,
 'n_subruns': 10,
 'bin_pointwise': False,
 'separate_response_channels': False}

You usually have to make just few changes to this basic configuration dictionary. An example below.

from copy import deepcopy
# Initialize the generator config (for MLP LANs)
generator_config = deepcopy(ssms.config.data_generator_config['lan']['mlp'])
# Specify generative model (one from the list of included models mentioned above)
generator_config['dgp_list'] = 'angle' 
# Specify number of parameter sets to simulate
generator_config['n_parameter_sets'] = 100 
# Specify how many samples a simulation run should entail
generator_config['n_samples'] = 1000

Now let's define our corresponding model_config.

model_config = ssms.config.model_config['angle']
print(model_config)
{'name': 'angle', 'params': ['v', 'a', 'z', 't', 'theta'], 
'param_bounds': [[-3.0, 0.3, 0.1, 0.001, -0.1], [3.0, 3.0, 0.9, 2.0, 1.3]], 
'boundary': <function angle at 0x11b2a7c10>, 
'n_params': 5, 
'default_params': [0.0, 1.0, 0.5, 0.001, 0.0], 
'hddm_include': ['z', 'theta'], 'nchoices': 2}

We are now ready to initialize a data_generator, after which we can generate training data using the generate_data_training_uniform function, which will use the hypercube defined by our parameter bounds from the model_config to uniformly generate parameter sets and corresponding simulated datasets.

my_dataset_generator = ssms.dataset_generators.data_generator(generator_config = generator_config,
                                                              model_config = model_config)
n_cpus used:  6
checking:  data/lan_mlp/
training_data = my_dataset_generator.generate_data_training_uniform(save = False)
simulation round: 1  of 10
simulation round: 2  of 10
simulation round: 3  of 10
simulation round: 4  of 10
simulation round: 5  of 10
simulation round: 6  of 10
simulation round: 7  of 10
simulation round: 8  of 10
simulation round: 9  of 10
simulation round: 10  of 10

training_data is a dictionary containing four keys:

  1. data the features for LANs, containing vectors of model parameters, as well as rts and choices.
  2. labels which contain approximate likelihood values
  3. generator_config, as defined above
  4. model_config, as defined above

You can now use this training data for your purposes. If you want to train LANs yourself, you might find the LANfactory package helpful.

You may also simply find the basic simulators provided with the ssms package useful, without any desire to use the outputs into training data for amortization purposes.

END

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

ssm_simulators-0.7.2.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

ssm_simulators-0.7.2-cp311-cp311-win_amd64.whl (348.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.2-cp311-cp311-musllinux_1_1_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.2-cp311-cp311-macosx_11_0_arm64.whl (413.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_x86_64.whl (479.6 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_universal2.whl (859.6 kB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

ssm_simulators-0.7.2-cp310-cp310-win_amd64.whl (346.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.7.2-cp310-cp310-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.2-cp310-cp310-macosx_11_0_arm64.whl (412.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_x86_64.whl (479.1 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_universal2.whl (858.0 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

ssm_simulators-0.7.2-cp39-cp39-win_amd64.whl (346.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.7.2-cp39-cp39-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.2-cp39-cp39-macosx_11_0_arm64.whl (413.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_x86_64.whl (481.2 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_universal2.whl (861.9 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file ssm_simulators-0.7.2.tar.gz.

File metadata

  • Download URL: ssm_simulators-0.7.2.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for ssm_simulators-0.7.2.tar.gz
Algorithm Hash digest
SHA256 b9504349866e8b777275d591ff8689e1d0fbc8b0947e168af378680a2613a7b1
MD5 91d9555028314e1aa0ac14f40481c7d4
BLAKE2b-256 dde17f8e431d689ae613ad2fdd7cd5927d62c27685ee84cb99a4daef6c75a08e

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f48226bcb0f915c5fac042012847572a7df9bafb80077167c9c97902bc658bc3
MD5 1e3ccc2de411f19acbd1ab15507979c4
BLAKE2b-256 0226ef2e0a19097c76608a0b6b703e8b4a381d4c00172d8506c95224c354b39c

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ad4a79344189647f726f4b2347c72d16f9fc6153559424343d4bd9ec61fc00b8
MD5 d39f4f5e0a523ca2392e8a749ce4ef70
BLAKE2b-256 f4cefc77df244168cd33d8b25175b1853f5ccc0b4b3dffd83727775ed3bf4c6c

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c5d8173f0399f74ea55c3317e2a52dbdd966534f947ff2b3412cad38c7cb0fd
MD5 a658b2ab5cb6b50b1d47dbe7f3294590
BLAKE2b-256 4225de084e4b919a3768257c64ffc8c897d261c7070d3c5c971be3f7ffaa15b6

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0670aeb15b1f795f9570ee94d925ae0c5201abaa0b63f7213e68088428a846e
MD5 90217a2de708dd0f0218baadf15b0723
BLAKE2b-256 94ea5a58fd373e176c5dd12c80a7f0b2c6695dd07ed678bd49f1134bee723630

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5327abc20e18f2015adcbf11631c4dd32403ce2c04f8bb005e2745485497b53e
MD5 8bf8216ee3e53b07399d142de1f97f39
BLAKE2b-256 7322520998f2ffb13fc882338dd16db5b109eb6eea7ae45301bd1ffdc4b4f4ef

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 62985b19096c5a0e83c91d34270235174e58db439a79a8b7d369b25d18fe8cf9
MD5 e6b8e20d4729c97cfaa816f2a3a3142e
BLAKE2b-256 7c973ad4cbf30949165404412f9061138cc22c510140cb7ce21352fc3fe127ea

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a41c7fc7bfe4d963dd98abc4e198d9af4d1e8c46a9c81934d263e90226044a19
MD5 b08cb008b63bb0e4c0881a67bf2098f9
BLAKE2b-256 3ee11b73d32655884eaab8c1c755b32351a100bb295356ced07ea2eafdfbdfd0

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ef265966e51ddbc78e6bedc8eb7adedb2cb55ec7475589fe2fe140daeb942c82
MD5 4341d320839dd3033a1fb85c04c47a08
BLAKE2b-256 39f601485e6b601bb98a3a2f32933c40f83722173f6bbaa46c732ea24c2336e0

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf749157b685e119df12aed16e8fc8cb3150e35e2c04c40685333a5feb4c4c2c
MD5 3de36fe551bdb246df5484fcdaedfe54
BLAKE2b-256 ef48886f090eea708b30c9f6eb0c5ac2c9e2f23674a928b59b569a2e29666342

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f2d5cce03c8f06ee88737d6ba805dfc96fe3cd3e4df63069b13776fe13cfaf23
MD5 67502080a88aca21f332f70ece452d4d
BLAKE2b-256 9cd1fffd4e1ff089e32caafb03aecd36e2c56ac8902ca43078afa734ce8ef364

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca37c035a65d75dbc3ea7df9be6e70ad6ada61934858a9d46a14c20003a8e459
MD5 84f6ffb48792e6961afc5fb7bcb6191a
BLAKE2b-256 875af7ddb00c70b48bc6e7670e8e657e80d72448a833fa60bbba482386402d5b

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 af0783b83fae0dbbcf2a66064897ad66b96ee70b9f5fef8c99e3151f1d7c4e32
MD5 637a5a349b15512e8f6292b54259244b
BLAKE2b-256 3ab56aa048e7f829dcb06614f541b4af63b877bc0b38ddda2a574e6ca76fe2fe

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d64a45052820532a10c6a5139583b37a0c24ee2ad10428537e9c789794bccab1
MD5 10aa0533efb851a61d3b80a2f3e83a45
BLAKE2b-256 e507d54bac2dabd0f0e56c8ebf01e804b488ec2cd50e8f151c9ff775023b84fa

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c600ffc56c9439f65a77aeea9efb33d4815aa6b2b0f4982d02524eec5892f582
MD5 154caa0c4a9e02a09913dbc175db1965
BLAKE2b-256 165d05f801c74ecd9a9d271f26156475641085c712bbd5fe201803050968613c

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4fe64691c3a1ccdf1ee477c77e3d1360bd154231f3e6ba2436dd407c2be75ab1
MD5 252dc03020ca51078ad2748aaa317980
BLAKE2b-256 3d813314c896f2c22304b404462543c941e93054f6484b8d25a9802791ae06ed

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e518d752d728082e5c862f71e734ab8c107363f04cd9e011c669cf336daf19f
MD5 2ece70d722213525800a7c0a0b418005
BLAKE2b-256 b6f2053b112e8f508dc94d0abfba60d1c3fe5a1ab56bce99e6c895170134f086

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e041ad25d0a15222f936e18a13f8034afa7e87a5f7e90db0dc17846607a30b82
MD5 2726c978444f0d57bd02c7729045a978
BLAKE2b-256 b59b301ed887c62f4930e178bf0813fbc230cc6f452d926b56953654201142d2

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c393f584a70be1caaa298dda3f4eab0f4fda4b3415359ac0ef11accee2cb22c6
MD5 12289b9d5cd0cef4d25cbc20df0ab40a
BLAKE2b-256 c9ae920958441f1cdd3419a562a0d948349d92f3552752b2234e429e97b08642

See more details on using hashes here.

Supported by

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