Drawing event times from a truncated exponential distribution

Hi Chris -

Im CCing our new team member Yuan (Taylor) Xie who is taking over from Neel (who started a PhD program at NYU). Taylor spent time as an NYU undergrad in Tony Movshon’s lab - so she has managed to pick up our MWorks needs pretty fast!

Im writing because we would like to implement a function/plug-in in MWorks for drawing values for particular trial events (e.g a time requirement for fixating a stimulus) from a distribution with specific properties (truncated exponential).

We have code from colleagues in Mike Shadlen’s lab here that implements this in C or Matlab (attached).

For example, in the Matlab version, we feed in a mean_time, min_time and max_time:

tOut = exponential_timer(mean_time, min_time, max_time)

Is it possible to implement something like this for us fairly soon? Any other suggestions for how we might implement it ourselves easily?

Many thanks,

exponential_timer.c (1.49 KB)

exponential_timer.m (758 Bytes)

Hi Yasmine & Taylor,

MWorks already has a truncated exponential distribution function. See Random Number Generators in the user manual. The function’s implementation looks just like the code you shared. If you want some other type of distribution, the quickest way to get it would be to implement it in Python.

FYI: I’m going to be on vacation for the next two weeks, so I may not be able to answer follow-up questions until I return.


Hi Chris -

Perfect! We’ll try this function and see how it works for us. This looks very similar to ours indeed.


Random number from exponential distribution with mean beta+min, optionally truncated at max. min and max are both optional and default to zero and positive infinity, respectively.