Skip to content

Compute DDM log density in log space for stable AD and Turing sampling - #139

Open
rsenne wants to merge 2 commits into
itsdfish:masterfrom
rsenne:ddm-AD-enhancements
Open

rsenne wants to merge 2 commits into
itsdfish:masterfrom
rsenne:ddm-AD-enhancements

Conversation

@rsenne

@rsenne rsenne commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

There has been a set of issues I've found in the DDM that has been causing me some issues and this PR fixes many of the sharp edges I've found. There may be more, but I have found these changes make the model more robust.

DDM used to compute its density on the natural scale and then take log(pdf(...)). For small boundary separations, very short or very long RTs, or large drift rates, the density underflowed to 0. That produced logpdf = -Inf with NaN gradients, which breaks HMC/NUTS in Turing. logpdf also threw an ArgumentError for rt ≤ τ, which aborts sampling instead of rejecting the proposal.

This PR computes logpdf directly in log space and defines pdf as exp(logpdf).

cc: @PTWaade

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results

master 6f9c221... master / 6f9c221...
logpdf/("SequentialSamplingModels.DDM", 10) 1.74 ± 0.13 μs 1.74 ± 0.11 μs 0.998 ± 0.099
logpdf/("SequentialSamplingModels.DDM", 100) 16.8 ± 0.93 μs 16.8 ± 0.79 μs 1 ± 0.073
logpdf/("SequentialSamplingModels.LBA", 10) 2.94 ± 0.18 μs 2.92 ± 0.17 μs 1.01 ± 0.086
logpdf/("SequentialSamplingModels.LBA", 100) 22.6 ± 0.8 μs 22.4 ± 0.82 μs 1.01 ± 0.052
logpdf/("SequentialSamplingModels.LNR", 10) 1.68 ± 0.26 μs 1.67 ± 0.14 μs 1.01 ± 0.18
logpdf/("SequentialSamplingModels.LNR", 100) 9.15 ± 0.46 μs 9.15 ± 0.54 μs 1 ± 0.077
logpdf/("SequentialSamplingModels.RDM", 10) 2.65 ± 0.29 μs 2.61 ± 0.26 μs 1.02 ± 0.15
logpdf/("SequentialSamplingModels.RDM", 100) 23.5 ± 0.98 μs 23.6 ± 1 μs 0.998 ± 0.06
logpdf/("SequentialSamplingModels.Wald", 10) 1.33 ± 0.018 μs 1.33 ± 0.018 μs 0.998 ± 0.019
logpdf/("SequentialSamplingModels.Wald", 100) 11.5 ± 0.24 μs 11.4 ± 0.22 μs 1.01 ± 0.029
rand/("SequentialSamplingModels.DDM", 10) 3.18 ± 0.43 μs 3.17 ± 0.47 μs 1 ± 0.2
rand/("SequentialSamplingModels.DDM", 100) 30.3 ± 1.6 μs 30.2 ± 1.7 μs 1 ± 0.077
rand/("SequentialSamplingModels.LBA", 10) 1.71 ± 0.079 μs 1.73 ± 0.071 μs 0.99 ± 0.061
rand/("SequentialSamplingModels.LBA", 100) 11.9 ± 1.4 μs 11.8 ± 1.3 μs 1.01 ± 0.16
rand/("SequentialSamplingModels.LCA", 10) 0.53 ± 0.17 ms 0.534 ± 0.21 ms 0.992 ± 0.51
rand/("SequentialSamplingModels.LCA", 100) 5.74 ± 0.22 ms 5.95 ± 0.14 ms 0.965 ± 0.043
rand/("SequentialSamplingModels.LNR", 10) 1.16 ± 0.056 μs 1.21 ± 0.12 μs 0.964 ± 0.1
rand/("SequentialSamplingModels.LNR", 100) 9.2 ± 3.2 μs 8.89 ± 2.9 μs 1.04 ± 0.5
rand/("SequentialSamplingModels.RDM", 10) 1.19 ± 0.056 μs 1.17 ± 0.052 μs 1.02 ± 0.066
rand/("SequentialSamplingModels.RDM", 100) 9.65 ± 0.4 μs 9.44 ± 0.39 μs 1.02 ± 0.06
rand/("SequentialSamplingModels.Wald", 10) 1.37 ± 0.028 μs 1.36 ± 0.029 μs 1.01 ± 0.03
rand/("SequentialSamplingModels.Wald", 100) 12 ± 0.12 μs 11.9 ± 0.13 μs 1.01 ± 0.015
simulate/SequentialSamplingModels.DDM 2.07 ± 0.65 μs 2.1 ± 0.65 μs 0.984 ± 0.43
simulate/SequentialSamplingModels.LBA 5.14 ± 1.7 μs 5.82 ± 3.3 μs 0.883 ± 0.58
simulate/SequentialSamplingModels.LCA 0.0729 ± 0.015 ms 0.0731 ± 0.013 ms 0.997 ± 0.28
simulate/SequentialSamplingModels.RDM 0.0621 ± 0.024 ms 0.0637 ± 0.024 ms 0.975 ± 0.52
simulate/SequentialSamplingModels.Wald 2.19 ± 0.63 μs 2.14 ± 0.61 μs 1.02 ± 0.41
simulate/mdft 0.16 ± 0.06 ms 0.169 ± 0.06 ms 0.949 ± 0.49
time_to_load 1.36 ± 0.0096 s 1.39 ± 0.021 s 0.982 ± 0.017

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@rsenne rsenne mentioned this pull request Oct 6, 2026
Comment thread test/multi_choice_models/ddm_tests.jl

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants