ADDM.cpp
Loading...
Searching...
No Matches
DDM Class Reference

Implementation of the Drift Diffusion Model (DDM). More...

#include <ddm.h>

Public Member Functions

bool operator< (const DDM &rhs) const
 
bool operator== (const DDM &rhs) const
 
 DDM (float d, float sigma, float barrier=1, unsigned int nonDecisionTime=0, float bias=0, float decay=0)
 Construct a new DDM object.
 
 DDM ()
 Construct an empty DDM object.
 
void exportTrial (DDMTrial dt, std::string filename)
 Export the data pertaining to a single DDM and DDMTrial to a JSON file.
 
double getTrialLikelihood (DDMTrial trial, bool debug=false, int timeStep=10, float stateStep=0.01)
 Compute the likelihood of the trial results provided the current parameters.
 
DDMTrial simulateTrial (float valueLeft, float valueRight, int timeStep=10, int seed=-1)
 Generate a simulated DDM trial provided item values.
 
ProbabilityData computeParallelNLL (vector< DDMTrial > trials, bool debug=false, int timeStep=10, float stateStep=0.01)
 Compute the total Negative Log Likelihood (NLL) for a vector of DDMTrials. Use CPU multithreading to maximize the number of blocks of trials that can have their respective NLLs computed in parallel.
 

Static Public Member Functions

static MLEinfo< DDM > fitModelMLE (vector< DDMTrial > trials, vector< float > rangeD, vector< float > rangeSigma, string computeMethod="basic", bool normalizePosteriors=false, float barrier=1, unsigned int nonDecisionTime=0, vector< float > bias={0}, vector< float > decay={0})
 Copmlete a grid-search based Maximum Likelihood Estimation of all possible paramters combinations (d, sigma) to determine which parameters are most likely to generate the provided DDMTrials. Each potential model generates an NLL value for the dataset and the method returns the model with the minimum NLL value.
 

Public Attributes

float d
 
float sigma
 
float barrier
 
unsigned int nonDecisionTime
 
float bias
 
float decay
 

Detailed Description

Implementation of the Drift Diffusion Model (DDM).

This class contains an implementation of the Drift Diffusion Model (DDM) as described by Ratcliff et al. (1998). This class provides methods for data simulation and model fitting via Maximum Likelihood Estimation. The processes of model fiting involves selecting some range of potential parameters (d, sigma) and iterating over the parameter space to determine which combination best fits the provided set of DDMTrials. For details on the simulation and model fitting process, see the individual methods described below.

Constructor & Destructor Documentation

◆ DDM() [1/2]

DDM::DDM ( float d,
float sigma,
float barrier = 1,
unsigned int nonDecisionTime = 0,
float bias = 0,
float decay = 0 )

Construct a new DDM object.

Parameters
dDrift rate.
sigmaNoise or standard deviation for the normal distribution.
barrierPositive magnitude of the signal threshold.
nonDecisionTimeAmount of time in milliseconds in which only noise is added to the decision variable.
biasCorresponds to the initial value of the decision variable. Must be smaller than the barrier.
decayControls the decay of the RDV barriers over time.

◆ DDM() [2/2]

DDM::DDM ( )
inline

Construct an empty DDM object.

Member Function Documentation

◆ computeParallelNLL()

ProbabilityData DDM::computeParallelNLL ( vector< DDMTrial > trials,
bool debug = false,
int timeStep = 10,
float stateStep = 0.01 )

Compute the total Negative Log Likelihood (NLL) for a vector of DDMTrials. Use CPU multithreading to maximize the number of blocks of trials that can have their respective NLLs computed in parallel.

Parameters
trialsVector of DDMTrials that the model should calculate the NLL for.
debugBoolean specifying if state variables should be printed for debugging purposes.
timeStepValue in milliseconds used for binning the time axis.
stateStepUsed for binning the RDV axis.
Returns
ProbabilityData containing NLL, sum of likelihoods, and a list of all computed likelihood.

◆ exportTrial()

void DDM::exportTrial ( DDMTrial dt,
std::string filename )

Export the data pertaining to a single DDM and DDMTrial to a JSON file.

Parameters
dtTrial to export
filenameFile to store the trial information in.

◆ fitModelMLE()

MLEinfo< DDM > DDM::fitModelMLE ( vector< DDMTrial > trials,
vector< float > rangeD,
vector< float > rangeSigma,
string computeMethod = "basic",
bool normalizePosteriors = false,
float barrier = 1,
unsigned int nonDecisionTime = 0,
vector< float > bias = {0},
vector< float > decay = {0} )
static

Copmlete a grid-search based Maximum Likelihood Estimation of all possible paramters combinations (d, sigma) to determine which parameters are most likely to generate the provided DDMTrials. Each potential model generates an NLL value for the dataset and the method returns the model with the minimum NLL value.

Parameters
trialsVector of DDMTrials that each model should calculate the NLL for.
rangeDVector of floats representing possible values of d to dest for.
rangeSigmaVector of floats representing possible values of sigma to test for.
computeMethodComputation method to calculate the NLL for each possible model. Allowed values are {basic, thread, gpu}. "basic" will compute each trial likelihood sequentially and compute the NLL as the sum of all negative log likelihoods. "thread" will use a thread pool to divide all trials into the maximum number of CPU threads and compute the NLL of each block of trials in parallel. "gpu" will call a CUDA kernel to compute the likelihood of each trial in parallel on the GPU.
normalizePosteriorstrue if the returned MLEinfo should contain a mapping of aDDMs to the normzlied posteriors distribution for each model; otherwise, the MLEinfo should containing a mapping of aDDMs to its corresponding NLL.
barrierPositive magnitude of the sigmal threshold.
nonDecisionTimeAmount of time in milliseconds in which only noise is added to the decision variable.
biasCorresponds to the initial RDV. Must be smaller than the barrier. Possible input forms are: (1) No input - the standard bias of 0 is assumed for all potential DDM models to check. (2) Single input (vector with one element) - i.e. {0.03} - the specified input bias is assumed for all potential models. (3) Range of inputs - i.e. {-0.12, 0, 0.12} - the input range is processed as another dimension to check and a new set of models will be tested with all possible combinations of biases.
decayCorresponds to the decay of the barriers over time. A decay of zero means that the barriers are constant. Similarly to the bias argument, the three input forms of no input, a vector with single element, and a vector with a range of elements.
Returns
MLEinfo containing the most optimal model and a mapping of models to floats determined by the normalizePosteriors argument.

◆ getTrialLikelihood()

double DDM::getTrialLikelihood ( DDMTrial trial,
bool debug = false,
int timeStep = 10,
float stateStep = 0.01 )

Compute the likelihood of the trial results provided the current parameters.

Parameters
trialDDMTrial object.
debugBoolean specifying if state variables should be printed for debugging purposes.
timeStepValue in milliseconds used for binning the time axis.
stateStepUsed for binning the RDV axis.
Returns
double representing the likelihood for the given trial.

◆ operator<()

bool DDM::operator< ( const DDM & rhs) const
inline

◆ operator==()

bool DDM::operator== ( const DDM & rhs) const
inline

◆ simulateTrial()

DDMTrial DDM::simulateTrial ( float valueLeft,
float valueRight,
int timeStep = 10,
int seed = -1 )

Generate a simulated DDM trial provided item values.

Parameters
valueLeftValue of the left item.
valueRightValue of the right item.
timeStepValue in milliseconds used for binning the time axis.
seedused for standardizing any random number generators.
Returns
DDMTrial resulting from the simulation.

Member Data Documentation

◆ barrier

float DDM::barrier

Positive float representing the magnitude of the signal threshold.

◆ bias

float DDM::bias

Float corresponding to the initial RDV. Must be smaller than the barrier.

◆ d

float DDM::d

Float parameter of the model that controls the speed of integration. Referred to as drift rate.

◆ decay

float DDM::decay

Parameter that controls the decay of the barriers over time. A decay of zero means the barriers are constant.

◆ nonDecisionTime

unsigned int DDM::nonDecisionTime

Non-negative integer representing the amount of time in milliseconds in which only noise is added to the decision variable.

◆ sigma

float DDM::sigma

Float parameter of the model that control noise of the RDV signal and standard deviation for any sampled normal distributions.


The documentation for this class was generated from the following files: