ltc_dynamics (macula_tweann v0.13.0)

View Source

Liquid Time-Constant (LTC) neural dynamics.

This module implements Liquid Time-Constant neurons and their Closed-form Continuous-time (CfC) approximation for high-performance evaluation.

LTC neurons have input-dependent time constants, enabling adaptive temporal processing. This makes them particularly suitable for time-series data and real-time control tasks.

Theory

The LTC neuron is governed by the ODE:

dx(t)/dt = -[1/tau + f(x,I,theta)] * x(t) + f(x,I,theta) * A

Where: - x(t) is the neuron's internal state at time t - tau is the base time constant (learnable) - f(...) is a nonlinear function producing the "liquid" time constant - A is the state bound (prevents explosion) - I(t) is the input at time t

CfC Approximation

Instead of solving the ODE numerically, CfC uses a closed-form approximation:

x(t+dt) = sigma(-f) * x(t) + (1 - sigma(-f)) * h

Where: - sigma is the sigmoid function - f is the backbone network output (time-constant modulator) - h is the head network output (target state)

CfC is approximately 100x faster than ODE-based LTC while maintaining similar expressivity.

References

[1] Hasani, R., Lechner, M., et al. (2021). "Liquid Time-constant Networks." Proceedings of the AAAI Conference on Artificial Intelligence.

[2] Hasani, R., Lechner, M., et al. (2022). "Closed-form Continuous-time Neural Networks." Nature Machine Intelligence.

[3] Beer, R.D. (1995). "On the Dynamics of Small Continuous-Time Recurrent Neural Networks." Adaptive Behavior, 3(4).

Summary

Types

State bound A

Time step

Base time constant

Functions

Clamp state to bounds [-Bound, Bound].

Compute backbone network output (time-constant modulator).

Compute head network output (target state).

Compute the liquid (input-dependent) time constant.

Evaluate CfC neuron with closed-form approximation.

Evaluate CfC neuron with custom backbone/head weights.

Evaluate LTC neuron using ODE integration (Euler method).

Evaluate LTC with ODE and custom parameters.

Reset state to zero.

Sigmoid function.

Hyperbolic tangent function.

Types

backbone_weights/0

-type backbone_weights() :: [float()].

bound/0

-type bound() :: float().

State bound A

dt/0

-type dt() :: float().

Time step

head_weights/0

-type head_weights() :: [float()].

input/0

-type input() :: float() | [float()].

state/0

-type state() :: float().

tau/0

-type tau() :: float().

Base time constant

Functions

clamp_state(State, Bound)

-spec clamp_state(state(), bound()) -> state().

Clamp state to bounds [-Bound, Bound].

Bounded dynamics are a key property of LTC that ensures stability.

compute_backbone(Input, Tau, Weights)

-spec compute_backbone(input(), tau(), backbone_weights()) -> float().

Compute backbone network output (time-constant modulator).

The backbone determines how the time constant varies with input. This is the "f" in the CfC equation.

compute_head(Input, Weights)

-spec compute_head(input(), head_weights()) -> float().

Compute head network output (target state).

The head determines the asymptotic state the neuron moves toward. This is the "h" in the CfC equation.

compute_liquid_tau(Input, State, BaseTau, Params)

-spec compute_liquid_tau(input(), state(), tau(), map()) -> float().

Compute the liquid (input-dependent) time constant.

The "liquid" aspect of LTC comes from the time constant varying based on input and state, allowing adaptive temporal dynamics.

evaluate_cfc(Input, State, Tau, Bound)

-spec evaluate_cfc(input(), state(), tau(), bound()) -> {state(), float()}.

Evaluate CfC neuron with closed-form approximation.

This is the fast path for LTC evaluation, avoiding ODE solving. Uses default backbone/head functions based on input only.

evaluate_cfc(Input, State, Tau, Bound, Params)

-spec evaluate_cfc(input(), state(), tau(), bound(), map()) -> {state(), float()}.

Evaluate CfC neuron with custom backbone/head weights.

For networks with evolved backbone/head parameters.

evaluate_ode(Input, State, Tau, Bound, Dt)

-spec evaluate_ode(input(), state(), tau(), bound(), dt()) -> {state(), float()}.

Evaluate LTC neuron using ODE integration (Euler method).

More accurate than CfC but slower. Use for training or when temporal precision is critical.

evaluate_ode(Input, State, Tau, Bound, Dt, Params)

-spec evaluate_ode(input(), state(), tau(), bound(), dt(), map()) -> {state(), float()}.

Evaluate LTC with ODE and custom parameters.

reset_state()

-spec reset_state() -> state().

Reset state to zero.

sigmoid(X)

-spec sigmoid(float()) -> float().

Sigmoid function.

sigma(x) = 1 / (1 + e^-x)

tanh(X)

-spec tanh(float()) -> float().

Hyperbolic tangent function.