Recipes for Non-Decision Time

General use of non-decision time

The simplest way to incorporate a non-decision time is to use the built-in OverlayNonDecision, for example:

from pyddm import Model, Fittable, OverlayNonDecision
from pyddm.plot import model_gui
model = Model(overlay=OverlayNonDecision(nondectime=Fittable(minval=0, maxval=.8)),
              dx=.01, dt=.01)
model_gui(model)

Gaussian-distributed non-decision time

import numpy as np
import scipy
from pyddm import Overlay, Solution
class OverlayNonDecisionGaussian(Overlay):
    name = "Add a Gaussian-distributed non-decision time"
    required_parameters = ["nondectime", "ndsigma"]
    def apply(self, solution):
        # Make sure params are within range
        assert self.ndsigma > 0, "Invalid st parameter"
        # Extract components of the solution object for convenience
        choice_upper = solution.choice_upper
        choice_lower = solution.choice_lower
        dt = solution.dt
        # Create the weights for different timepoints
        times = np.asarray(list(range(-len(choice_upper), len(choice_upper))))*dt
        weights = scipy.stats.norm(scale=self.ndsigma, loc=self.nondectime).pdf(times)
        if np.sum(weights) > 0:
            weights /= np.sum(weights) # Ensure it integrates to 1
        newchoice_upper = np.convolve(weights, choice_upper, mode="full")[len(choice_upper):(2*len(choice_upper))]
        newchoice_lower = np.convolve(weights, choice_lower, mode="full")[len(choice_upper):(2*len(choice_upper))]
        return Solution(newchoice_upper, newchoice_lower, solution.model,
                        solution.conditions, solution.undec)

Try it out with:

from pyddm import Model, Fittable, OverlayNonDecision
from pyddm.plot import model_gui
model = Model(overlay=OverlayNonDecisionGaussian(
                  nondectime=Fittable(minval=0, maxval=.8),
                  ndsigma=Fittable(minval=0, maxval=.8)),
              dx=.01, dt=.01)
model_gui(model)

Different non-decision time for left and right trials

Here we show an example of a non-decision time which depends on both the trial conditions and mulitiple parameters. In this case, we use a different non-decision time based on whether a stimulus was presented on the left or right side of the subject.

import numpy as np
from pyddm import OverlayNonDecision, Solution
class OverlayNonDecisionLR(OverlayNonDecision):
    name = "Separate non-decision time for left and right sides"
    required_parameters = ["nondectimeL", "nondectimeR"]
    required_conditions = ["side"] # Side coded as 0=L or 1=R
    def get_nondecision_time(self, conditions):
        assert conditions['side'] in [0, 1], "Invalid side"
        return self.nondectimeL if conditions['side'] == 0 else self.nondectimeR

Try it out with:

from pyddm import Model, Fittable, OverlayNonDecision
from pyddm.plot import model_gui
model = Model(overlay=OverlayNonDecisionLR(
                  nondectimeL=Fittable(minval=0, maxval=.8),
                  nondectimeR=Fittable(minval=0, maxval=.8)),
              dx=.01, dt=.01)
model_gui(model, conditions={"side": [0, 1]})