GLShortMemory

GLShortMemory#

class brainpy.integrators.fde.GLShortMemory(f, alpha, inits, num_memory, dt=None, name=None, state_delays=None)[source]#

Efficient Computation of the Short-Memory Principle in Grünwald-Letnikov Method [1].

According to the explicit numerical approximation of Grünwald-Letnikov, the fractional-order derivative \(q\) for a discrete function \(f(t_K)\) can be described as follows:

\[{{}_{k-\frac{L_{m}}{h}}D_{t_{k}}^{q}}f(t_{k})\approx h^{-q} \sum\limits_{j=0}^{k}C_{j}^{q}f(t_{k-j})\]

where \(L_{m}\) is the memory lenght, \(h\) is the integration step size, and \(C_{j}^{q}\) are the binomial coefficients which are calculated recursively with

\[C_{0}^{q}=1,\ C_{j}^{q}=\left(1- \frac{1+q}{j}\right)C_{j-1}^{q},\ j=1,2, \ldots k.\]

Then, the numerical solution for a fractional-order differential equation (FODE) expressed in the form

\[D_{t_{k}}^{q}x(t_{k})=f(x(t_{k}))\]

can be obtained by

\[x(t_{k})=f(x(t_{k-1}))h^{q}- \sum\limits_{j=1}^{k}C_{j}^{q}x(t_{k-j}).\]

for \(0 < q < 1\). The above expression requires infinity memory length for numerical solution since the summation term depends on the discritized time \(t_k\). This implies relatively high simulation times.

To reduce the computational time, the upper bound of summation needs to be modified by \(k=v\), where

\[\begin{split}v=\begin{cases} k, & k\leq M,\\ L_{m}, & k > M. \end{cases}\end{split}\]

This is known as the short-memory principle, where \(M\) is the memory window with a width defined by \(M=\frac{L_{m}}{h}\). As was reported in [2], the accuracy increases by increaing the width of memory window.

Examples

>>> import brainpy as bp
>>>
>>> a, b, c = 10, 28, 8 / 3
>>> def lorenz(x, y, z, t):
>>>   dx = a * (y - x)
>>>   dy = x * (b - z) - y
>>>   dz = x * y - c * z
>>>   return dx, dy, dz
>>>
>>> integral = bp.fde.GLShortMemory(lorenz,
>>>                                 alpha=0.96,
>>>                                 num_memory=500,
>>>                                 inits=[1., 0., 1.])
>>> runner = bp.IntegratorRunner(integral,
>>>                              monitors=list('xyz'),
>>>                              inits=[1., 0., 1.],
>>>                              dt=0.005)
>>> runner.run(100.)
>>>
>>> import matplotlib.pyplot as plt
>>> plt.plot(runner.mon.x.flatten(), runner.mon.z.flatten())
>>> plt.show()
Parameters:
  • f (callable) – The derivative function.

  • alpha (int, float, jnp.ndarray, bm.ndarray, sequence) – The fractional-order of the derivative function. Should be in the range of (0., 1.).

  • num_memory (int) –

    The length of the short memory.

    Changed in version 2.1.11.

  • inits (sequence) – A sequence of the initial values for variables.

  • dt (float, int) – The numerical precision.

  • name (str) – The integrator name.

References

reset(inits)[source]#

Reset function of the delay variables.