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

Uploaded Source

Built Distributions

ssm_simulators-0.6.1-cp311-cp311-win_amd64.whl (302.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

ssm_simulators-0.6.1-cp311-cp311-musllinux_1_1_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ssm_simulators-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (349.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ssm_simulators-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl (411.5 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ssm_simulators-0.6.1-cp311-cp311-macosx_10_9_universal2.whl (732.4 kB view details)

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

ssm_simulators-0.6.1-cp310-cp310-win_amd64.whl (300.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

ssm_simulators-0.6.1-cp310-cp310-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ssm_simulators-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (349.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ssm_simulators-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl (411.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ssm_simulators-0.6.1-cp310-cp310-macosx_10_9_universal2.whl (732.2 kB view details)

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

ssm_simulators-0.6.1-cp39-cp39-win_amd64.whl (301.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

ssm_simulators-0.6.1-cp39-cp39-musllinux_1_1_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ssm_simulators-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ssm_simulators-0.6.1-cp39-cp39-macosx_11_0_arm64.whl (351.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ssm_simulators-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl (413.9 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ssm_simulators-0.6.1-cp39-cp39-macosx_10_9_universal2.whl (735.7 kB view details)

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

File details

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

File metadata

  • Download URL: ssm-simulators-0.6.1.tar.gz
  • Upload date:
  • Size: 671.2 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.6.1.tar.gz
Algorithm Hash digest
SHA256 8bca71c5d58485992ca57775194a16d1cd6849ebb0f1c7381aa038377e8da9f6
MD5 7248aa5d3cbe97cf6f8c4f37d7a44193
BLAKE2b-256 9fdafeffa6a409e418f6dbf9741ebe9f9bf0737d216871e108e35ba3ba0bfc2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 769db8780871af7b31754cd147d865696ba6521b7b9499e57bee9f1d06b9bbf4
MD5 27aab317e9658644782f238966595cf6
BLAKE2b-256 b289544eb6e572f38ccc489a015ca58bcf0ca817cf3b3c8b8514ef787bbf9fd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b9d041a157320051528319bbdf249da4f6fb9d8502b009140e7b483391f510ea
MD5 0ef2ab80cadaa83d38c254b453e4a696
BLAKE2b-256 b49c378fdd8943e2e796825a448ef1a39ba4bd29b0df64de42139d6eec8037ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ed99dfa9f69ba7a893c3395c2c9af4e07b779e6c8cf180ad2c93e56b6fe4602
MD5 b12e14071b0641706a7655fce0f68481
BLAKE2b-256 887c158e9683b4e909ea619d2a0b57c236cd0874c71af32c767800f13aa5ec95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa952bac332873bcc311da685053cb9b8124486857f7f40ff270653c78000cc8
MD5 c967a721204ca0b226a00e5774e59494
BLAKE2b-256 1591df6de96b231c1e7b1396c6f9b516e4c92e71564d9c54fdfcadaea33b745e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 51bc8fca72f76836695ba083cd13bef3554afca0cc20cd6fdba24bd3951fed0b
MD5 d543190a3ed104735a604895fe7dae18
BLAKE2b-256 4f170431283b07fea14378b666388e351c68736501f8444ce1e2d594dee410b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9ae0d07303614e6f23972acc2d7510905114569eecf5fa1a52a888806d65ffb6
MD5 7031dfaa01f8cba392487d7814978882
BLAKE2b-256 c201943831793461adc579775bc5e2b15b7a00a215fea2941960cab0ec87c9af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c825c99c189fa7ee8d971a1dd6f8e778f67753bd92d9ab5f3d560e39e53e1e7a
MD5 7f1c6586552e641e1777fa5ee0d2039a
BLAKE2b-256 2ec0ca56f44f83b0f4683c118a0e6542169d249dfb40eef534371a96936f5ccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5af95d7d63a73c1eb529320d93a5c9cf6eb79da14a1ccdb405cf6bbee703f986
MD5 685a95e694aea1387d7bd80bbad05200
BLAKE2b-256 5fab04426ff19de49a840b528fdeda99dfa753e3f7042906abe3882a9ec3c140

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12b2cd46d6d6ce41749aa8329c5f0e6a91883227b813234a486b67a0745467a6
MD5 cfe3fdba3fdd4fb7061d21dafd324a18
BLAKE2b-256 8cdd14bb0bf09330bd98877b3d2d54a48ed83c5da0ce86c9722498bcc5f47e2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 419cc9a8c8b393e46228822bb168eb122053f2e3e6174ac66e3e706b68f67df9
MD5 d185e3998dec6fed80b540c2492e17a3
BLAKE2b-256 e3d0436a69082055d6fd6e5157516fbd9badaa74b12f89da4dbb11c658f56d21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 65ce408525ae9b6871b8684748b27d084b4dbc4b2b0e58a5fce02eb9595e52e5
MD5 10d571f8410c2b6757b11f14a9513d4e
BLAKE2b-256 b4472da33dc5d118b6a3009cc22efa9d43fa558bac3be2653fa7d5a3b299f601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a63f537bd62d2190714db7814ce1b14951c7fbf99a063bdf9e00528ec2136338
MD5 ed8bff6e34a4968603d4783d5b6972ee
BLAKE2b-256 2e819c72b88c537eb4bb2155b0deffd235637ad49fec893094294ff4d4066707

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c0a2955c0c4e5f2f1edee5449b2449559dd138fb438fde03e58a2ce0983b1e5c
MD5 a98a83cd904aea7751b2eab3c89fbf6b
BLAKE2b-256 8be402fed25ae2d7d69e99bcab9a2972da62f7b619baa2c3822f692935f3fcbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f070343aacf96bd45ba4886677751f1ea11116b1916d9706b7a8dd6fc770f8b4
MD5 c37ad1e92129ae8e07c4c1afb0a8b870
BLAKE2b-256 c568445c241aa7861f1b8f7d7c26bcc70325394f7530e73412e0c1638a6d838d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebc2f373fe1cdf4038b252261da556841df0e123538f74d9fb8af6c98c298192
MD5 983a863d47459dfff997e2b99c4dc6b7
BLAKE2b-256 ca15a853544c25e057d23c7e0d004566017544c41bf64a491245e0c2c65ca76b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 01076c668a87833271c39c9882bf41fc71ff33b052504480710254593b9f9aa3
MD5 28efbb702a8639403a5b0ea556f22cd2
BLAKE2b-256 50b0a2b342d859f36e2223f2729dfe92ab36cd3913367ebe5bba67ba425c28b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4f4335f0c9522fd072f32285ad7ced6589d7a703003a5c145629f3096b31a40a
MD5 4f402728ee8e50c3023ed37fbf578210
BLAKE2b-256 a4930d20fef11d7a2669d207a588e852424617c0639fe22d42e8995789fcc3e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.6.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3c62a9f07220432991ee6ba8d71f435b032f09cc8b504faef83b13f6a2583752
MD5 3990605014f32f07651ab261dd94ad3f
BLAKE2b-256 e82316eec5bb07ce3f4f613f2943b18860b1925fd2f12b42a1845831cbe8a205

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