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

Uploaded Source

Built Distributions

ssm_simulators-0.5.3-cp311-cp311-win_amd64.whl (284.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.5.3-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.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.5.3-cp311-cp311-macosx_11_0_arm64.whl (320.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.5.3-cp311-cp311-macosx_10_9_x86_64.whl (381.0 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.5.3-cp311-cp311-macosx_10_9_universal2.whl (673.3 kB view details)

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

ssm_simulators-0.5.3-cp310-cp310-win_amd64.whl (284.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.5.3-cp310-cp310-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ssm_simulators-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.5.3-cp310-cp310-macosx_11_0_arm64.whl (319.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.5.3-cp310-cp310-macosx_10_9_x86_64.whl (380.8 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.5.3-cp310-cp310-macosx_10_9_universal2.whl (672.9 kB view details)

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

ssm_simulators-0.5.3-cp39-cp39-win_amd64.whl (284.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.5.3-cp39-cp39-musllinux_1_1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ssm_simulators-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.5.3-cp39-cp39-macosx_11_0_arm64.whl (322.1 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.5.3-cp39-cp39-macosx_10_9_x86_64.whl (383.7 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.5.3-cp39-cp39-macosx_10_9_universal2.whl (677.9 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for ssm-simulators-0.5.3.tar.gz
Algorithm Hash digest
SHA256 d53cc7c44a5c739fd4a93a0370defb60cbd7cb35a9c80028f1ffb7cdd3d5b04b
MD5 b61a41ff74f3769e064a9f49ca04521b
BLAKE2b-256 8cf0afb4041431e11fc9136dc163205e42a86a0be18cccc115539cc8bfef90f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 06405b2135056b6ed72ad8fa83e8ebc561dce72e9cc9b82f18ed73c3a1c36767
MD5 1be648310a2a79cc67c79458d00f53aa
BLAKE2b-256 eec8af86f001fcdf44cd830d987007eb1038f498a8a42efc8b5114e8beafeb92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1186a0259a93070d3085afa66efc702cc6622c4b8b117ffd60bb3094edd3d71b
MD5 e24517c4752278741065a26929a68a98
BLAKE2b-256 0562dab37c6e97bd7122f549d4466618fa765a4f36f87388e8f41c4a7da3d07f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5dc0f410fe455ac7f6715140e6532b89359fc9326e00921334748cb568338c1
MD5 8782acaf65700bfce44b09c211c2b640
BLAKE2b-256 08c6f570f1827c0b993081104e17ad3fc4d776a82a4b12355fcdc47d15082c10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd92ca5f38fd2c8f063824bf8740759fff940a632c6786caf5d38180b560c837
MD5 4e044cfac66cf6b9a32b533aac8bc7e1
BLAKE2b-256 981cc4691e0dd7094d268cd72d706944bc83c5856203e845ee4ad5c1a326c837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef0e2520d482a66c63a83aa798b63fc47b5a4c8b7a61e24eafbdc3b0c31b27da
MD5 7826b43333e0d812f006c041f2cceda0
BLAKE2b-256 e2fa1a5657db386204306c3636e5e0cf4383605a2d80fccabb11b3967965d279

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 575d6fc1818a94a605d41a2b116905eb3603ae7652d042d27d4b542c0670be80
MD5 2e196a39c98263714dc7cadcd74bdeb5
BLAKE2b-256 d8af975891ca1e20ee78cc0bee4b894181fa8b31f7e861e418c3eb9254135fce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 507768ba7e7ac1c1a43d9a42197e2c2791db6ba1bef736c54947493181a821d5
MD5 dd1955d27db3729f702bb5adddf9f5b1
BLAKE2b-256 f80ecfaba6a29cd4b52de45fdddd258df9931ccb22fe611f703f58006f60b030

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1df6b161f8c8e7dd130b00c5f3f7f20d7088621ee6cf4315e8d5681e5d0e0731
MD5 8be60a8a8d6c46e0518a381b80bbfe48
BLAKE2b-256 7ca40caa86bd6ee550609983c94860d2c070f36d6d948d98c56e216744a883aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6328e16fdd3cfd9d9d5d96f43b0d51b0401a6eed50632dbffc8b562fdf02567c
MD5 f824e907599c80e94ba3070e7b35c8cc
BLAKE2b-256 b2f09cc2091261db729d607329180912e26aed76e6b2ccf9b4a9942c77473f6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05ef4ae77980a71cf1d9b757215678fddf8aa3e9b5b3f07bde19363698a8c6e7
MD5 617f294ce9b1dc637a94655b92bf8082
BLAKE2b-256 7236e659eb20c37882ed53aa9345f7f9f05955cd182007e06bd6a36d8da7d134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fbb73f86a426345991df693b74be4f37a72b6003d2d6348f59c69b109b2b7412
MD5 af0140d9da872515808cb2ddc4028f23
BLAKE2b-256 4b2a837765c6e3b1e5ece3f91c3c0fd7e98ce34967dd11519b04717e6b3aac7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e6cde633e778712a47a39d3aa267a83969b587100576f41de7e3a2c0947745fa
MD5 3e1605add4a655cb415793a26141399b
BLAKE2b-256 4a5d5b9b4119b429230639e296bb8ad15712d85552b6cd73caed03f975c66f24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cd8f38a2d4feb6b762af178f7ce7ba8385c6bbf9ef9dde1f2e1258a110448eb4
MD5 0b67ff776ad9c3e03476e934e264426a
BLAKE2b-256 2cbaf3e5d47dd7f467f17e17bbc632edda83e1e4899aef96a5c8dd38e833d017

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c51b7f8f198fc0dee8e357ab01895ec5b2c2711b073d7dd1f64b3073b7bdfca6
MD5 abad0a5b7b4936764d32a2d002a3c9e7
BLAKE2b-256 b4744a9b61335d5b5364f635ff3d40e23bdfefc8d50a5d9e765f938a91caf0f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd5bbf92f381ac961118ac0396005851981e4964b0ad9c3109977f22f64ebc20
MD5 fcb408d5b2770dfd3689c7020abffbef
BLAKE2b-256 762cc06754ae6db439c3d9cef7cd08fa84d9494be0c59fa72770a442bec6ac64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0cb19263b085404334cbeaea6d1692a75688c54e01d03020ad4eebd372a2b713
MD5 326ec333a0b737924fd661bb09969d53
BLAKE2b-256 44f5af28b6a67ea9f1427d792bc45635a29911919f9845c3f2ef8c83894f1b2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 68ac5c9b6eb756396f1434baa66201c16d3cb411e1235e4cbc90b3c08439be99
MD5 edf44825c2676227e4621fd3e13198ae
BLAKE2b-256 efc34b52ce6d21b42f9e42391acdc956390c0eca017c1a2ae96d61f8a9f9ec47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.5.3-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d41724acf3ada04856a76714267ba22aedbff5a064d0e5bb9be2758bd44b2e26
MD5 eba01a842d2e46ee0cd3be7c60d27811
BLAKE2b-256 15e51e28ddf1196116d16bfb9f6e3ea6b7e552efe16fbeae5814769deb39e7b7

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