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

Uploaded Source

Built Distributions

ssm_simulators-0.7.5-cp311-cp311-win_amd64.whl (361.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.7.5-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.5-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.5-cp311-cp311-macosx_11_0_arm64.whl (371.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.7.5-cp311-cp311-macosx_10_9_x86_64.whl (428.2 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.7.5-cp311-cp311-macosx_10_9_universal2.whl (766.9 kB view details)

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

ssm_simulators-0.7.5-cp310-cp310-win_amd64.whl (360.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.7.5-cp310-cp310-musllinux_1_2_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

ssm_simulators-0.7.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.7.5-cp310-cp310-macosx_11_0_arm64.whl (371.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.7.5-cp310-cp310-macosx_10_9_x86_64.whl (427.8 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.7.5-cp310-cp310-macosx_10_9_universal2.whl (765.4 kB view details)

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

File details

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

File metadata

  • Download URL: ssm_simulators-0.7.5.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for ssm_simulators-0.7.5.tar.gz
Algorithm Hash digest
SHA256 fab8462525dce9cf3e93b32f5103423ea3d001e68d4f423ed9199ef27951e195
MD5 aa8e48ed9d23361868fc13e098ef50e3
BLAKE2b-256 bdf4283c1765fd321d7a75e82c0db34054598ec957cb99511c5e17baf43826b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d28b99e54e16e84c0986a7436c5e43afd513838fe6cc88919a5b988b535a769a
MD5 6d37d05aeb97790422b9a3f8ec23961a
BLAKE2b-256 42a2558e4dd0f05976f661e89029bfc9ac4afd477a83aeaac5af533ae28e9b06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b6f82f10658c43afe714778816ede94bc2e34c1eab44611da296f1ca060e4ff5
MD5 0e3189a1044819b581ba9ab261d41392
BLAKE2b-256 73cae7c24e3f979654c1dd68bb30376d26c6a0e41d310086ad02b84ce0c6a9f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e6473cee255213620c9275c744c118fc77aef8ac528bb46f2052539274259b94
MD5 4bfb101931cb9adcf59fab6295e3f0bc
BLAKE2b-256 750c35a8385c0d94aae7714dec231481b488a477865ba10c12e0fcf995f63d66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 226bda408325a82a81d1d1d43bcce4661f6d457bf5eaaf3c6701eaf63a4b4c02
MD5 bc47196dd09681379d56b2a462428576
BLAKE2b-256 5986c9401789b57b8c9b686d5c7230dca7cac900fb94a7050023b75b3a63714c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1c4f9c460bc166337579709002d43ff271585da5cf2cec6731913d51c4b02bcb
MD5 55a631b0cdf5ac6d94eccc49b5a6ad8c
BLAKE2b-256 3b12d2383b3e5e205598aa80047cdcb886ecf9eea39b0e688fc29a106de2bfb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 79c480e6b5424063b96d35f6673d7ffe0af0bf1c62e5334156e0313a529b349c
MD5 ebcfaf17b3f00efcd500071f40977429
BLAKE2b-256 e5de1c6fce99edb2307eff5424509cf7d728c3f35493c30c125a21470c206589

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6b16c80b3445e3f49d15891ea06d18084c410b34b53e3c2b2f1fa0cfd3a1cddc
MD5 4f30f6b811f0fe3125ddeb2f2083bf01
BLAKE2b-256 73a222a17b184f20111134b432f31a1fe67f69d8a196390441fca1dd29035afe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c2f5f84dfc9e59ae55c9e9f5f0c7a35aae5ae279038f1c3fc267c69e59e2169b
MD5 d98790d89f231e4ef1a4fc2be9911e59
BLAKE2b-256 c4782ed7334fa6d7eb29f1fc30845a1f9a1349f908a4e4c390e00470f5c3d49e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0d3c0b5a436d049c37edd534911ad5945eaa3479c676a33db6ca376dd2b1cf5
MD5 9d67770db0f896ebb6ab752df2c89f2d
BLAKE2b-256 1047f8cdbfa1a59b4c57e12a372096e4acd3ccf86fef93ad660ea571b8f1ae3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9537c517f5f7173691bbef2d134b7968de924a34625f9e09098e8f993509dbbc
MD5 dbb4f57923bf2a248419c9908b9e03c1
BLAKE2b-256 ca1589d80365447ddb9b8a43f9788c12d22061d7e594d758d1e1ba0ffd937a7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 76fd8c1f1afad4086e0c4ce621cbdaefe3793c8fa4c1f2db2f69aed3ed0fdeb2
MD5 541bf248ee5826c66a02d1d4c63f136e
BLAKE2b-256 f565831ec5ebce33de5f295c252b1e5b8ea8e0a84200e2e712134f5f55ae209f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.7.5-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 33843b00cea320e75839931be6bf748c14c3d6ab6090821f970607d2f2e0785d
MD5 46bb8ee64b25620838fa5650a3bc0a9a
BLAKE2b-256 cc62fe9665234e6ed603f4e5714e2f4b1a0e93a3967941af2194f59f58d7cc42

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