ssm-simulators 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. ssm-simulators-0.3.0/LICENSE +21 -0
  2. ssm-simulators-0.3.0/MANIFEST.in +10 -0
  3. ssm-simulators-0.3.0/PKG-INFO +12 -0
  4. ssm-simulators-0.3.0/README.md +225 -0
  5. ssm-simulators-0.3.0/notebooks/basic_tutorial copy.ipynb +845 -0
  6. ssm-simulators-0.3.0/notebooks/basic_tutorial.ipynb +383 -0
  7. ssm-simulators-0.3.0/notebooks/basic_tutorial_tmp.ipynb +1736 -0
  8. ssm-simulators-0.3.0/pyproject.toml +2 -0
  9. ssm-simulators-0.3.0/setup.cfg +4 -0
  10. ssm-simulators-0.3.0/setup.py +33 -0
  11. ssm-simulators-0.3.0/src/cssm.cpp +56092 -0
  12. ssm-simulators-0.3.0/src/cssm.pyx +2480 -0
  13. ssm-simulators-0.3.0/ssm_simulators.egg-info/PKG-INFO +12 -0
  14. ssm-simulators-0.3.0/ssm_simulators.egg-info/SOURCES.txt +27 -0
  15. ssm-simulators-0.3.0/ssm_simulators.egg-info/dependency_links.txt +1 -0
  16. ssm-simulators-0.3.0/ssm_simulators.egg-info/requires.txt +6 -0
  17. ssm-simulators-0.3.0/ssm_simulators.egg-info/top_level.txt +2 -0
  18. ssm-simulators-0.3.0/ssms/__init__.py +6 -0
  19. ssm-simulators-0.3.0/ssms/basic_simulators/__init__.py +3 -0
  20. ssm-simulators-0.3.0/ssms/basic_simulators/boundary_functions.py +102 -0
  21. ssm-simulators-0.3.0/ssms/basic_simulators/drift_functions.py +102 -0
  22. ssm-simulators-0.3.0/ssms/basic_simulators/simulator.py +1264 -0
  23. ssm-simulators-0.3.0/ssms/config/__init__.py +1 -0
  24. ssm-simulators-0.3.0/ssms/config/config.py +846 -0
  25. ssm-simulators-0.3.0/ssms/dataset_generators/__init__.py +2 -0
  26. ssm-simulators-0.3.0/ssms/dataset_generators/lan_mlp.py +680 -0
  27. ssm-simulators-0.3.0/ssms/dataset_generators/snpe.py +638 -0
  28. ssm-simulators-0.3.0/ssms/support_utils/__init__.py +1 -0
  29. ssm-simulators-0.3.0/ssms/support_utils/kde_class.py +185 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Alexander Fengler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ recursive-include docs
2
+ include README.md LICENSE
3
+ include ssms *.py
4
+ include src/*.pyx
5
+ include notebooks/*
6
+ global-exclude .gitignore
7
+ global-exclude .git
8
+ global-exclude *~
9
+ global-exclude *.pyc
10
+ global-exclude .#*
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.1
2
+ Name: ssm-simulators
3
+ Version: 0.3.0
4
+ Summary: 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
5
+ Home-page: https://github.com/AlexanderFengler/ssms
6
+ Author: Alexander Fenger
7
+ Classifier: Development Status :: 1 - Planning
8
+ Classifier: Environment :: Console
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Topic :: Scientific/Engineering
12
+ License-File: LICENSE
@@ -0,0 +1,225 @@
1
+ # ssm_simulators
2
+ Python Package which collects simulators for Sequential Sampling Models.
3
+
4
+ ### Quick Start
5
+
6
+ The `ssms` package serves two purposes.
7
+
8
+ 1. Easy access to *fast simulators of sequential sampling models*
9
+
10
+ 2. Support infrastructure to construct training data for various approaches to likelihood / posterior amortization
11
+
12
+ We provide two minimal examples here to illustrate how to use each of the two capabilities.
13
+
14
+ #### Install
15
+
16
+ Let's start with *installing* the `ssms` package.
17
+
18
+ You can do so by typing,
19
+
20
+ `pip install git+https://github.com/AlexanderFengler/ssm_simulators`
21
+
22
+ in your terminal.
23
+
24
+ Below you find a basic tutorial on how to use the package.
25
+
26
+ #### Tutorial
27
+
28
+ ```python
29
+ # Import necessary packages
30
+ import numpy as np
31
+ import pandas as pd
32
+ import ssms
33
+ ```
34
+
35
+ #### Using the Simulators
36
+
37
+ Let's start with using the basic simulators.
38
+ You access the main simulators through the `ssms.basic_simulators.simulator` function.
39
+
40
+ To get an idea about the models included in `ssms`, use the `config` module.
41
+ The central dictionary with metadata about included models sits in `ssms.config.model_config`.
42
+
43
+
44
+ ```python
45
+ # Check included models
46
+ list(ssms.config.model_config.keys())[:10]
47
+ ```
48
+
49
+
50
+
51
+
52
+ ['ddm',
53
+ 'ddm_legacy',
54
+ 'angle',
55
+ 'weibull',
56
+ 'levy',
57
+ 'levy_angle',
58
+ 'full_ddm',
59
+ 'ornstein',
60
+ 'ornstein_angle',
61
+ 'ddm_sdv']
62
+
63
+
64
+
65
+
66
+ ```python
67
+ # Take an example config for a given model
68
+ ssms.config.model_config['ddm']
69
+ ```
70
+
71
+
72
+
73
+
74
+ {'name': 'ddm',
75
+ 'params': ['v', 'a', 'z', 't'],
76
+ 'param_bounds': [[-3.0, 0.3, 0.1, 0.0], [3.0, 2.5, 0.9, 2.0]],
77
+ 'boundary': <function ssms.basic_simulators.boundary_functions.constant(t=0)>,
78
+ 'n_params': 4,
79
+ 'default_params': [0.0, 1.0, 0.5, 0.001],
80
+ 'hddm_include': ['z'],
81
+ 'nchoices': 2}
82
+
83
+
84
+
85
+ **Note:**
86
+ The usual structure of these models includes,
87
+
88
+ - Parameter names (`'params'`)
89
+ - Bounds on the parameters (`'param_bounds'`)
90
+ - A function that defines a boundary for the respective model (`'boundary'`)
91
+ - The number of parameters (`'n_params'`)
92
+ - Defaults for the parameters (`'default_params'`)
93
+ - The number of choices the process can produce (`'nchoices'`)
94
+
95
+ The `'hddm_include'` key concerns information useful for integration with the [hddm](https://github.com/hddm-devs/hddm) python package, which facilitates hierarchical bayesian inference for sequential sampling models. It is not important for the present tutorial.
96
+
97
+
98
+ ```python
99
+ from ssms.basic_simulators import simulator
100
+ sim_out = simulator(model = 'ddm',
101
+ theta = [0, 1, 0.5, 0.5],
102
+ n_samples = 1000)
103
+ ```
104
+
105
+ The output of the simulator is a `dictionary` with three elements.
106
+
107
+ 1. `rts` (array)
108
+ 2. `choices` (array)
109
+ 3. `metadata` (dictionary)
110
+
111
+ The `metadata` includes the named parameters, simulator settings, and more.
112
+
113
+ #### Using the Training Data Generators
114
+
115
+ 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.
116
+
117
+ We will use the `data_generator` class from `ssms.dataset_generators`. Initializing the `data_generator` boils down to supplying two configuration dictionaries.
118
+
119
+ 1. The `generator_config`, concerns choices as to what kind of training data one wants to generate.
120
+ 2. The `model_config` concerns choices with respect to the underlying generative *sequential sampling model*.
121
+
122
+ We will consider a basic example here, concerning data generation to prepare for training [LANs](https://elifesciences.org/articles/65074).
123
+
124
+ Let's start by peeking at an example `generator_config`.
125
+
126
+
127
+ ```python
128
+ ssms.config.data_generator_config['lan']['mlp']
129
+ ```
130
+
131
+
132
+
133
+
134
+ {'output_folder': 'data/lan_mlp/',
135
+ 'dgp_list': 'ddm',
136
+ 'nbins': 0,
137
+ 'n_samples': 100000,
138
+ 'n_parameter_sets': 10000,
139
+ 'n_parameter_sets_rejected': 100,
140
+ 'n_training_samples_by_parameter_set': 1000,
141
+ 'max_t': 20.0,
142
+ 'delta_t': 0.001,
143
+ 'pickleprotocol': 4,
144
+ 'n_cpus': 'all',
145
+ 'kde_data_mixture_probabilities': [0.8, 0.1, 0.1],
146
+ 'simulation_filters': {'mode': 20,
147
+ 'choice_cnt': 0,
148
+ 'mean_rt': 17,
149
+ 'std': 0,
150
+ 'mode_cnt_rel': 0.9},
151
+ 'negative_rt_cutoff': -66.77497,
152
+ 'n_subruns': 10,
153
+ 'bin_pointwise': False,
154
+ 'separate_response_channels': False}
155
+
156
+
157
+
158
+ You usually have to make just few changes to this basic configuration dictionary.
159
+ An example below.
160
+
161
+
162
+ ```python
163
+ from copy import deepcopy
164
+ # Initialize the generator config (for MLP LANs)
165
+ generator_config = deepcopy(ssms.config.data_generator_config['lan']['mlp'])
166
+ # Specify generative model (one from the list of included models mentioned above)
167
+ generator_config['dgp_list'] = 'angle'
168
+ # Specify number of parameter sets to simulate
169
+ generator_config['n_parameter_sets'] = 100
170
+ # Specify how many samples a simulation run should entail
171
+ generator_config['n_samples'] = 1000
172
+ ```
173
+
174
+ Now let's define our corresponding `model_config`.
175
+
176
+
177
+ ```python
178
+ model_config = ssms.config.model_config['angle']
179
+ print(model_config)
180
+ ```
181
+
182
+ {'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}
183
+
184
+
185
+ 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.
186
+
187
+
188
+ ```python
189
+ my_dataset_generator = ssms.dataset_generators.data_generator(generator_config = generator_config,
190
+ model_config = model_config)
191
+ ```
192
+
193
+ n_cpus used: 6
194
+ checking: data/lan_mlp/
195
+
196
+
197
+
198
+ ```python
199
+ training_data = my_dataset_generator.generate_data_training_uniform(save = False)
200
+ ```
201
+
202
+ simulation round: 1 of 10
203
+ simulation round: 2 of 10
204
+ simulation round: 3 of 10
205
+ simulation round: 4 of 10
206
+ simulation round: 5 of 10
207
+ simulation round: 6 of 10
208
+ simulation round: 7 of 10
209
+ simulation round: 8 of 10
210
+ simulation round: 9 of 10
211
+ simulation round: 10 of 10
212
+
213
+
214
+ `training_data` is a dictionary containing four keys:
215
+
216
+ 1. `data` the features for [LANs](https://elifesciences.org/articles/65074), containing vectors of *model parameters*, as well as *rts* and *choices*.
217
+ 2. `labels` which contain approximate likelihood values
218
+ 3. `generator_config`, as defined above
219
+ 4. `model_config`, as defined above
220
+
221
+ You can now use this training data for your purposes. If you want to train [LANs](https://elifesciences.org/articles/65074) yourself, you might find the [LANfactory](https://github.com/AlexanderFengler/LANfactory) package helpful.
222
+
223
+ 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.
224
+
225
+ ##### END