Package jdistlib.inference.autodiff
Class ReverseTape
java.lang.Object
jdistlib.inference.autodiff.ReverseTape
Allocation-conscious reverse-mode automatic-differentiation tape.
Nodes are represented by integer handles and stored in reusable primitive
arrays. A caller normally invokes reset() before every log-density
evaluation, creates the independent variables, builds a scalar result, and
calls reverse(int). Resetting retains the allocated arena.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintadd(int a, double b) intadd(int a, int b) doubleadjoint(int handle) intatomic(double value, int[] parents, double[] partials) Creates an allocation-free many-input atomic node.intcapacity()Current reusable arena capacity.intconstant(double value) intcos(int a) intcustomBinary(int left, int right, double value, double leftPartial, double rightPartial) Creates a binary node from a caller-supplied value and exact local derivatives.intcustomUnary(int parent, double value, double partial) Creates a unary node from a caller-supplied value and exact local derivative.intdivide(int a, double b) intdivide(int a, int b) intexp(int a) intexpm1(int a) intlog(int a) intlog1p(int a) intmark()Returns a mark to which temporary nodes can later be rewound.intmultiply(int a, double b) intmultiply(int a, int b) intnegate(int a) intpow(int a, double exponent) intpow(int a, int b) voidreset()Clears all nodes while retaining the arena capacity.voidreverse(int output) Runs one reverse sweep with unit seed atoutput.voidrewind(int mark) Discards nodes created aftermark, retaining their storage.intsin(int a) intsize()Current node count, useful for instrumentation and capacity planning.intsqrt(int a) intsubtract(double a, int b) intsubtract(int a, int b) inttanh(int a) doublevalue(int handle) intvariable(double value)
-
Constructor Details
-
ReverseTape
public ReverseTape() -
ReverseTape
public ReverseTape(int initialCapacity)
-
-
Method Details
-
reset
public void reset()Clears all nodes while retaining the arena capacity. -
size
public int size()Current node count, useful for instrumentation and capacity planning. -
capacity
public int capacity()Current reusable arena capacity. -
mark
public int mark()Returns a mark to which temporary nodes can later be rewound. -
rewind
public void rewind(int mark) Discards nodes created aftermark, retaining their storage. -
variable
public int variable(double value) -
constant
public int constant(double value) -
value
public double value(int handle) -
adjoint
public double adjoint(int handle) -
add
public int add(int a, int b) -
add
public int add(int a, double b) -
subtract
public int subtract(int a, int b) -
subtract
public int subtract(double a, int b) -
multiply
public int multiply(int a, int b) -
multiply
public int multiply(int a, double b) -
divide
public int divide(int a, int b) -
divide
public int divide(int a, double b) -
negate
public int negate(int a) -
exp
public int exp(int a) -
expm1
public int expm1(int a) -
log
public int log(int a) -
log1p
public int log1p(int a) -
sqrt
public int sqrt(int a) -
sin
public int sin(int a) -
cos
public int cos(int a) -
tanh
public int tanh(int a) -
pow
public int pow(int a, double exponent) -
pow
public int pow(int a, int b) -
customUnary
public int customUnary(int parent, double value, double partial) Creates a unary node from a caller-supplied value and exact local derivative. -
customBinary
public int customBinary(int left, int right, double value, double leftPartial, double rightPartial) Creates a binary node from a caller-supplied value and exact local derivatives. -
atomic
public int atomic(double value, int[] parents, double[] partials) Creates an allocation-free many-input atomic node.The parent and partial arrays are copied into the reusable edge arena, allowing probability and linear-algebra kernels to contribute one tape node rather than exposing all of their scalar implementation steps.
-
reverse
public void reverse(int output) Runs one reverse sweep with unit seed atoutput.
-