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

Uploaded Source

Built Distributions

ssm_simulators-0.7.6-cp311-cp311-win_amd64.whl (369.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.6-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.6-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.6-cp311-cp311-macosx_11_0_arm64.whl (379.7 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.6-cp311-cp311-macosx_10_9_x86_64.whl (433.8 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.7.6-cp311-cp311-macosx_10_9_universal2.whl (773.8 kB view details)

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

ssm_simulators-0.7.6-cp310-cp310-win_amd64.whl (367.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.7.6-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.6-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.6-cp310-cp310-macosx_11_0_arm64.whl (379.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.6-cp310-cp310-macosx_10_9_x86_64.whl (433.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.7.6-cp310-cp310-macosx_10_9_universal2.whl (772.7 kB view details)

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

File details

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

File metadata

  • Download URL: ssm_simulators-0.7.6.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.6.tar.gz
Algorithm Hash digest
SHA256 1207eec69c3be9df0f4c58504c92c0035266299fe10fe371b9f84045f65f895f
MD5 02ff4172f6fe070c478c3d1e2ee6ce54
BLAKE2b-256 7285a7bdce23d3ce3fedc512681a850ee646ddc9b7c6d25f46f338e2aceaed70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6f726d833c300e1a217c6a5fc47017d6d094188636007d17fb5bd4ff2f15dd72
MD5 97cd3889805d7022b30445fe4c5f6c76
BLAKE2b-256 d42dce74bd899d5d960d64b7e5c5b8b384eedbe82e5c8b2ac2217366ab92186e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8dec568c90364bd52a50c245d9e078ff8ed4e43bd79bec7a2a264cf1e1dd87e0
MD5 a9922f10fd0ff5bc703c3e6e6ed55417
BLAKE2b-256 a7a0db1ca44336ab34fbc9c1e8969bfbb712a6651bcd89ada90aab461baafeda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 564e5853f804c551b0b72a55a21ec3653602e2131d87b3af6cae9fb7646db5f6
MD5 7b042721fb800ce7724f8ea6f9bb6de6
BLAKE2b-256 877ca0bdcbc8bc3ae5da16b6fc167a3c599c1cf7cc31b8d1c867d4f1206d8467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a3ce86eedcf14748d1ca0c267c22d01ba59013d0d63a62ce510c67eb2695b8d
MD5 8a7e49d322163f1599f3b1fb909558e3
BLAKE2b-256 db0d2218efea3349add865dd3ec873d296196b37ef262d6d3791b2061d8685bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b8c49a12026334e56dd4f5523aafa48cb22e725da3e246598d22afb6bb6cf052
MD5 7aee3ca0832bfc4d49c5be080ffc3f52
BLAKE2b-256 ad99e80f53d93e381e93b790443b3682805e569818792fa1dc237618a55deccf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 87e27823ace4cb2007dac6d14d4e27df1170786c16daeec79b52119fffce9330
MD5 90400b5b51dd1aad5514a59db46d7f1a
BLAKE2b-256 344ddff76f2c945aff6e73a9211981fb897bc71a5a795e85c709c9b9f1083974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d2690326cfe7bab310843ae1731856ce91dd70f009da7c4fa1dddc2015e6609f
MD5 a5c788941280f4ca17ead7d6a18787b9
BLAKE2b-256 748f5ab5dc44c19cf2556e92b04361de0a63786310af6f495df4b05553e2625c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 633cec0ab68977372a1447a2769c56db40b6dd5d65050def640e893eaeaf160d
MD5 dceac8dc229ace2ac902beadfac98315
BLAKE2b-256 980bd1d9fc6b752a3c15b4ade3b2dccecd5890e9798433a20b14382160e54902

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 787dd499abeeb8fba024271ad5b54b64cece5655a3461ed4d09ac804935f9fe1
MD5 52497d7219faaf519d3d567f377e7574
BLAKE2b-256 6e0cb72dabfa80ceab61c8d0e4d363305415fe9db7903ba4964925c0d2943d3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c465ee975479f01d19e558e2f5471cfece3b1b9a9946f59b1c0e3e330c9b25b
MD5 3b1ec589edddb0a2e3c17b2da8d4af82
BLAKE2b-256 dd287b88a3048c9ff8ad35fb7b837c84cc7bec7ea573ee693c3f1b60b68a3969

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ce723b7bd5f0171448aac0e0ed9ce31d53a07ba2e23d5ef0b9416261ec1acafb
MD5 293869c2f6afd164309ffefec72f52e0
BLAKE2b-256 9fe94678288514289187ee49f53ec19ecab77b9704aeb8b749c75f5275e77728

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.6-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 db7f123742874f2b6c550293d93127d768629e8409b4553f0311ace3e11efc19
MD5 dab1dfb7c413a3237d8b38b5601dacf8
BLAKE2b-256 d00d6c3ca31ceb77f8ad47ab731d44136e38e7f8ebec558f07e4eddeb475fa27

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