Skip to content

Commit 555dccb

Browse files
Update docstrings in vbjax/loops.py
- Add `method` parameter to `make_ode` docstring. - Add `unroll` and `zero_delays` parameters to `make_sdde` docstring. - Expand `make_dde` docstring to include parameters, returns, and example. - Expand `make_continuation` docstring to include parameters and returns. Co-authored-by: maedoc <5189886+maedoc@users.noreply.github.com>
1 parent e3c84a2 commit 555dccb

1 file changed

Lines changed: 66 additions & 12 deletions

File tree

vbjax/loops.py

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def make_ode(dt, dfun, adhoc=None, method='heun'):
189189
adhoc : function or None
190190
Function of the form `f(x, p)` that allows making adhoc corrections
191191
to states after a step.
192+
method : str
193+
Integration method - ``'euler'``, ``'heun'``, or ``'rk4'``.
194+
Default is ``'heun'``.
192195
193196
Returns
194197
=======
@@ -232,7 +235,44 @@ def op(x, t):
232235

233236

234237
def make_dde(dt, nh, dfun, unroll=10, adhoc=None):
235-
"Invokes make_sdde w/ gfun 0."
238+
"""Use a Heun scheme to integrate autonomous delay differential equations (DDEs).
239+
240+
This is a convenience wrapper around ``make_sdde`` with zero noise.
241+
242+
Parameters
243+
==========
244+
dt : float
245+
Time step
246+
nh : int
247+
Maximum delay in time steps.
248+
dfun : function
249+
Function of the form `dfun(xt, x, t, p)` that computes drift coefficients of
250+
the differential equation.
251+
unroll : int
252+
Loop unroll factor for performance. Default is 10.
253+
adhoc : function or None
254+
Function of the form `f(x,p)` that allows making adhoc corrections after
255+
each step.
256+
257+
Returns
258+
=======
259+
step : function
260+
Function of the form `step((x_t,t), z_t, p)` that takes one step in time
261+
according to the Heun scheme.
262+
loop : function
263+
Function of the form `loop((xs, t), p)` that iteratively calls `step`
264+
for each `xs[nh:]` and starting time index `t`.
265+
266+
Example
267+
=======
268+
>>> import vbjax as vb, jax.numpy as np
269+
>>> def dfun(xt, x, t, p):
270+
... return -xt[t-2]
271+
>>> _, dde = vb.make_dde(1.0, 2, dfun)
272+
>>> x,t = dde(np.ones(6)+10, None)
273+
>>> x
274+
Array([ 11., 11., 11., 0., -11., -22.], dtype=float32)
275+
"""
236276
return make_sdde(dt, nh, dfun, 0, unroll, adhoc=adhoc)
237277

238278

@@ -257,6 +297,10 @@ def make_sdde(dt, nh, dfun, gfun, unroll=1, zero_delays=False, adhoc=None):
257297
adhoc : function or None
258298
Function of the form `f(x,p)` that allows making adhoc corrections after
259299
each step.
300+
unroll : int
301+
Loop unroll factor for performance. Default is 1.
302+
zero_delays : bool
303+
Include predictor in history (performance vs accuracy). Default is False.
260304
261305
Returns
262306
=======
@@ -358,19 +402,29 @@ def loop(buf, p, t=0):
358402
def make_continuation(run_chunk, chunk_len, max_lag, n_from, n_svar, stochastic=True):
359403
"""
360404
Helper function to lower memory usage for longer simulations with time delays.
361-
WIP
362-
363-
Takes a function
364-
365-
run_chunk(buf, params) -> (buf, chunk_states)
366-
367-
and returns another
368405
369-
continue_chunk(buf, params, rng_key) -> (buf, chunk_states)
406+
Parameters
407+
==========
408+
run_chunk : function
409+
Function of the form `run_chunk(buf, params) -> (buf, chunk_states)`.
410+
chunk_len : int
411+
Length of the chunk.
412+
max_lag : int
413+
Maximum delay lag.
414+
n_from : int
415+
Number of state variables.
416+
n_svar : int
417+
Number of state variables.
418+
stochastic : bool
419+
If True, fills the buffer with random noise.
370420
371-
The continue_chunk function wraps run_chunk and manages
372-
moving the latest states to the first part of buf and filling
373-
the rest with samples from N(0,1) if required.
421+
Returns
422+
=======
423+
continue_chunk : function
424+
Function of the form `continue_chunk(buf, params, rng_key) -> (buf, chunk_states)`.
425+
The continue_chunk function wraps run_chunk and manages
426+
moving the latest states to the first part of buf and filling
427+
the rest with samples from N(0,1) if required.
374428
375429
"""
376430
from vbjax import randn

0 commit comments

Comments
 (0)