saddm 0.1.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.
- saddm-0.1.0/LICENSE +21 -0
- saddm-0.1.0/PKG-INFO +103 -0
- saddm-0.1.0/README.md +68 -0
- saddm-0.1.0/pyproject.toml +43 -0
- saddm-0.1.0/saddm/__init__.py +33 -0
- saddm-0.1.0/saddm/core.py +71 -0
- saddm-0.1.0/saddm/ddmsa.py +437 -0
- saddm-0.1.0/saddm/integrator.py +200 -0
- saddm-0.1.0/saddm/model.py +113 -0
- saddm-0.1.0/saddm.egg-info/PKG-INFO +103 -0
- saddm-0.1.0/saddm.egg-info/SOURCES.txt +18 -0
- saddm-0.1.0/saddm.egg-info/dependency_links.txt +1 -0
- saddm-0.1.0/saddm.egg-info/requires.txt +24 -0
- saddm-0.1.0/saddm.egg-info/top_level.txt +1 -0
- saddm-0.1.0/setup.cfg +4 -0
- saddm-0.1.0/tests/test_core.py +94 -0
- saddm-0.1.0/tests/test_ddmsa.py +392 -0
- saddm-0.1.0/tests/test_integrator.py +107 -0
- saddm-0.1.0/tests/test_model.py +173 -0
- saddm-0.1.0/tests/test_pdf_properties.py +170 -0
saddm-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kianté Fernandez, Blair R K Shevlin, Roger Ratcliff, Ian Krajbich
|
|
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.
|
saddm-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: saddm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Drift diffusion model with across-trial variability in boundary separation (DDM-SA): differentiable PyTensor likelihood for PyMC and HSSM
|
|
5
|
+
Author: Kianté Fernandez, Blair R K Shevlin, Roger Ratcliff, Ian Krajbich
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/kiante-fernandez/saddm
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: scipy
|
|
16
|
+
Requires-Dist: pytensor
|
|
17
|
+
Provides-Extra: sampling
|
|
18
|
+
Requires-Dist: pymc>=5.20; extra == "sampling"
|
|
19
|
+
Requires-Dist: arviz; extra == "sampling"
|
|
20
|
+
Requires-Dist: jax==0.5.3; extra == "sampling"
|
|
21
|
+
Requires-Dist: jaxlib==0.5.3; extra == "sampling"
|
|
22
|
+
Requires-Dist: numpyro==0.19.0; extra == "sampling"
|
|
23
|
+
Provides-Extra: hssm
|
|
24
|
+
Requires-Dist: saddm[sampling]; extra == "hssm"
|
|
25
|
+
Requires-Dist: hssm>=0.3.0; extra == "hssm"
|
|
26
|
+
Requires-Dist: matplotlib<3.11; extra == "hssm"
|
|
27
|
+
Provides-Extra: reference
|
|
28
|
+
Requires-Dist: numba; extra == "reference"
|
|
29
|
+
Provides-Extra: test
|
|
30
|
+
Requires-Dist: pytest; extra == "test"
|
|
31
|
+
Requires-Dist: numba; extra == "test"
|
|
32
|
+
Requires-Dist: pymc>=5.20; extra == "test"
|
|
33
|
+
Requires-Dist: arviz; extra == "test"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Implementation of Diffusion decision model with across-trial variability in boundary separation
|
|
37
|
+
|
|
38
|
+
Diffusion decision model with across-trial variability in boundary separation
|
|
39
|
+
(`sa`), drift (`sv`), and non-decision time (`st`). This codebase presents the
|
|
40
|
+
DDM-SA as a fully differentiable PyTensor likelihood for gradient-based Bayesian estimation.
|
|
41
|
+
|
|
42
|
+
The likelihood is analytic (Navarro–Fuss density; drift variability integrated
|
|
43
|
+
in closed form, uniform variability by Gauss–Legendre quadrature), so NUTS gets
|
|
44
|
+
exact gradients. It is validated against the Fortran implementation the model
|
|
45
|
+
was originally developed in; the Fortran programs, the data, and reference
|
|
46
|
+
results ship in this repository so every validation is reproducible from a
|
|
47
|
+
clone.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install -e . # core: numpy, scipy, pytensor
|
|
53
|
+
pip install -e ".[sampling]" # + pymc, arviz, numpyro (pinned jax)
|
|
54
|
+
pip install -e ".[hssm]" # + hssm
|
|
55
|
+
pip install -e ".[test]" # + pytest, numba (reference backend)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from saddm import make_ddmsa_model, sample_ddmsa, sample_ddmsa_exact
|
|
62
|
+
|
|
63
|
+
data = sample_ddmsa_exact(a=1.1, z=0.5, v=1.5, t=0.25,
|
|
64
|
+
sv=0.8, sa=0.5, st=0.08, n_trials=2000)
|
|
65
|
+
idata = sample_ddmsa(make_ddmsa_model(data), backend="numpyro")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`saddm.ddmsa_logp(rt, response, a, z, v, t, sv, sa, st, sz)` is the per-trial
|
|
69
|
+
log-likelihood; every parameter may be a scalar or a per-trial vector. It has
|
|
70
|
+
no lapse mixture: HSSM applies its own `p_outlier` on top of any analytical
|
|
71
|
+
likelihood, and in plain PyMC one is a `pm.logaddexp` away.
|
|
72
|
+
|
|
73
|
+
With HSSM, register `saddm.ddmsa_logp` as a `loglik_kind="analytical"`
|
|
74
|
+
likelihood; `examples/estimate_HSSM_saddm.py` is the minimal adapter.
|
|
75
|
+
|
|
76
|
+
## Layout
|
|
77
|
+
|
|
78
|
+
| path | contents |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `saddm/` | `ddmsa.py`: the likelihood and PyMC glue. `core.py`/`integrator.py`/`model.py`: the Numba reference implementation (`reference` extra). |
|
|
81
|
+
| `tests/` | `test_ddmsa.py`: verification suite — s = 1 closed forms, agreement with the Numba/Fortran reference, finite-difference gradients, corner finiteness, per-trial broadcasting, backend agreement, static-zero collapse (run directly with `--sample` for an end-to-end NUTS check). Remaining `test_*.py` cover the Numba reference. |
|
|
82
|
+
| `verification/` | `parameter_recovery.py`: 100-config NUTS recovery study. `recovery_figure.py`, `compare_to_fortran.py`, `likelihood_figure.py`: analysis and figures (read `results/reference/` by default; set `RESULTS` for a fresh run). |
|
|
83
|
+
| `examples/` | HSSM applications: flat fit on cavanagh_theta, the per-subject + k-sweep replication of the Fortran intertemporal-choice analysis, hierarchical variants, and the random-effects figure. |
|
|
84
|
+
| `fortran/` | The Fortran programs that produced the benchmarks, with build notes. |
|
|
85
|
+
| `data/itc_amasino/` | Amasino et al. (2019) trials, the Fortran benchmarks, and the exact k-sweep permutation files. |
|
|
86
|
+
| `results/reference/` | Reference outputs: recovery, ITC, hierarchical, and cavanagh results with figures. Everything else under `results/` is gitignored, and every script writes there by default. |
|
|
87
|
+
|
|
88
|
+
## Citation
|
|
89
|
+
|
|
90
|
+
```bibtex
|
|
91
|
+
@unpublished{shevlin2026little,
|
|
92
|
+
author = {Shevlin, Blair R. K. and Fernandez, Kiant{\'e} and Ratcliff, Roger and Krajbich, Ian},
|
|
93
|
+
title = {A little goes a long way: Fitting one-shot decisions with cognitive models},
|
|
94
|
+
note = {Manuscript in preparation},
|
|
95
|
+
year = {2026},
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Blair R. K. Shevlin\* and Kianté Fernandez\* contributed equally.
|
|
100
|
+
|
|
101
|
+
:Author: Kianté Fernandez, Blair R K Shevlin, Roger Ratcliff, Ian Krajbich
|
|
102
|
+
|
|
103
|
+
:Contact: kiante@ucla.edu, blair.shevlin@mssm.edu, ratcliff.22@osu.edu, krajbich@ucla.edu
|
saddm-0.1.0/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Implementation of Diffusion decision model with across-trial variability in boundary separation
|
|
2
|
+
|
|
3
|
+
Diffusion decision model with across-trial variability in boundary separation
|
|
4
|
+
(`sa`), drift (`sv`), and non-decision time (`st`). This codebase presents the
|
|
5
|
+
DDM-SA as a fully differentiable PyTensor likelihood for gradient-based Bayesian estimation.
|
|
6
|
+
|
|
7
|
+
The likelihood is analytic (Navarro–Fuss density; drift variability integrated
|
|
8
|
+
in closed form, uniform variability by Gauss–Legendre quadrature), so NUTS gets
|
|
9
|
+
exact gradients. It is validated against the Fortran implementation the model
|
|
10
|
+
was originally developed in; the Fortran programs, the data, and reference
|
|
11
|
+
results ship in this repository so every validation is reproducible from a
|
|
12
|
+
clone.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install -e . # core: numpy, scipy, pytensor
|
|
18
|
+
pip install -e ".[sampling]" # + pymc, arviz, numpyro (pinned jax)
|
|
19
|
+
pip install -e ".[hssm]" # + hssm
|
|
20
|
+
pip install -e ".[test]" # + pytest, numba (reference backend)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from saddm import make_ddmsa_model, sample_ddmsa, sample_ddmsa_exact
|
|
27
|
+
|
|
28
|
+
data = sample_ddmsa_exact(a=1.1, z=0.5, v=1.5, t=0.25,
|
|
29
|
+
sv=0.8, sa=0.5, st=0.08, n_trials=2000)
|
|
30
|
+
idata = sample_ddmsa(make_ddmsa_model(data), backend="numpyro")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`saddm.ddmsa_logp(rt, response, a, z, v, t, sv, sa, st, sz)` is the per-trial
|
|
34
|
+
log-likelihood; every parameter may be a scalar or a per-trial vector. It has
|
|
35
|
+
no lapse mixture: HSSM applies its own `p_outlier` on top of any analytical
|
|
36
|
+
likelihood, and in plain PyMC one is a `pm.logaddexp` away.
|
|
37
|
+
|
|
38
|
+
With HSSM, register `saddm.ddmsa_logp` as a `loglik_kind="analytical"`
|
|
39
|
+
likelihood; `examples/estimate_HSSM_saddm.py` is the minimal adapter.
|
|
40
|
+
|
|
41
|
+
## Layout
|
|
42
|
+
|
|
43
|
+
| path | contents |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `saddm/` | `ddmsa.py`: the likelihood and PyMC glue. `core.py`/`integrator.py`/`model.py`: the Numba reference implementation (`reference` extra). |
|
|
46
|
+
| `tests/` | `test_ddmsa.py`: verification suite — s = 1 closed forms, agreement with the Numba/Fortran reference, finite-difference gradients, corner finiteness, per-trial broadcasting, backend agreement, static-zero collapse (run directly with `--sample` for an end-to-end NUTS check). Remaining `test_*.py` cover the Numba reference. |
|
|
47
|
+
| `verification/` | `parameter_recovery.py`: 100-config NUTS recovery study. `recovery_figure.py`, `compare_to_fortran.py`, `likelihood_figure.py`: analysis and figures (read `results/reference/` by default; set `RESULTS` for a fresh run). |
|
|
48
|
+
| `examples/` | HSSM applications: flat fit on cavanagh_theta, the per-subject + k-sweep replication of the Fortran intertemporal-choice analysis, hierarchical variants, and the random-effects figure. |
|
|
49
|
+
| `fortran/` | The Fortran programs that produced the benchmarks, with build notes. |
|
|
50
|
+
| `data/itc_amasino/` | Amasino et al. (2019) trials, the Fortran benchmarks, and the exact k-sweep permutation files. |
|
|
51
|
+
| `results/reference/` | Reference outputs: recovery, ITC, hierarchical, and cavanagh results with figures. Everything else under `results/` is gitignored, and every script writes there by default. |
|
|
52
|
+
|
|
53
|
+
## Citation
|
|
54
|
+
|
|
55
|
+
```bibtex
|
|
56
|
+
@unpublished{shevlin2026little,
|
|
57
|
+
author = {Shevlin, Blair R. K. and Fernandez, Kiant{\'e} and Ratcliff, Roger and Krajbich, Ian},
|
|
58
|
+
title = {A little goes a long way: Fitting one-shot decisions with cognitive models},
|
|
59
|
+
note = {Manuscript in preparation},
|
|
60
|
+
year = {2026},
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Blair R. K. Shevlin\* and Kianté Fernandez\* contributed equally.
|
|
65
|
+
|
|
66
|
+
:Author: Kianté Fernandez, Blair R K Shevlin, Roger Ratcliff, Ian Krajbich
|
|
67
|
+
|
|
68
|
+
:Contact: kiante@ucla.edu, blair.shevlin@mssm.edu, ratcliff.22@osu.edu, krajbich@ucla.edu
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "saddm"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Drift diffusion model with across-trial variability in boundary separation (DDM-SA): differentiable PyTensor likelihood for PyMC and HSSM"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Kianté Fernandez" },
|
|
13
|
+
{ name = "Blair R K Shevlin" },
|
|
14
|
+
{ name = "Roger Ratcliff" },
|
|
15
|
+
{ name = "Ian Krajbich" },
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.11"
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Topic :: Scientific/Engineering",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"numpy",
|
|
25
|
+
"scipy",
|
|
26
|
+
"pytensor",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/kiante-fernandez/saddm"
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
# jax is pinned: jax 0.10 silently freezes numpyro NUTS at its initial point.
|
|
34
|
+
sampling = ["pymc>=5.20", "arviz", "jax==0.5.3", "jaxlib==0.5.3", "numpyro==0.19.0"]
|
|
35
|
+
hssm = ["saddm[sampling]", "hssm>=0.3.0", "matplotlib<3.11"]
|
|
36
|
+
reference = ["numba"]
|
|
37
|
+
test = ["pytest", "numba", "pymc>=5.20", "arviz"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools]
|
|
40
|
+
packages = ["saddm"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
saddm - Drift Diffusion Model with across-trial variability in boundary separation.
|
|
3
|
+
|
|
4
|
+
Parameters (s = 1): a boundary separation, z relative start point in (0, 1),
|
|
5
|
+
v drift rate, t non-decision time (seconds); sv Gaussian drift variability;
|
|
6
|
+
sa, st, sz uniform full-width variability of boundary, non-decision time, and
|
|
7
|
+
start point.
|
|
8
|
+
|
|
9
|
+
The Numba reference implementation (saddm.core, saddm.integrator, saddm.model)
|
|
10
|
+
needs the `reference` extra and is imported explicitly.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
|
|
15
|
+
from .ddmsa import (
|
|
16
|
+
DDMSA,
|
|
17
|
+
ddmsa_logp,
|
|
18
|
+
ddmsa_potential,
|
|
19
|
+
make_ddmsa_model,
|
|
20
|
+
sample_ddmsa,
|
|
21
|
+
sample_ddmsa_exact,
|
|
22
|
+
simulate_ddmsa,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"ddmsa_logp",
|
|
27
|
+
"ddmsa_potential",
|
|
28
|
+
"DDMSA",
|
|
29
|
+
"make_ddmsa_model",
|
|
30
|
+
"sample_ddmsa",
|
|
31
|
+
"sample_ddmsa_exact",
|
|
32
|
+
"simulate_ddmsa",
|
|
33
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from numba import njit, float64
|
|
2
|
+
from math import pi, sqrt, exp, log, sin, ceil, floor
|
|
3
|
+
|
|
4
|
+
@njit(float64(float64, float64, float64), cache=True)
|
|
5
|
+
def ftt_01w(tt, w, err):
|
|
6
|
+
"""Compute f(t|0,1,w) following Navarro & Fuss, 2009."""
|
|
7
|
+
# calculate number of terms needed for large t
|
|
8
|
+
if pi * tt * err < 1:
|
|
9
|
+
kl = sqrt(-2 * log(pi * tt * err) / (pi * pi * tt))
|
|
10
|
+
kl = max(kl, 1. / (pi * sqrt(tt)))
|
|
11
|
+
else:
|
|
12
|
+
kl = 1. / (pi * sqrt(tt))
|
|
13
|
+
|
|
14
|
+
# calculate number of terms needed for small t
|
|
15
|
+
if 2 * sqrt(2 * pi * tt) * err < 1:
|
|
16
|
+
ks = 2 + sqrt(-2 * tt * log(2 * sqrt(2 * pi * tt) * err))
|
|
17
|
+
ks = max(ks, sqrt(tt) + 1)
|
|
18
|
+
else:
|
|
19
|
+
ks = 2
|
|
20
|
+
|
|
21
|
+
# compute f(tt|0,1,w)
|
|
22
|
+
p = 0.0
|
|
23
|
+
if ks < kl: # small t approximation
|
|
24
|
+
K = int(ceil(ks))
|
|
25
|
+
lower = -int(floor((K-1)/2))
|
|
26
|
+
upper = int(ceil((K-1)/2))
|
|
27
|
+
for k in range(lower, upper + 1):
|
|
28
|
+
p += (w + 2 * k) * exp(-(pow(w + 2 * k, 2)) / 2 / tt)
|
|
29
|
+
p /= sqrt(2 * pi * pow(tt, 3))
|
|
30
|
+
else: # large t approximation
|
|
31
|
+
K = int(ceil(kl))
|
|
32
|
+
for k in range(1, K + 1):
|
|
33
|
+
p += k * exp(-(k * k) * (pi * pi) * tt / 2) * sin(k * pi * w)
|
|
34
|
+
p *= pi
|
|
35
|
+
|
|
36
|
+
return p
|
|
37
|
+
|
|
38
|
+
@njit(float64(float64, float64, float64, float64, float64, float64),
|
|
39
|
+
cache=True)
|
|
40
|
+
def ddm_pdf_core(rt, a, z, v, ter, sv):
|
|
41
|
+
"""Core DDM PDF calculation including drift rate variability.
|
|
42
|
+
|
|
43
|
+
Parameters use diffusion coefficient s=1:
|
|
44
|
+
rt: response time (seconds)
|
|
45
|
+
a: boundary separation (~0.65-2.4)
|
|
46
|
+
z: relative starting point (0 to 1, e.g. 0.5 for unbiased)
|
|
47
|
+
v: drift rate (~0.1-0.5)
|
|
48
|
+
ter: non-decision time (seconds)
|
|
49
|
+
sv: drift rate variability (Gaussian SD)
|
|
50
|
+
"""
|
|
51
|
+
if rt <= 0 or rt <= ter or a <= 0:
|
|
52
|
+
return 0.0
|
|
53
|
+
|
|
54
|
+
tt = (rt - ter) / (a * a)
|
|
55
|
+
err = 1e-4
|
|
56
|
+
p = ftt_01w(tt, z, err)
|
|
57
|
+
|
|
58
|
+
if sv <= 1e-10:
|
|
59
|
+
return p * exp(-v * a * z - (v * v * (rt - ter)) / 2.) / (a * a)
|
|
60
|
+
else:
|
|
61
|
+
sv_squared_rt = sv * sv * (rt - ter)
|
|
62
|
+
|
|
63
|
+
if sv_squared_rt > 100:
|
|
64
|
+
return 0.0
|
|
65
|
+
|
|
66
|
+
exp_term = ((a * z * sv)**2 - 2 * a * v * z - (v * v) * (rt - ter)) / (2 * (sv_squared_rt + 1))
|
|
67
|
+
scaling = 1 / sqrt(sv_squared_rt + 1)
|
|
68
|
+
if exp_term < -500 or exp_term > 500:
|
|
69
|
+
return 0.0
|
|
70
|
+
|
|
71
|
+
return p * exp(exp_term) * scaling / (a * a)
|