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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.8-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.8-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.8-cp311-cp311-macosx_11_0_arm64.whl (380.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.8-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.8-cp311-cp311-macosx_10_9_universal2.whl (774.0 kB view details)

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

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.8-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.8-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.8.tar.gz.

File metadata

  • Download URL: ssm_simulators-0.7.8.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.8.tar.gz
Algorithm Hash digest
SHA256 af03b7624e61f8d243fecedc94312cadfe85a93d3a79c95aeda9a9445d5f3e8d
MD5 44cc2821b86fb2a3302c9d7a090ee456
BLAKE2b-256 8c6c7663f463bf46108329737d26cfde03c2d8c5eb9836a01a6f6d6e23ab94b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0fa051f737db0421a73a453e3da5fec85218b6cf5fc0c07ed41453502f76e07d
MD5 566dd30a46e8aa9b879daa9a695d6b23
BLAKE2b-256 778a3b743da1a4d765222203e9684c8a1433d507c359dbd1f420ba55048b71f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c8262fa395da4ff7781d96d5d09a01f81cdeef38277e97c36a04175c5eaaa95
MD5 f60c2c0dbcd20f98ee661e02ebb7b9e2
BLAKE2b-256 f1473758e617140a245f501e4898b5a1edf61d7ad355e6074ad6e2dd7ebd044f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ab8c25249905dc4695f46769cc15e55cfe64e5d32c4c195e6d874a59fb364f3
MD5 d043b68920374315ca2a0e5e39f9e95d
BLAKE2b-256 475a060a7f0445a6d120971417965214c4fede415b3a6111a313c06b24395b51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c3c3f840b3771584fae920f06da3ffabd02ca4b1fd8a79dd9686f9fe48eade3f
MD5 c7a6d35d6cb5a288b2587a0113fa47d1
BLAKE2b-256 b71bb9633822fc34c04d015f5b0bb658e991d77a4d87dc1005386cd9435a278c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e799a2c6d67173889e495bc89ed7256546d72d0dc13d928345cfff8229b4f196
MD5 cbee8bc1410029f5ed6107907acf565a
BLAKE2b-256 197c36e9f3af8631852eb44effd3c67bd2379e3d56040296a149be9748bd9d18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ffc67955d705591f89bdc7af7d7bc63b4fd405f10349bfac882c69df66a282b6
MD5 5bc8b0f9558e91fe14b0b984b52d4216
BLAKE2b-256 8a6126e5efb1f87e89a6287c5632928438bc124ff19892de2b4ef98ed7d9c4b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2e90bfe32fe8c9b157db8d95177a170f0a05b2cbfc10c6946e4974c4e461307f
MD5 abb55ee2f297ef871abc420272256bd0
BLAKE2b-256 6e1fbd570595860a1e82dd80026f81524a62be55ca61fa1174b7b9e2c13ecd3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 43dcd98625cf9394bdba535fe17665dd5f49ae7a0cbf9a3a62ee6681dda103c2
MD5 c5411555c0246a65c7005aa339a29512
BLAKE2b-256 b480e9778a8441e3d83b441decd741c1340d72267d1626e9c57b2ad9c73b36b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 344d489b1a48c56a3fe6cb0bc088980681097b46ff2d7e624c948bcce3f6dc47
MD5 072ed88db55411914a71c2b4cb1127c3
BLAKE2b-256 b511e615745e84578bb1fd6d9d4903434f3e2ff9ded408544f65d04b1e088973

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 64ae8e8edaabf4d50e129dfaf94ba307abda9312edf1ba326548b34075a3c851
MD5 47b7ecdfbcefcb6c68ea5d2165468300
BLAKE2b-256 9317b8215e6a86a80a322ab89aac5284abba96d849e11b715cdd838ad7610125

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dc9ba57ee09c029a18e7aab5a6a009cfd5e256c8a78dfec9598f7aafdba67ee9
MD5 f977ad4a4f721f4cef1291ab66c1b326
BLAKE2b-256 c24f5d67335e8d1d7e873ecc76af04dc901b9f0721af8be6e385ea1da9b915d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 234d25d5b56b8ecc54fa83f65bed2f819e6764197bd9501eec2b61ad7596f16b
MD5 c46ba636af0ec27083879ea1b843f1eb
BLAKE2b-256 03b2e20357e6671f7f9f51f6e2d57eb2b1e0e4198fd7dee7b12042fbfe1107da

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