Skip to content

Creating a running average with self.variable #1005

Answered by jheek
matthias-wright asked this question in Q&A
Discussion options

You must be logged in to vote

By default all variables are immutable during apply. This is to avoid accidental side effects in otherwise stateless code.
Here you should use y, new_state = net.apply(params, x, mutable=['moving_stats']).
The new_state will be a dict containing 'moving_stats' with the updated batch statistics.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by matthias-wright
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants