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.4.5.tar.gz (525.1 kB view details)

Uploaded Source

Built Distributions

ssm_simulators-0.4.5-cp311-cp311-win_amd64.whl (269.8 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.4.5-cp311-cp311-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ssm_simulators-0.4.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.4.5-cp311-cp311-macosx_11_0_arm64.whl (307.8 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.4.5-cp311-cp311-macosx_10_9_x86_64.whl (369.2 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.4.5-cp311-cp311-macosx_10_9_universal2.whl (650.7 kB view details)

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

ssm_simulators-0.4.5-cp310-cp310-win_amd64.whl (270.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.4.5-cp310-cp310-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ssm_simulators-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.4.5-cp310-cp310-macosx_11_0_arm64.whl (307.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.4.5-cp310-cp310-macosx_10_9_x86_64.whl (368.6 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.4.5-cp310-cp310-macosx_10_9_universal2.whl (649.7 kB view details)

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

ssm_simulators-0.4.5-cp39-cp39-win_amd64.whl (273.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.4.5-cp39-cp39-musllinux_1_1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ssm_simulators-0.4.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.4.5-cp39-cp39-macosx_11_0_arm64.whl (309.0 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.4.5-cp39-cp39-macosx_10_9_x86_64.whl (370.2 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.4.5-cp39-cp39-macosx_10_9_universal2.whl (652.5 kB view details)

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

File details

Details for the file ssm-simulators-0.4.5.tar.gz.

File metadata

  • Download URL: ssm-simulators-0.4.5.tar.gz
  • Upload date:
  • Size: 525.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for ssm-simulators-0.4.5.tar.gz
Algorithm Hash digest
SHA256 d809e617b085b7a4fb8f96ee2587a5ea19dcb86df5e7a1ddebfc73a7812ade6f
MD5 438bba714bc2c74fca17fb20bdf6b635
BLAKE2b-256 dc2e6c247501751c69c6836c3b4349b8be571d4acb3b4d50b410f8be5ba2d431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0c2c0eaee0a1e4d014507c0dde4dcc623b5c220043d726fb76e45a9c865ca2b4
MD5 5264c8799ff2e841d44185e7ea968f84
BLAKE2b-256 00893f6f469705314c1faa8c0b44c5700d264b24d93412422ca18c4867cf3048

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ed640728a8b6413eb8ee732790da2e55e5107066dec09424b0a38cdcf4146723
MD5 0822e58cadd5db995a79b7a4d3e235a2
BLAKE2b-256 219a84dd2d9301b54e2d3f4db53b44e405ce43de3dad19b9ecdc4d90aabbb8c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 695c23887c27164784e91a32225b3cdd3d39a7be9c72c85d0d67d5ea1dff0ede
MD5 072caac51aab9caa80a66cad6a881bff
BLAKE2b-256 ec03b88f10a1e942a2bc196572975ac8506191703faeddb4139889226a790850

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32571e8d7e0effec609334865087b30d1c30288950e30ac9950eb0b3641b50c1
MD5 778b74e172db828751360195d092f116
BLAKE2b-256 64dcda55b60d520eccca1b2d8eb932b9e5f03711022693baff01f04321758084

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef5e98c6104d3d28690eae497bf80d134c526b04935ecdd4e913e7e175c4e532
MD5 3938040bd9a12a8fb3b88bd22ba66352
BLAKE2b-256 31bb3c9a39802aee7116fa7f767a5ab828390a173a4f4b6a388ca4d9d6b6b2c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 046eee339e11105443a9fbfc7de0059918d8a9050897bfb0c0ae6f8bf05150a2
MD5 a8798ee18a8843da8ad4630002562613
BLAKE2b-256 c5d6cf66c171f6d3ff6e7256c20ea070bffbbc777edce2b360a392bd81e74115

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6a1a31b20a69a9ce12fb6ace6ea9b84ce4be8ad298d0f0368bfd19f7630d6309
MD5 d8244c0d0939021e030dae687a9c95eb
BLAKE2b-256 8cd1390aaf267bf49eebce5e3bd07d6a84ae573b56f831f641c34c13b28ccbb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c98e37e33ff29b8937ff66975c07abff0c34582a3f75065ac52eeb5024a52a74
MD5 bcf8d8b3896e944bab280b5dd13c4140
BLAKE2b-256 ba6ab6a5f056bde87bd4548876409b5f39e1e6fc6cebd9b5789b2665f890675f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1329d5efad1c98262e0a270902c953a7393fd6a412f6f2cca696ee8a612f7b36
MD5 b4acd98672b9fcb0975f3a0b39eaa7aa
BLAKE2b-256 e67772a4412167ccf291b2a486fcc9a3fc0e8e4b692ea95e370dd6c3cfd0daf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55e4a668f076cf8d8d5bccba22818a1bfa65f52ef32ab1a8456ac1d55a44f23e
MD5 2b303e639a257341e8761f81c02d2be5
BLAKE2b-256 dd3965bbfc82677a4eb365f0a2278e00d7fb25451b25991a640aa97844913f5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 25861dc5bc34fba5a66f976891b20290cc9c8eed4f6f1ec4735429f6d3eb524c
MD5 0a52d69c42297d02ee3ba69b60355079
BLAKE2b-256 bd418520863f7aecd47d7a27377441014a7fc614b8d289efef8da13a9b9d5d0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f465c443f3757b9b8de1ad8ee81235181cddecf9f933334f74ec3e173fd646f6
MD5 a374c98c708ac306aed24878e35eb0ab
BLAKE2b-256 30bd9549ac739f7d8174b59fca8620a4de6880775e2a8cbedbf0260ac8945003

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cb06a5de37051959fcd03efff4d1d0d0672d31fa1a8a7029dc99a398d6dbd4bf
MD5 4e627bec315666ab075e25500e515d24
BLAKE2b-256 c86daf9c871c256fedbc360c6113d7d02dd195579a057c729ff9eb7e690a2ad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3c989ed023bedddcd51d2a3d941a7e7c936b8c805c0be3785216de17a4e43c41
MD5 f5840997ed60dc65c3f6e50140a4f961
BLAKE2b-256 e846e6500f8ccd61d6a64d81fd0d59f208fd5811dcc611e7fa1cbd4b11c0d8ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8cddcdbb9552459ef3a12d57b3cfe2b7095fe0b90be974ee5f7ddf772d75164
MD5 57bc38e6d23b759625a505534648ffb6
BLAKE2b-256 254f9a368e58230c4d6110694cff7023631390caf53b4d6b8674e7bccb12b680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66e47a1043ee02f9d708e998c3acab282c5a31338bafda4ea9d089d8175509ff
MD5 f03cc4d26e4c7db39f771becdef7eba5
BLAKE2b-256 75bfd6306687ee88b91bd142d3ce58b753a95f6147c861ad339444a0c175cc37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 df55cb4bdd39ee9cedcfd96e6e4b0beac10c9716181056c29d618ac20c71592f
MD5 a29bd7a33f8b23e4d9c8291a71955899
BLAKE2b-256 f226fb8541955fc103917b127fa5bc2ab80c5e3139a5612eb47f5951a18d9898

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.4.5-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4cb7903be1f100c4febea099156f3f17fcc662ed834dfd4bcd2c443a37ac4000
MD5 19ff3478d164d1aa732f3323bd452c12
BLAKE2b-256 863021116022726af2046164648150493891d315ca03bd318179753f76be6cfd

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