dcmri.expconv#
- dcmri.expconv(f, T, t=None, dt=1.0)[source]#
Convolve a 1D-array with a normalised exponential.
This function returns the convolution \(f(t)\otimes\exp(-t/T)/T\) using an efficient and accurate numerical formula, as detailed in the appendix of Flouri et al (2016)
- Parameters:
f (array_like) – the 1D array to be convolved.
T (float) – the characteristic time of the normalized exponential function.
t (array_like, optional) – the time points where the values of f are defined, in the same units as T. If t=None, the time points are assumed to be uniformly spaced with spacing dt. Defaults to None.
dt (float, optional) – spacing between time points for uniformly spaced time points. This parameter is ignored if t is explicity provided. Defaults to 1.0.
- Returns:
a 1D numpy array of the same length as f.
- Return type:
Notes
expconv
implements the same convolution product asconv
, but is more accurate and faster in the special case where one of the factors is known to be an exponential:\[g(t) = \frac{e^{-t/T}}{T} \otimes f(t)\]In code this translates as:
g = expconv(f, T, t)
expconv
should be used instead ofconv
whenever this applies. Since the transit time distribution of a compartment is exponential, this is an important use case.expconv
can calculate a convolution between two exponential factors, but in that case an analytical formula can be used which is faster and more accurate. It is implemented in the functionbiexpconv
.Example
Import package and create a vector f:
>>> import dcmri as dc >>> f = [5,4,3,6]
Calculate \(g(t) = f(t) \otimes \exp(-t/3)/3\) over a uniformly sampled grid of time points with spacing dt=1:
>>> dc.expconv(f, 3) array([0. , 1.26774952, 1.89266305, 2.6553402 ])
Calculate the same convolution over a grid of time points with spacing dt=2:
>>> dc.expconv(f, 3, dt=2) array([0. , 2.16278873, 2.7866186 , 3.70082337])
Calculate the same convolution over a non-uniform grid of time points:
>>> t = [0,1,3,7] >>> dc.expconv(f, 3, t) array([0. , 1.26774952, 2.32709015, 4.16571645])
Examples using dcmri.expconv
#
A comparison of convolution functions