Skip to content

Derivative sources

Almost every candidate term contains a derivative, but your data only carries field values. KD produces the derivatives itself, along one of two routes: finite differences on the grid, or automatic differentiation through a neural network that represents the field.

Finite differences

Central-difference stencils applied directly on the grid. Every derivative is computed once before the search starts, and every later use is a lookup.

  • First- and second-order derivatives use fourth-order accurate stencils; third-order uses a second-order accurate one. Atomic derivatives are supported up to third order.
  • Periodic axes use a wrap-around stencil, so boundary points keep the interior accuracy; non-periodic axes fall back to reduced-order formulas at the boundary.
  • Coordinates must be increasing and evenly spaced.

Automatic differentiation

A neural network is trained to map coordinates to field values, and PyTorch autograd differentiates that network. The derivatives are exact for the trained network, so they are not bounded by a stencil's order and they need not be evaluated at the original grid points. The price is one extra training run.

Surrogate network sources

Three things can supply the network that gets differentiated:

  • Trained by the platform: an algorithm declares that it needs a surrogate network, and the platform trains one and wires it in with nothing required from you. This is DLGA-PDE's route.
  • Trained by the algorithm: under derivatives="autograd", SGA-PDE trains its own surrogate network and uses it for the terminal derivatives (u_x, u_t), while derivative operators inside the expression tree still go through the dataset's finite differences.
  • Supplied by you: kd.Model(algorithm="dlga", surrogate_model=...) takes an already-trained torch.nn.Module and the platform skips its own training. The parameter applies to DLGA-PDE only.

Derivative source per algorithm

Every mode of every algorithm declares its derivative source in kd.instrument_schemas():

import kd

for schema in kd.instrument_schemas():
    for mode in schema["modes"]:
        print(f"{schema['algorithm']:9s} {mode['name']:15s} {mode['provider_kind']}")
sga       default         finite_diff
sga       autograd        autograd
dlga      default         autograd
discover  mode1           finite_diff
pysr      default         finite_diff
eqgpt     single_wave     finite_diff
eqgpt     wave_multicase  none
eqgpt     steady          none
llm4ed    default         finite_diff
pysindy   default         finite_diff

DLGA-PDE always differentiates through a network; DISCOVER, PySR, PySINDy, LLM4ED and EqGPT's single-case wave mode use finite differences; SGA-PDE offers both and defaults to finite differences. EqGPT's multi-case wave mode and steady mode report none: they take no derivatives from the platform and build their own field representation and evaluation internally.

Configurable options

  • How SGA-PDE differentiates: kd.Model(algorithm="sga", derivatives="autograd") switches the terminal derivatives to autograd. On a regular, well-resolved grid the default finite differences are computed once and cost you no training run; choose autograd when you want the derivatives to come from a continuous representation of the field.
  • DLGA-PDE's surrogate network: by default the platform trains it from the surrogate settings in kd.DLGAConfig. If you already have a trained field network, pass it through surrogate_model= and that training is skipped.

Every other algorithm has a fixed derivative source, with nothing to choose. For what the data itself must look like, see data requirements.