Utilities¶
Numerical solvers, linear-algebra helpers and shared type aliases.
Solvers¶
See ODE and SDE integration for adaptive controllers, gradients and inverse log-determinants.
probjax.utils.odeint
¶
odeint
¶
odeint(drift, y0, ts, *args, solver='rk4', method=None, dtype=float32, filter_state=None, collect_trace=True, check_points=None, step_size_adaptor=None, logdet_rng=None, trace_estimator='exact', num_samples=1, sample_dist='rademacher')
Solve an ordinary differential equation dy/dt = drift(t, y, *args).
drift may be any of:
- a plain Python callable
drift(t, y, *args)— it is automatically wrapped in :class:probjax.utils.functions.generic_driftso it rides as a pytree throughjax.jitand thecustom_inverseprimitive; - a registered JAX pytree node (
eqx.Module,flax.struct.PyTreeNode, :class:~probjax.utils.functions.Driftsubclass, ...) — its array leaves participate in transformations natively, non-array fields ride as aux.
Drift keyword arguments are no longer supported. Pass parameters
positionally via *args, or bind them up-front with functools.partial
(or drift.bind_args(...) on a :class:~probjax.utils.functions.Drift).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift
|
Callable[..., PyTree[Array]]
|
The drift function |
required |
y0
|
PyTree[Array]
|
Initial state. Single array or pytree of arrays. |
required |
ts
|
Array
|
Time points at which to evaluate the solution. |
required |
*args
|
Any
|
Positional arguments forwarded to |
()
|
solver
|
Union[str, type, ConfiguredSolver]
|
Integration method: a registered name ( |
'rk4'
|
method
|
Optional[str]
|
Deprecated alias of |
None
|
dtype
|
Optional[dtype]
|
Computation dtype (default |
float32
|
filter_state
|
Optional[Callable[[PyTree[Array]], Optional[PyTree[Array]]]]
|
Optional function to filter the state during integration. |
None
|
collect_trace
|
bool
|
If |
True
|
check_points
|
Optional[Sequence[int]]
|
Optional index sequence for checkpointed grid integration. |
None
|
step_size_adaptor
|
Optional[StepSizeAdaptor]
|
Step-size controller for adaptive solver
methods ( |
None
|
logdet_rng
|
Optional[Array]
|
RNG key for stochastic log-determinant estimators.
Required when |
None
|
trace_estimator
|
TraceEstimator
|
Log-det trace estimator used when the function is
inverted via
|
'exact'
|
num_samples
|
int
|
Hutchinson probe-vector count per trajectory. Higher values reduce variance linearly in cost. |
1
|
sample_dist
|
SampleDist
|
Hutchinson probe distribution — |
'rademacher'
|
Returns:
| Type | Description |
|---|---|
Optional[PyTree[Array]]
|
Pytree containing either the time-series trace (when |
Optional[PyTree[Array]]
|
|
Example
import jax.numpy as jnp from probjax.utils.odeint import odeint
def lotka_volterra(t, y, alpha, beta, delta, gamma): ... prey, predator = y ... dprey = alpha * prey - beta * prey * predator ... dpredator = delta * prey * predator - gamma * predator ... return jnp.array([dprey, dpredator])
y0 = jnp.array([40.0, 9.0]) ts = jnp.linspace(0, 10, 100) ys = odeint(lotka_volterra, y0, ts, 1.0, 0.1, 0.075, 0.5, solver="dopri5")
Source code in probjax/utils/odeint.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
probjax.utils.sdeint
¶
sdeint
¶
sdeint(rng, drift, diffusion, y0, ts, *args, solver='euler_maruyama', method=None, dtype=float32, sde_type='ito', return_brownian=False, return_state=False, filter_state=None, collect_trace=True, check_points=None, step_size_adaptor=None)
Solve a stochastic differential equation
dy = drift(t, y, *args) dt + diffusion(t, y, *args) dW.
drift and diffusion may be plain Python callables (automatically
wrapped as :class:~probjax.utils.functions.generic_drift) or any
pytree-registered callable (marker
:class:~probjax.utils.functions.Drift subclass, eqx.Module, etc.).
Keyword arguments to drift/diffusion are no longer supported. Pass
parameters positionally via *args, or bind them with
functools.partial / drift.bind_args(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng
|
Key
|
Random number generator key. |
required |
drift
|
Callable[..., PyTree[Array]]
|
Drift function |
required |
diffusion
|
Callable[..., PyTree[Array]]
|
Diffusion function |
required |
y0
|
PyTree[Array]
|
Initial state. Single array or pytree of arrays. |
required |
ts
|
Array
|
Strictly increasing 1D array of time points. |
required |
*args
|
Any
|
Positional arguments forwarded to both drift and diffusion. |
()
|
solver
|
Union[str, type, ConfiguredSolver]
|
Integration method: a registered name, a solver class or a
configured solver (
|
'euler_maruyama'
|
method
|
Optional[str]
|
Deprecated alias of |
None
|
dtype
|
Optional[dtype]
|
Computation dtype (default |
float32
|
sde_type
|
str
|
|
'ito'
|
return_brownian
|
bool
|
Whether to return Brownian paths (requires
|
False
|
return_state
|
bool
|
Whether to return solver state. |
False
|
filter_state
|
Optional[Callable[[PyTree[Array]], Optional[PyTree[Array]]]]
|
Optional state filter; returning |
None
|
collect_trace
|
bool
|
Record the filtered quantity at every time step
( |
True
|
check_points
|
Optional[Sequence[int]]
|
Optional index sequence for checkpointed grid integration. |
None
|
step_size_adaptor
|
Optional[SDEStepSizeAdaptor]
|
When provided, switches integration to an
adaptive step-doubling Euler-Maruyama scheme driven by the
given controller. Pass
:class: |
None
|
Returns:
| Type | Description |
|---|---|
Union[Optional[PyTree[Array]], Tuple[Any, Optional[PyTree[Array]]], Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]], Tuple[Any, Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]]]]
|
When |
Union[Optional[PyTree[Array]], Tuple[Any, Optional[PyTree[Array]]], Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]], Tuple[Any, Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]]]]
|
|
Union[Optional[PyTree[Array]], Tuple[Any, Optional[PyTree[Array]]], Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]], Tuple[Any, Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]]]]
|
|
Union[Optional[PyTree[Array]], Tuple[Any, Optional[PyTree[Array]]], Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]], Tuple[Any, Tuple[Optional[PyTree[Array]], Optional[PyTree[Array]]]]]
|
|
Example
import jax.numpy as jnp from probjax.utils.sdeint import sdeint from jax import random
def drift(t, state, mu, sigma): ... return {"price": mu * state["price"]} def diffusion(t, state, mu, sigma): ... return {"price": sigma * state["price"]}
rng = random.PRNGKey(0) y0 = {"price": jnp.array([1.0])} ts = jnp.linspace(0, 1, 100) ys = sdeint(rng, drift, diffusion, y0, ts, 0.1, 0.2)
Source code in probjax/utils/sdeint.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
probjax.utils.root
¶
Find a root of fun(x, *args).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Callable
|
Function to find root of. |
required |
x0
|
Array
|
Initial value. |
required |
args
|
tuple
|
Extra arguments to pass to function. Defaults to (). |
()
|
method
|
str
|
Method to use. Only |
'newton-raphson'
|
tol
|
float
|
Tolerance, floored at machine epsilon. Defaults to 1e-3. |
0.001
|
max_iter
|
int
|
Maximum number of iterations. Defaults to 20. |
20
|
**newton_kwargs
|
|
{}
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in probjax/utils/solver.py
probjax.utils.newton_raphson
¶
Newton-Raphson root finding for f(x) = 0 with f(x).shape == x.shape.
Gradients of the returned root use the implicit function theorem
(jax.lax.custom_root) instead of differentiating through the
iterations, so they cost one extra linear solve. The gradient is only
valid when the solve converged: always check the returned flag before
differentiating (callers that keep stepping, like the implicit ODE
solvers, record it in their info).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Function whose root is sought. |
required | |
x0
|
Initial guess. |
required | |
tol
|
Stop once a Newton step is shorter than this (in 2-norm), floored at machine epsilon. |
1e-06
|
|
max_iter
|
Maximum number of Newton steps (at least 1). |
50
|
|
jacobian
|
str
|
|
'dense'
|
linear_solver
|
Any
|
Solver for each Newton step, passed to
:func: |
'auto'
|
Returns:
| Type | Description |
|---|---|
|
|
|
|
than |
Source code in probjax/utils/solver.py
Special functions¶
probjax.utils.betaincinv
¶
Regularized beta inverses with cached solvers and implicit reverse AD.
betaincinv
¶
Invert regularized lower beta for finite positive shapes.
Probabilities are clipped to [0, 1]; invalid shapes return NaN. The total safeguarded Halley/bisection budget is 2 plus both step settings. Reverse AD uses the inverse density and central differences for shapes; forward AD and higher shape derivatives are not supported.
Source code in probjax/utils/special/betaincinv.py
betainccinv
¶
Invert regularized upper beta directly, preserving tiny q.
q=0 returns one; q=1 returns zero. Domain, step settings and differentiation have the same semantics as betaincinv.
Source code in probjax/utils/special/betaincinv.py
probjax.utils.betainccinv
¶
Invert regularized upper beta directly, preserving tiny q.
q=0 returns one; q=1 returns zero. Domain, step settings and differentiation have the same semantics as betaincinv.
Source code in probjax/utils/special/betaincinv.py
probjax.utils.gammaincinv
¶
Regularized gamma inverses with implicit differentiation.
gammaincinv
¶
gammainccinv
¶
Invert regularized upper gamma directly, preserving tiny q.
Finite a > 0 is required. Probabilities are clipped to [0, 1]; q=0 returns infinity and q=1 returns zero. Invalid shapes return NaN. Supports implicit forward and reverse differentiation.
Source code in probjax/utils/special/gammaincinv.py
probjax.utils.gammainccinv
¶
Invert regularized upper gamma directly, preserving tiny q.
Finite a > 0 is required. Probabilities are clipped to [0, 1]; q=0 returns infinity and q=1 returns zero. Invalid shapes return NaN. Supports implicit forward and reverse differentiation.
Source code in probjax/utils/special/gammaincinv.py
probjax.utils.log1mexp
¶
Compute log(1-exp(x)) for x <= 0; positive inputs return NaN.
Zero returns -inf and -inf returns zero. Inactive branch arguments are guarded to keep interior gradients finite near zero.
Source code in probjax/utils/special/logspace.py
probjax.utils.logdiffexp
¶
Compute log(exp(a)-exp(b)), broadcasting a >= b.
Equal finite inputs and (-inf, -inf) return -inf. Invalid domains, including (+inf, +inf), return NaN. Gradients require finite a > b.
Source code in probjax/utils/special/logspace.py
probjax.utils.digammainv
¶
digammainv
¶
Inverse of the digamma function using Newton's method with asymptotic approximations.
Implementation follows the approach described in the literature: For Ψ(x) = y, use Newton's method with the update: x_new = x_old - (Ψ(x) - y) / Ψ'(x)
NOTE: Digamm is only invertible for x > 0. and this function assumes that y is in the domain of invertibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Union[float, ndarray]
|
The value to find the inverse digamma for |
required |
maxiter
|
int
|
Maximum number of Newton iterations (5 iterations typically sufficient for 14 digits) |
5
|
tol
|
float
|
Tolerance for convergence |
1e-14
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
x such that digamma(x) = y |
Source code in probjax/utils/special/digammainv.py
Interpolation and linear algebra¶
probjax.utils.linear_interpolation
¶
Linear interpolation function for a given set of points (ts, ys). Here ts must be a one dimensional sorted array and ys can be any array with the same length as ts on axis 0. Outside of the data range, the function returns the value of the nearest data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Array
|
Time points |
required |
ys
|
Array
|
Values at time points |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Float], Array]
|
Callable[[Float], Array]: Interpolation function that can be evaluated at any |
Callable[[Float], Array]
|
time point. |
Source code in probjax/utils/interpolation.py
probjax.utils.polynomial_interpolation
¶
Polynomial interpolation function for a given set of points (ts, ys). Here ts must be a one dimensional sorted array and ys can be any array with the same length as ts on axis 0.
The interpolation is done using a polynomial of degree 'degree'. The window parameter can be used to limit the range of data points used for interpolation. If window is None, the interpolation is done using all the data points.
Outside of the data range, the function does return the value of the
interpolant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Array
|
description |
required |
ys
|
Array
|
description |
required |
degree
|
Int
|
description. Defaults to 3. |
3
|
window
|
Optional[Int]
|
description. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
Callable[[Float], Array]
|
description |
Source code in probjax/utils/interpolation.py
probjax.utils.cholesky_update
¶
Update the Cholesky decomposition of a matrix after a rank-1 update i.e.
C = L @ L.T + multiplier * u @ u.T
Args: L: A [D, D] lower triangular matrix, the Cholesky factor of the original matrix. u: A [D,] vector, the update vector.
Returns: The updated [D, D] lower triangular matrix.
Source code in probjax/utils/linalg.py
probjax.utils.mv_diag_or_dense
¶
Dot product of a diagonal matrix and a dense matrix
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Array
|
Diagonal matrix |
required |
B
|
Array
|
Dense matrix |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Dot product |
Source code in probjax/utils/linalg.py
Linear operators¶
probjax.utils.linear_operator.Diagonal
dataclass
¶
Bases: LinearOperator
Elementwise x -> diag * x; a 0-d diag is diag * I.
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.Dense
dataclass
¶
Bases: LinearOperator
A materialized (out_size, in_size) matrix acting on shaped arrays.
Source code in probjax/utils/linear_operator.py
jacfwd
classmethod
¶
Materialized Jacobian of fn at x.
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.Function
dataclass
¶
Bases: LinearOperator
Matrix-free operator given by a linear matvec on in_shape arrays.
out_shape/dtype are inferred with jax.eval_shape (no FLOPs)
when omitted. matvec is static pytree data, so build Function
operators inside the traced function that uses them rather than passing
them across jit/scan boundaries.
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.Jacobian
dataclass
¶
Bases: LinearOperator
Matrix-free Jacobian of fn(x, *args) with respect to x.
Each application costs one JVP. x and args are pytree leaves and
fn is static, so rebuilding the Jacobian at a new point inside a
jitted function does not retrace.
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.solve
¶
Solve op @ x = b for x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
LinearOperator
|
Square operator ( |
required |
b
|
ArrayLike
|
Right-hand side of |
required |
solver
|
Any
|
|
'auto'
|
psd
|
bool
|
Whether |
False
|
tol
|
float
|
Relative tolerance of the iterative solvers. |
1e-05
|
maxiter
|
int | None
|
Iteration cap of the iterative solvers. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Solution of |
Source code in probjax/utils/linear_operator.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
probjax.utils.linear_operator.logdet
¶
log |det op| of a square operator.
Function operators need psd=True and use Lanczos quadrature
(:func:probjax.utils.linalg.lanczos_logdet, which receives
lanczos_kwargs); call as_dense() first for an exact result.
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.as_operator
¶
Interpret A as a square operator on arrays of shape.
Operators pass through (their domain must equal shape); a 0-d array
or 1-d array broadcastable to shape is a diagonal, and a square 2-d
array a dense matrix on vector states of matching dimension. Anything
else raises a clear error: the exact solvers need a flattened square
system, so dense drifts support vector states only (evaluate the drift
itself for matmul-broadcast behavior on shaped states).
Source code in probjax/utils/linear_operator.py
probjax.utils.linear_operator.phi_matrices
¶
[phi_0(Z), ..., phi_k(Z)] from one block matrix exponential.
expm of the (k+1)-block-bidiagonal augmentation (Z in the first
block, identities on the first superdiagonal) has phi_j(Z) in its
j-th top-row block.
Source code in probjax/utils/linear_operator.py
ODE integration internals¶
probjax.utils.odeutil.ODESolver
¶
Bases: NamedTuple
This is a NamedTuple that represents a ODE kernel. given by the drift.
Source code in probjax/utils/odeutil/solvers/base.py
probjax.utils.odeutil.get_method
¶
(solver_factory, info) for a name, solver class or configured solver.
probjax.utils.odeutil.get_methods
¶
probjax.utils.odeutil.StepSizeAdaptor
¶
Standardized step-size controller for adaptive ODE solvers.
Constructor arguments are the classic adaptive-RK tuning knobs:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rtol
|
float
|
Relative tolerance (per-component). |
0.0001
|
atol
|
float
|
Absolute tolerance (per-component). |
1e-05
|
mxstep
|
int
|
Hard cap on inner adaptive iterations between two output
grid points. Defaults to |
inf
|
dtmin
|
float
|
Minimum admissible step size; the controller clips below this and accepts the step regardless of error. |
0.0
|
dtmax
|
float
|
Maximum admissible step size. |
inf
|
maxerror
|
float
|
Accept-step threshold on the normalized error ratio. |
1.2
|
safety, ifactor, dfactor
|
Hairer–Wanner safety factor and grow/shrink limits applied around the optimal step. |
required | |
error_norm
|
float
|
Order of the error norm ( |
2
|
order
|
int
|
Local-error order. Set automatically by the integrator to match the chosen method, so there is rarely a reason to set this at construction time. |
5
|
Subclass to customize the strategy:
>>> class HairerOnly(StepSizeAdaptor):
... def accept_step(self, error_ratio, dt):
... return error_ratio <= self.maxerror
Note
This object is only consulted by adaptive solver methods
("dopri5", "dopri8", "bosh3", etc.). Fixed-step methods
("euler", "rk4", "midpoint", ...) ignore it entirely.
Source code in probjax/utils/odeutil/adaptive.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
with_order
¶
Return a shallow copy with the local-error order set.
The adaptive integrator calls this once after resolving the method's
local order, so subclasses do not need to track order themselves.
Source code in probjax/utils/odeutil/adaptive.py
initial_step_size
¶
Pick the initial step dt0 from drift / state magnitudes.
Source code in probjax/utils/odeutil/adaptive.py
error_ratio
¶
Compute ||error / (atol + rtol·max(|y|,|y_next|))||_p.
next_step_size
¶
Hairer–Wanner optimal step, clipped to [dtmin, dtmax].
Source code in probjax/utils/odeutil/adaptive.py
accept_step
¶
Accept iff the error is below maxerror or dt hit a clip.
probjax.utils.odeutil.euler
¶
probjax.utils.odeutil.implicit_euler
¶
probjax.utils.odeutil.TraceFilter
¶
Bases: Protocol
Protocol for specifying which parts of the state to trace.
A filter receives a PyTree with the same structure as the solver state and
should return either a PyTree selecting the components that should be
recorded over time or None to disable tracing entirely.
Source code in probjax/utils/odeutil/filters.py
probjax.utils.odeutil.TraceEverything
¶
probjax.utils.odeutil.TraceNothing
¶
SDE integration internals¶
probjax.utils.sdeutil.SDEStepSizeAdaptor
¶
Bases: StepSizeAdaptor
Base class for SDE step-size controllers.
Extends the ODE :class:StepSizeAdaptor with a noise-sampling protocol:
- :meth:
init_brownianconstructs the per-trajectory sampling state. - :meth:
propose_incrementsproduces the increment for a proposeddtplus the bridge-consistent halves used by step doubling. - :meth:
on_rejectupdates the sampling state when a step is rejected before the next attempt.
Subclasses set :attr:is_path_consistent so downstream code can decide
whether per-path quantities are meaningful.
Source code in probjax/utils/sdeutil/adaptive.py
bind_interval
¶
accept_step
¶
Always accept: the error only steers the next step (see module docs).
propose_increments
¶
Return (committed_state, dW_full, dW_first_half, dW_second_half).
The two halves satisfy dW_first_half + dW_second_half == dW_full
within the proposed step (Brownian-bridge consistent), enabling an
unbiased step-doubling local error estimate.
committed_state is the new sampling state to keep on accept; the
integrator passes it through :meth:on_reject instead on rejection.
Source code in probjax/utils/sdeutil/adaptive.py
probjax.utils.sdeutil.StrongStepSizeAdaptor
¶
Bases: SDEStepSizeAdaptor
Path-consistent sampling via a virtual Brownian tree.
All increments come from a single keyed path, so the integrator's output
is a sample from one consistent W. Use this whenever per-path quantities matter (state
estimation, log-likelihood under a given path, gradient methods that
assume realized-path consistency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree_depth
|
int
|
Static refinement depth for the underlying virtual
Brownian tree. Per-query cost is |
20
|
tree_tol
|
Optional[float]
|
Backward-compatibility alias; converted to
|
None
|
Source code in probjax/utils/sdeutil/adaptive.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
probjax.utils.sdeutil.WeakStepSizeAdaptor
¶
Bases: SDEStepSizeAdaptor
Fresh PRNG increments — valid for distributional quantities only.
The trajectory is not a sample from a single Brownian path. Suitable for
diffusion-model sampling or any setting where you only care about moments /
densities of the terminal state. Use :class:StrongStepSizeAdaptor for
per-path quantities.
Source code in probjax/utils/sdeutil/adaptive.py
probjax.utils.sdeutil.SDESolver
¶
Bases: NamedTuple
This is a NamedTuple that represents a ODE kernel. given by the drift.
Source code in probjax/utils/sdeutil/base.py
probjax.utils.sdeutil.get_method
¶
probjax.utils.sdeutil.get_methods
¶
probjax.utils.sdeutil.euler_maruyama
¶
probjax.utils.sdeutil.exp_euler_maruyama
¶
probjax.utils.sdeutil.milstein
¶
probjax.utils.sdeutil.sri1
¶
Bases: SDESolverAPI
SRI1 method - Strong order 1.0 stochastic Runge-Kutta method.
Source code in probjax/utils/sdeutil/solver/srk_explicit.py
probjax.utils.sdeutil.sri2
¶
Bases: SDESolverAPI
SRI2 method - Strong order 1.0 stochastic Runge-Kutta method.
Source code in probjax/utils/sdeutil/solver/srk_explicit.py
probjax.utils.sdeutil.linear_exact_sde
¶
Special functions (subpackage)¶
probjax.utils.special.betaincinv
¶
Regularized beta inverses with cached solvers and implicit reverse AD.
betaincinv
¶
Invert regularized lower beta for finite positive shapes.
Probabilities are clipped to [0, 1]; invalid shapes return NaN. The total safeguarded Halley/bisection budget is 2 plus both step settings. Reverse AD uses the inverse density and central differences for shapes; forward AD and higher shape derivatives are not supported.
Source code in probjax/utils/special/betaincinv.py
betainccinv
¶
Invert regularized upper beta directly, preserving tiny q.
q=0 returns one; q=1 returns zero. Domain, step settings and differentiation have the same semantics as betaincinv.
Source code in probjax/utils/special/betaincinv.py
probjax.utils.special.betainccinv
¶
Invert regularized upper beta directly, preserving tiny q.
q=0 returns one; q=1 returns zero. Domain, step settings and differentiation have the same semantics as betaincinv.
Source code in probjax/utils/special/betaincinv.py
probjax.utils.special.gammaincinv
¶
Regularized gamma inverses with implicit differentiation.
gammaincinv
¶
gammainccinv
¶
Invert regularized upper gamma directly, preserving tiny q.
Finite a > 0 is required. Probabilities are clipped to [0, 1]; q=0 returns infinity and q=1 returns zero. Invalid shapes return NaN. Supports implicit forward and reverse differentiation.
Source code in probjax/utils/special/gammaincinv.py
probjax.utils.special.gammainccinv
¶
Invert regularized upper gamma directly, preserving tiny q.
Finite a > 0 is required. Probabilities are clipped to [0, 1]; q=0 returns infinity and q=1 returns zero. Invalid shapes return NaN. Supports implicit forward and reverse differentiation.
Source code in probjax/utils/special/gammaincinv.py
probjax.utils.special.digammainv
¶
digammainv
¶
Inverse of the digamma function using Newton's method with asymptotic approximations.
Implementation follows the approach described in the literature: For Ψ(x) = y, use Newton's method with the update: x_new = x_old - (Ψ(x) - y) / Ψ'(x)
NOTE: Digamm is only invertible for x > 0. and this function assumes that y is in the domain of invertibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Union[float, ndarray]
|
The value to find the inverse digamma for |
required |
maxiter
|
int
|
Maximum number of Newton iterations (5 iterations typically sufficient for 14 digits) |
5
|
tol
|
float
|
Tolerance for convergence |
1e-14
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
x such that digamma(x) = y |
Source code in probjax/utils/special/digammainv.py
probjax.utils.special.log1mexp
¶
Compute log(1-exp(x)) for x <= 0; positive inputs return NaN.
Zero returns -inf and -inf returns zero. Inactive branch arguments are guarded to keep interior gradients finite near zero.
Source code in probjax/utils/special/logspace.py
probjax.utils.special.logdiffexp
¶
Compute log(exp(a)-exp(b)), broadcasting a >= b.
Equal finite inputs and (-inf, -inf) return -inf. Invalid domains, including (+inf, +inf), return NaN. Gradients require finite a > b.