Skip to main content

Your first derivative

Start with one identity, check the result, then take the derivative into a training loop. These instructions target the 0.5.0rc1 release candidate.

Install​

python -m pip install --pre "omnibias-torch==0.5.0rc1"

Use Python 3.11 or later for new environments. Keep these prereleases in a separate environment from older consumer applications; see installation.

Evaluate and check​

For tanh, the first derivative is 1 - tanh(x)**2. get_activation returns the backend's specification; fastpath evaluates a supported derivative order directly.

first_derivative.py
import torch
from omnibias.torch import get_activation

x = torch.linspace(-2, 2, 9, dtype=torch.float64)
spec = get_activation("tanh")
first = spec.fastpath(x, 1)
expected = 1 - torch.tanh(x).square()

torch.testing.assert_close(first, expected)
print(first.shape) # torch.Size([9])

Download the complete script.

The input and output both have shape (9,). The assertion compares the analytic path with the known identity at float64 precision.

The registry contains activations with different derivative-order limits. Check fastpath availability and the activation contract before assuming that every registered activation supports arbitrary order. Reusing a base activation avoids repeated evaluation, but polynomial arithmetic still grows with order.

Next: keep it trainable​

A fourth-order residual carries Taylor coefficients through a network, converts them back to derivatives, and computes parameter gradients. For a Laplacian, use the direct operator contraction.

Keras users can start with a complete operator-layer example. The JAX residual is included in the JAX quickstart.