Class ReverseTape

java.lang.Object
jdistlib.inference.autodiff.ReverseTape

public final class ReverseTape extends Object
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
    Constructor
    Description
     
    ReverseTape(int initialCapacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    add(int a, double b)
     
    int
    add(int a, int b)
     
    double
    adjoint(int handle)
     
    int
    atomic(double value, int[] parents, double[] partials)
    Creates an allocation-free many-input atomic node.
    int
    Current reusable arena capacity.
    int
    constant(double value)
     
    int
    cos(int a)
     
    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.
    int
    customUnary(int parent, double value, double partial)
    Creates a unary node from a caller-supplied value and exact local derivative.
    int
    divide(int a, double b)
     
    int
    divide(int a, int b)
     
    int
    exp(int a)
     
    int
    expm1(int a)
     
    int
    log(int a)
     
    int
    log1p(int a)
     
    int
    Returns a mark to which temporary nodes can later be rewound.
    int
    multiply(int a, double b)
     
    int
    multiply(int a, int b)
     
    int
    negate(int a)
     
    int
    pow(int a, double exponent)
     
    int
    pow(int a, int b)
     
    void
    Clears all nodes while retaining the arena capacity.
    void
    reverse(int output)
    Runs one reverse sweep with unit seed at output.
    void
    rewind(int mark)
    Discards nodes created after mark, retaining their storage.
    int
    sin(int a)
     
    int
    Current node count, useful for instrumentation and capacity planning.
    int
    sqrt(int a)
     
    int
    subtract(double a, int b)
     
    int
    subtract(int a, int b)
     
    int
    tanh(int a)
     
    double
    value(int handle)
     
    int
    variable(double value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 after mark, 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 at output.