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
        corr = solution.corr
        err = solution.err
        dt = solution.model.dt
        # Create the weights for different timepoints
        times = np.asarray(list(range(-len(corr), len(corr))))*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
        newcorr = np.convolve(weights, corr, mode="full")[len(corr):(2*len(corr))]
        newerr = np.convolve(weights, err, mode="full")[len(corr):(2*len(corr))]
        return Solution(newcorr, newerr, 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]})