Docs / jax4j-core / com.nablatensor.jax4j.autodiff

final class

Var

A reverse-mode autodiff tape node wrapping a Tensor. Every fluent op (add/mul/matmul/...) both computes the forward Tensor value and records a local backward rule; backward() walks the recorded graph in reverse topological order, accumulating each node's gradient into its parents. AutoDiff brackets a recording session so the intermediate (non-leaf) nodes created along the way can be closed deterministically once gradients have been read out, instead of relying on GC/Cleaner timing.

Methods

static Var leaf(Tensor value)

Wraps a tensor as an untracked leaf: a trainable parameter or a constant. Never auto-closed.

Tensor value()
Tensor grad()

Accumulated upstream gradient after backward(); null if never reached.

Var add(Var other)
Var sub(Var other)
Var mul(Var other)
Var div(Var other)
Var matmul(Var other)
Var transpose()
Var reshape(int... dims)
Var relu()

Rectified linear unit; the backward pass routes gradient only where the input was positive.

Var conv2d(Var weights, ConvSpec spec)

2-D convolution against weights; see ConvSpec for the layout.

Var exp()
Var log()
Var sqrt()
Var tanh()
Var abs()
Var neg()
Var sigmoid()
Var scaled(double factor)

Scales by a plain (non-differentiable) double, e.g. a learning rate or 1/N.

Var sum()

Sums every element, returning a single-element (shape (1)) node.

Var sum(int axis)

Sums along one axis. The backward pass broadcasts the reduced gradient to the input shape.

Var sum(int axis, boolean keepDims)

Sums along one axis, optionally retaining a size-one reduced dimension.

Var max(int axis)
Var max(int axis, boolean keepDims)

Maximum along one axis. Ties route the gradient to the first maximum, matching argmax(int).

Var mean()

Mean over every element, returning a single-element (shape (1)) node.

void backward()

Seeds this (scalar-shaped) node's gradient with 1 and backprops through the whole tape.