auto_uncertainties.jittable_function_wrapper
Attributes
Functions
|
A decorator to propagate uncertainties through a given function using |
Module Contents
- auto_uncertainties.jittable_function_wrapper.propagate_uncertainties(func, implement_mode='same_shape')[source]
A decorator to propagate uncertainties through a given function using first-order Taylor expansion.
- Parameters:
func (callable) – The function through which to propagate uncertainties. This function should be compatible with JAX for automatic differentiation.
implement_mode (str)
- Returns:
A new function that propagates uncertainties when called with
Uncertaintyobjects.- Return type:
callable
Notes
This decorator uses JAX’s automatic differentiation to compute gradients, which are then used to propagate uncertainties. The function being decorated should be compatible with JAX, meaning it should use JAX-compatible operations.
Examples
>>> import numpy as np >>> import jax.numpy as jnp >>> from auto_uncertainties import Uncertainty, propagate_uncertainties >>> @propagate_uncertainties ... def my_function(x, y): ... return x * jnp.sin(y) >>> x = Uncertainty(2.0, 0.1) # Value 2.0 with uncertainty 0.1 >>> y = Uncertainty(np.pi / 4, 0.01) # Value pi/4 with uncertainty 0.01 >>> result = my_function(x, y)