Compute the bias-corrected exponential moving average of a sequence, and return both the final running state and the corrected average at every step.
The rows of values are x1,…,xT, each of shape (D,), and β is decay. Starting from m0=0, for every step t from 1 to T,
mt=βmt−1+(1−β)xt,m^t=1−βtmt.Here mt is the raw running average and m^t is its bias-corrected value.
Your function is compiled with jax.jit, with decay passed as a traced float32 scalar.
Return a dict with the key final_state, a float32 JAX array of shape (D,) holding the raw mT, and the key corrected, a float32 JAX array of shape (T, D) whose row t−1 is m^t.
Input: values = [[1.0],[2.0],[3.0]], decay = 0.5
Output: {"final_state":[2.125],"corrected":[[1.0],[1.666667],[2.428571]]}
Explanation: The raw averages are 0.5, 1.25 and 2.125, and the weight sums 1 - 0.5^t are 0.5, 0.75 and 0.875, so the corrected averages are 1, 1.666667 and 2.428571. final_state is the raw value 2.125.
Input: values = [[2.0,-1.0],[2.0,-1.0],[2.0,-1.0],[2.0,-1.0]], decay = 0.9
Output: {"final_state":[0.6878,-0.3439],"corrected":[[2.0,-1.0],[2.0,-1.0],[2.0,-1.0],[2.0,-1.0]]}
Input: values = [[1.0,0.0,-1.0],[3.0,1.0,0.0]], decay = 0.0
Output: {"final_state":[3.0,1.0,0.0],"corrected":[[1.0,0.0,-1.0],[3.0,1.0,0.0]]}
final, outs = jax.lax.scan(step, init, xs) with step(carry, x) -> (new_carry, out).
The carry can be a tuple, such as (avg, power).
jnp.zeros_like(xs[0]) gives a starting state with the right shape and dtype.
Accepts: array
Accepts: number
Compute the bias-corrected exponential moving average of a sequence, and return both the final running state and the corrected average at every step.
The rows of values are x1,…,xT, each of shape (D,), and β is decay. Starting from m0=0, for every step t from 1 to T,
mt=βmt−1+(1−β)xt,m^t=1−βtmt.Here mt is the raw running average and m^t is its bias-corrected value.
Your function is compiled with jax.jit, with decay passed as a traced float32 scalar.
Return a dict with the key final_state, a float32 JAX array of shape (D,) holding the raw mT, and the key corrected, a float32 JAX array of shape (T, D) whose row t−1 is m^t.
Input: values = [[1.0],[2.0],[3.0]], decay = 0.5
Output: {"final_state":[2.125],"corrected":[[1.0],[1.666667],[2.428571]]}
Explanation: The raw averages are 0.5, 1.25 and 2.125, and the weight sums 1 - 0.5^t are 0.5, 0.75 and 0.875, so the corrected averages are 1, 1.666667 and 2.428571. final_state is the raw value 2.125.
Input: values = [[2.0,-1.0],[2.0,-1.0],[2.0,-1.0],[2.0,-1.0]], decay = 0.9
Output: {"final_state":[0.6878,-0.3439],"corrected":[[2.0,-1.0],[2.0,-1.0],[2.0,-1.0],[2.0,-1.0]]}
Input: values = [[1.0,0.0,-1.0],[3.0,1.0,0.0]], decay = 0.0
Output: {"final_state":[3.0,1.0,0.0],"corrected":[[1.0,0.0,-1.0],[3.0,1.0,0.0]]}
final, outs = jax.lax.scan(step, init, xs) with step(carry, x) -> (new_carry, out).
The carry can be a tuple, such as (avg, power).
jnp.zeros_like(xs[0]) gives a starting state with the right shape and dtype.
Accepts: array
Accepts: number