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

Uploaded Source

Built Distributions

ssm_simulators-0.7.0-cp311-cp311-win_amd64.whl (320.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (377.4 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl (437.6 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.7.0-cp311-cp311-macosx_10_9_universal2.whl (783.0 kB view details)

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

ssm_simulators-0.7.0-cp310-cp310-win_amd64.whl (318.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.7.0-cp310-cp310-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (377.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl (437.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.7.0-cp310-cp310-macosx_10_9_universal2.whl (782.4 kB view details)

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

ssm_simulators-0.7.0-cp39-cp39-win_amd64.whl (319.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.7.0-cp39-cp39-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ssm_simulators-0.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.0-cp39-cp39-macosx_11_0_arm64.whl (378.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.7.0-cp39-cp39-macosx_10_9_x86_64.whl (439.6 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.7.0-cp39-cp39-macosx_10_9_universal2.whl (785.7 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for ssm-simulators-0.7.0.tar.gz
Algorithm Hash digest
SHA256 0d08b4a8747fc39d48db863211eccb3608d2731e961de5afbcaee16c7f242ef2
MD5 415d61a5e86782ca533b7bae8a3ffa16
BLAKE2b-256 fe56689d70dd976083e170d5f5d8b835641282a58fccf237b6ef6bce63d4eb2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a8212bc99ac62458cf9a0041f50cd05063fb9874d88e1a492db7884a494018e5
MD5 609260165995744c77b1a6b66ca13f01
BLAKE2b-256 3e5ef1b2e21878680ee6d45398f740a8fa25dc1eb88473f1a2dc7b238f872374

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4da4e306e73c40861b80bc21db13e944b226d313da5be4679b7c3409d0478891
MD5 ffa932924713ecd553048de9f7e69c54
BLAKE2b-256 ad2285e27530ddffb3554f947a4bc9ff1ab065cde3a2efea04c37015c7b160d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a67cdb36aa87a3758786c5e5fb5f8af253390e2ea0b9df0913a4df3716c703f
MD5 942958314fbdb6240bf46c7c0a060bde
BLAKE2b-256 d3daa351a0d9446746dcb8734ffd6d381bac8e7614bbd598c0519ed696111047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9060e92007fa8982dd41e60b6bc26b6c3fd00bdf00a7019132daa7464394c0eb
MD5 4596a391c219ce9ab65ba9625ef13e37
BLAKE2b-256 8327aec83bbd00c254cd33029b2a185f6b18a8ba904e4bd7a00860667ad0d5d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 adcee0ef33b94e235c81fb14c600910da52b6d46d7567a7ddb56e262e89fbbe4
MD5 8ad6fc86238364a33e7ee84219a5276c
BLAKE2b-256 d1499b5bfbd1dce1fda38c294fe427d4b3d3fc856856bccddfd4ac7afb9a39a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ab7f0d6e7f599dae89d14fb8acad37774a0f11b5801cec5146f2834d2a863379
MD5 81bf04ec29db4b463f3cf4c2ccad267f
BLAKE2b-256 4b85d022177c0ec59d40ec3ef5d6c665e0422d8dacd1f0b42ff605cec3208331

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c6051bbe0445b998532a16dd00206a922912f6d7a7d4a7a17858ca29540a6349
MD5 33ab1ed94a442e055f63da2d5caabc3b
BLAKE2b-256 c86f595020742492960cdfe7a57cc0c46b04a8dd264bd588f5cc09d43242a6d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bad73fa57df32274c8c21ab15e72d1cb1c81395e0439210aecfebdd3482e8efb
MD5 aa6585f0e12d7a51e05d87cb8ab7a28d
BLAKE2b-256 3106b69d47044eba92cba39aadb81e5a9805824b0f7772179c76927a6f3992c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a620b58f0c86184fa9d9099715b155f06a296c1841d3a091803b2a7f59e9ecdf
MD5 69be8086f321f7e2e9265667955d487e
BLAKE2b-256 c7a127d933e885fdae6c3e843962061930604111fe7dd8cb3f0481a7b0370e62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7b8eada880c0ef92ff6ab3983190787f924f9796c93328ae086e4fa8db0ba8d
MD5 18cf141ca8212dfa59ab51877c3c9218
BLAKE2b-256 ebff541dc2096c893995d31895bfbc8187afdf43ab22ede95c533bcc10ac89cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f7529470b7153368663ad82c7bddf5ab8cb7e59db9f4e0e6dd59ac6e30b5baff
MD5 79cc65b13283a1fb6df2c2f1b5100d1d
BLAKE2b-256 95e35b07b6c995382e43ee3362f39b95baff16f2cf27dbf4769935a835886706

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b4e2848621f6313b8bda055b5b28fff5a48f1717d4f545ce32cf75b30605db43
MD5 349681fadcc4c5c0b7d17f932f3513a6
BLAKE2b-256 5d1ee53805f73816ca4d407cee9be96ec026e0af6de76fde1e61371c7147110a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 74a1b79f4aacf3efcdaf547e132822a22bf8576c1a59141f04d09e0c7701c3c9
MD5 0172b3ff23ad4802a8475680d7ceb49d
BLAKE2b-256 dd327952603412523c5955011716f5c3471290cb06c118349c148f316f2c680e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 cbda4a4a4a1db312000be5a4b11c01a0088e6096c6aebce24bc408e52dafc5d5
MD5 741dacce01f2ba7f907a69adb40abb7a
BLAKE2b-256 00f1913a64e2347bf8b5b34b700c1330030b050d1aaf609fa6b0ee5fc4a1bc3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8fec2d67badd7de2d50f6e5bde19ef7989b831ff4ac03e65e7ba2ff316ea5e0c
MD5 63577dabdc31f64ba101bee106deaab3
BLAKE2b-256 72355cc6897800164b75162761a49855d474893b7f57aefbbcb1e9b505acfc2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f34536648f0d95dc72822c615ecdc012b910559df08c2f3e24ea444d467615c
MD5 58fa22bf5901660eb419a10b9283aafc
BLAKE2b-256 aa7cdbfed3d5f4f888a6ae5b1906effa786e0759b95f3bcf30d82d78874cbb62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9d71066eba3f795d9cd3bb6235494891da35b27e763fa9e7b8de96dae53e2a0f
MD5 ae67db95c5a95d737c24e01bb78397e3
BLAKE2b-256 3b7d0365386d14e447368f23ca3f8d59b78fec6a539bff2a348a945c1c2afb2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a1a8fbbc4d0195b75d7a00d222bce347fb090f0ff17578c0558f0d2249ec8ff8
MD5 6039e2ed3340080ca6196148450ce6da
BLAKE2b-256 e498617ae44dc67808017502cc7914f5730efeab1b0fe0f424586ed1359ea083

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