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

Uploaded Source

Built Distributions

ssm_simulators-0.5.0-cp311-cp311-win_amd64.whl (270.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.5.0-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.5.0-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.5.0-cp311-cp311-macosx_11_0_arm64.whl (308.5 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl (369.7 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.5.0-cp311-cp311-macosx_10_9_universal2.whl (651.1 kB view details)

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

ssm_simulators-0.5.0-cp310-cp310-win_amd64.whl (271.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.5.0-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.5.0-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.5.0-cp310-cp310-macosx_11_0_arm64.whl (308.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl (369.5 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.5.0-cp310-cp310-macosx_10_9_universal2.whl (650.5 kB view details)

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

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

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.5.0-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.5.0-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.5.0-cp39-cp39-macosx_11_0_arm64.whl (309.9 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl (371.0 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.5.0-cp39-cp39-macosx_10_9_universal2.whl (653.2 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for ssm-simulators-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f21c31f06e8c73e3cec53be77302bc7629b44bef80f85aafdc5b49b0a971a427
MD5 81adae7c2afb865f0b2809c7ec01919a
BLAKE2b-256 b950b3ff189224ea1745c056ce3d7b9b3c57c24ba65baff1d31ce0c02d0d9cd0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 36d738bb3445ceb9c3665eddce551055bf668beb9de81af50053fb36c517bf10
MD5 7c9136d8b4bae7f8f46a840ad02dda7f
BLAKE2b-256 3a90f8cd319da2e64267047db1cae254ba15b21f06d852c0e4d43fcc465f4a84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ac3746eae8880d91161b35ce2eacfa62985edfcff31cbdfc24d4e97cb7377d2e
MD5 0b02f0d94485838dab6ee3a0bf329f1f
BLAKE2b-256 cbfbd579f11b94b6d687b2368c1832d78bc96286ea1ece859e9b2283cecbfce8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 beff89e343599a7cf0d3c8b6e4f6788d9a2baf7f0d030b2b390937c6365dfd4a
MD5 159105aae81fe22df8c807e621721f8f
BLAKE2b-256 87b3dd3ddc625a18bbc8456dc5bd95c8b78d9d516f4970d2b990fef31d592388

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e824f599e068e93ed179073c759ff8999971f38e7b2977d8069f024b6adf2b8d
MD5 cb5afe021f49f823c1caf66dde8e80a9
BLAKE2b-256 6e4f30d0fa9968925323833de4de599ec91e50b1abaed3595258fb122f56282d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef40b15f0b01b0b71cd5040c0890b0b66477d7fd2f7547ef91adc0943c515df0
MD5 155724001cb5165fb6ad3b2aeae6e5bf
BLAKE2b-256 2e870491d05f89db5f863596444ce2b53bc688319116c5a0cdbf34e31ca9fa28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 01cd2ef6e761707f50099a6033a7c3de93ed56114cab00ecfd2314f7264d1345
MD5 c24337fe00de5547a09ca706e172d0cd
BLAKE2b-256 1ed20986a21af9854e1b5eaf415f712d30c26e8fe1cce64b009536a1437fbea3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3d70e1af17e5d08aa3c3da479891f16c9b2c257782daa5c28ce25700c0c3a746
MD5 41684691c232654bec6366fd8e699a0e
BLAKE2b-256 6501f9d923a4be291a8f0285b4f797f9ab91c7d38f5e56a76a72da2f76d38903

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e9e1ed7bc95f6319c5dfdc1bd0ae075caa365544cba7459e17959f05a05cb11c
MD5 8232a1991f3cdf3e5dd3b0004e118972
BLAKE2b-256 fe21d077a6eeceaa4f908c33cb6f321059f117cfa799a2f0e2761f0eacfe2f4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e159846d37de0eddf4b034acc5c49eaa0a6862c3d4beb4bd02b1ed8077ba71af
MD5 ff0f07526489317f755150da1c3e4ff5
BLAKE2b-256 64ede7bb2a8db72372446234bfcef11df1079f5208f0493b1702a560f9ad6768

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0dd350235f88610b9aac236434b35139f0b400e543baf5a0b260016daf3f5261
MD5 5f435456ceb1e8a251181a248f5f6083
BLAKE2b-256 6a83df18de263fbe944a1bc35837b867adb422d58247e1bbbb2f05852186e348

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 662cd666413c327ad3e71e77a24092aa0663cca5024c244b5f660cb054fbc390
MD5 d2e5570478c1c15a47a56968e66266b2
BLAKE2b-256 6884f972e22cf5dff4be0aa991afa269f34f2359244ccad9ec0e823eae6c4d40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1e9da3289269a658192d7260f56cfe047418a62ad5d23f4be346c9ae6c1420af
MD5 f87c3fe59b703ae013b3768b33d36455
BLAKE2b-256 907a49033f424eb128d92e70a6d6158ccd60dc12c2647b9962dcee2aea927630

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a11d9861b1518455d66310d95fba93fa40707ba094aafb245fbdadbc2aae4423
MD5 628a79f98442577ab6ba94ab6acad9ee
BLAKE2b-256 b615a17ed3c89cd5dc1f6cd56e62b4f2cc6d2f37df2f8dd1182b30499a85e657

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ebb4e237d0d294a8947c4fb21ae695f7a71717f04f8ac7f4a39eb314db8c8887
MD5 d0d17689df93087139d3ae7ee7685819
BLAKE2b-256 bdc0a710ff483c1b520e60d6441f24d46a5daf6998941c3826117292b0e6436d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a288ba41dd861f6e90810eae62b22f79d288db8fe1e49736bf12bb75ac4bd69
MD5 0e73293a4b5da8d2f0df364fb4a54a84
BLAKE2b-256 6730eabd6bdeb10457b478d46bc1c52d0f966690e6cd94dfe3b75249834701d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9cf275e6196ebd8dbab3c39f496d38539abbdd1dbbfab9d0536fcb0055af77e
MD5 092f479ce515034d5882d61d97380324
BLAKE2b-256 ddebd079baf0adf535d3637ef29b62a3217cdf32b19465f14e5943352908caca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7fefdcf69c9c1b1ca150a9063975ac13a50674bbc2f18debae969b63b8a69703
MD5 93c845fb055beaae38476fdc4d4505aa
BLAKE2b-256 1d17ec06a293d2a9b77dd45b69159005b305cbf0542deafcddc5610b632da71f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 cc39548c0954371cde1a36056fc529f87b9e2e5c4b96230e81f118e8cfddaad5
MD5 09fb7f4f011685afdb1c5ac5752bb9a6
BLAKE2b-256 b405b9505dc6a632add709fa24b28b69aec1b78242b02d8e46d01906bd8c9e75

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