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.7.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

ssm_simulators-0.7.7-cp311-cp311-win_amd64.whl (369.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.7-cp311-cp311-musllinux_1_2_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

ssm_simulators-0.7.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.7-cp311-cp311-macosx_11_0_arm64.whl (380.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.7-cp311-cp311-macosx_10_9_x86_64.whl (434.1 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.7.7-cp311-cp311-macosx_10_9_universal2.whl (774.1 kB view details)

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

ssm_simulators-0.7.7-cp310-cp310-win_amd64.whl (368.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.7.7-cp310-cp310-musllinux_1_2_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

ssm_simulators-0.7.7-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.7-cp310-cp310-macosx_11_0_arm64.whl (379.6 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.7-cp310-cp310-macosx_10_9_x86_64.whl (433.5 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.7.7-cp310-cp310-macosx_10_9_universal2.whl (773.0 kB view details)

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

File details

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

File metadata

  • Download URL: ssm_simulators-0.7.7.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ssm_simulators-0.7.7.tar.gz
Algorithm Hash digest
SHA256 79740f12a4c00cd677ad4cbfc91a0969d8949e45eeaa9934426bd5d1292fbdcf
MD5 5659f8225fc7857b0bfdb1c8a8323212
BLAKE2b-256 e94c2fdfedc610f4ecb99c5542f1a15610e2efa24950f2bbeeacf3dfaf03d25e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 11768064de3f3139fc1a2f6febf5ea7dd4b87cea6f9a3402ffb809e67a8e0480
MD5 764804c052b39742cb11f9bea153aaac
BLAKE2b-256 3a67e922252f862ee146657e41a209e7a3491c4954ad8b2a80f1a97bac52e336

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.7-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fa313efccdb781cc3560811baa847d025d5a16753d1171c607a3640ae60e64e9
MD5 85324fde88fbf760554b9f0f541e47c2
BLAKE2b-256 5376e52724209800446b520e2b1ca3c251969b9aab7e8e73ce519af2271b2774

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf5cd7d968163b633c76372080502d0678314998ad82de735218587fde7cecff
MD5 b74cf235e92dc7c52707ab55972b876a
BLAKE2b-256 dc89775dfec606f0deba0c3c53f6b05394e5cd9225bca1214e7e76cb8a13b0d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f39c4af88679edcb83707b99ad0a6c18e9a18f2204d38776062ea1f6904987bb
MD5 b6b64e5556d10eca37ae1e9ed8ced35d
BLAKE2b-256 3385713ec72aef0b6cf823f0ef6006ac6182e59b7545fde84fbe93018a7f5863

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef07afcf1127a8b5eaaa292594bcc3dbb19934e6d012667bd9551ffe02b966be
MD5 0927f4d1bd3c2f823f8f90577238b30f
BLAKE2b-256 36157016c545a3554b938f181060360d60cde9b3347fbdf6e760fb409b74b73f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 20fa6b21d4e45555bd08d6b87d2f3122f466e8139949eb8ac31ec0bfe3bdb026
MD5 af3a5500fc71e0d06fdc16e17aa4c2cb
BLAKE2b-256 3ae70bf4471618ac99b1fe3c0d2ea4a625733f14f523388eb3655ab93149ef00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c3b902f3c61268da3d7c887f6e3f9a74b4b35799cfa120cfecb8ad9fe6f6f657
MD5 3405a16688d0f0a5c055f0852e10d83c
BLAKE2b-256 b59115bc30eb50eaf36268a838d5a7d5252e7b24c134bf5ef25cbe2dfe391c4e

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.7.7-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2543de6a4eda2f8f902b3638c6cfd6eb0e683f427baa601c323edf425d17b79c
MD5 207f5c9ecb4740d2dfbefddb78d5315e
BLAKE2b-256 91a72d7902a3d26cb3bceb06b069d66730ae69fa3827ceb45da3c0d7a13dc52f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42bfc4d11752e20c53cd91ae8716b1fb688bbc9826a6621fbb7a825c491023ff
MD5 bf86d1037212056c11369ed93a11e831
BLAKE2b-256 82e2a4a7ddaed07cd623520ad72dc8978e7d37eb31f4a36225176b4f856b6a91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65e3a7d45e00456002e39a93f49fbe1db4d4aa4a79e360ed21fb8a27b168713f
MD5 456c39fdb386da3301387893d1f1b40b
BLAKE2b-256 222c15833440364430423b0ff62af4452f39d2e13e85aaf6a7ef225f2c740377

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 450ec3586d781f6bf34dd1e545d20bdbac3faedb3d65d02fa4a1665c05d8d752
MD5 f6d498bef4929830f7584294a356ae5a
BLAKE2b-256 d80b7eda8a1057fa4c91d3079b5ad2bcb174c9b2232c576e2a48f4adfe0d9787

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.7-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 65c21478e7eb56dbedfe43c49a66b729a89a69111499c5cff7d4bb6bd62f1fe0
MD5 fee51760dbfb90432c22cefef714454e
BLAKE2b-256 0dbfcd7c82c0f36878b77b17f2a4399262fdfed57cb3bf7dddedb818d848cd12

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