Search

Search papers and lessons

Noisy Networks

Level 4 · 12 min read

A noisy network learns how much random noise to add to its own weights, so exploration comes from the network itself instead of a fixed epsilon rule.

On this page

  • Colour = topic mix
  • Probability
  • Reinforcement learning
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

A reinforcement-learning agent has to try things it does not yet know are good. A noisy network handles this by adding random noise to its own weights, with a learned amount of noise for each weight, so the network's output varies from one step to the next. The agent then acts greedily on the noisy output, and the randomness in the network does the exploring. The network learns how big the noise should be, so it explores more where it is unsure and less where it has learned.

Builds on: Deep Q-Network, Gaussian (Normal) Distribution · Leads to: Rainbow, which combines it with other improvements to DQN

Where it's used

Atari games with sparse rewards. In games such as Montezuma's Revenge, the agent must perform a long sequence of correct actions before it gets any reward. A common fix, the Epsilon-Greedy Policy, picks a random action with a fixed probability. That random action is unlikely to continue a useful sequence, so the agent rarely gets far. Noisy networks were introduced to fix this by making exploration part of the value network, and they gave clear gains on hard Atari games.

Rainbow. The Rainbow agent of 2017 combined six improvements to DQN, and noisy networks replaced its epsilon-greedy exploration. The combined agent was far stronger across the Atari suite than any single improvement, which is why noisy layers now appear in many reinforcement-learning codebases.

Any problem with a learned value function that needs exploration. The same layer can sit in a policy head or a value head. Anywhere a network must choose actions and must keep learning about options it has not tried much, a noisy final layer provides exploration without a separate schedule to tune.

How it works

Take a single neuron with one input and one weight, and trace what the noise does. Let the usual weight be μ=0.5\mu = 0.5, the noise scale be σ=0.2\sigma = 0.2, and the input be x=2x = 2.

  1. Write the weight as a mean plus a noisy part. The noisy weight is w=μ+σεw = \mu + \sigma \varepsilon, where ε\varepsilon is a random number drawn from a standard normal distribution (mean 0, variance 1). The network stores μ\mu and σ\sigma as trainable parameters. Check: with ε=0\varepsilon = 0 the weight is just μ=0.5\mu = 0.5.
  2. Draw a fresh noise sample. Suppose the draw is ε=1\varepsilon = 1. The weight is 0.5+0.2⋅1=0.70.5 + 0.2 \cdot 1 = 0.7. Check: this is above the mean, as expected for a positive draw.
  3. Compute the output. The output is y=wx=0.7⋅2=1.4y = w x = 0.7 \cdot 2 = 1.4. Check: the mean output is 0.5⋅2=1.00.5 \cdot 2 = 1.0, so the noise moved the output by 0.40.4.
  4. Draw again and see the other side. With ε=−1\varepsilon = -1 the weight is 0.30.3 and the output is 0.60.6. The noise moved the output by −0.4-0.4 this time.
  5. Learn the scale. During training, backpropagation sends the gradient into μ\mu and into σ\sigma just as for any weight, using stochastic gradient descent. If the noise hurts the loss, σ\sigma shrinks. If the noise helps the agent find better actions, σ\sigma can grow. The agent therefore decides how much to explore.
  6. Act greedily on the noisy values. In a state, the network gives a Q value for each action. A Q value is the network's estimate of the total future reward for taking that action in that state. The agent takes the action with the largest noisy value, which is called acting greedily. Because the noise changes from step to step, the choice changes too, and that is the exploration.
  7. Use the means when evaluating. After training, the noise can be switched off so that the agent plays with its best estimates, the means μ\mu. This is the usual practice, and it avoids playing with randomness when the goal is the best score.
flowchart LR
  P[means mu and scales sigma] --> N[draw noise epsilon]
  N --> W[noisy weights mu plus sigma times epsilon]
  W --> Q[Q values for each action]
  Q --> A[take the greedy action]
  A --> L[loss gradient updates mu and sigma]
  L --> P

The loop shows the important point: the noise is part of the function being trained, so the gradient can change how much noise there is.

The math

The paper's noisy linear layer computes y=μwx+μb+(σw⊙εw)x+σb⊙εby = \mu^{w} x + \mu^{b} + \left(\sigma^{w} \odot \varepsilon^{w}\right) x + \sigma^{b} \odot \varepsilon^{b}. Here ⊙\odot means element-by-element multiplication, xx is the layer's input vector, μw\mu^{w} and σw\sigma^{w} are matrices of the same shape as the weights, and μb\mu^{b} and σb\sigma^{b} are vectors for the bias. The random matrix εw\varepsilon^{w} and the random vector εb\varepsilon^{b} are the noise.

Step 2 in symbols: the noisy weights

Each weight is wij=μijw+σijwεijww_{ij} = \mu^{w}_{ij} + \sigma^{w}_{ij} \varepsilon^{w}_{ij}, where εijw\varepsilon^{w}_{ij} is drawn from a standard normal distribution. The mean μijw\mu^{w}_{ij} is the centre of the distribution of possible weights, and σijw\sigma^{w}_{ij} is its spread. Because the spread is learned, the layer has a learned degree of randomness.

Step 3 in symbols: the output

Multiply the noisy matrix by the input vector and add the noisy bias. The output for neuron jj is

yj=∑i(μjiw+σjiwεjiw)xi+μjb+σjbεjb.y_j = \sum_i \left(\mu^{w}_{ji} + \sigma^{w}_{ji} \varepsilon^{w}_{ji}\right) x_i + \mu^{b}_j + \sigma^{b}_j \varepsilon^{b}_j.

In the one-weight example, y=(0.5+0.2ε)⋅2y = (0.5 + 0.2 \varepsilon) \cdot 2. With ε=1\varepsilon = 1 this gives 1.41.4, as in Step 3 of How it works.

Step 5 in symbols: learning the scale

Let L(θ)L(\theta) be the loss, here the DQN loss with the noisy network's Q values, where θ\theta stands for all the μ\mu and σ\sigma. The chain rule gives

∂L∂σjiw=∂L∂wji⋅εjiw,\frac{\partial L}{\partial \sigma^{w}_{ji}} = \frac{\partial L}{\partial w_{ji}} \cdot \varepsilon^{w}_{ji},

so the change to the spread depends on the gradient of the weight and on the sign and size of the noise draw. The mean is learned with ∂L/∂μjiw=∂L/∂wji\partial L / \partial \mu^{w}_{ji} = \partial L / \partial w_{ji}.

Noise with fewer random numbers

Drawing an independent normal number for every weight is costly for big layers. The paper's factorised form draws one number per input and one per output, and builds the weight noise from them. Let f(z)=sign⁡(z)∣z∣f(z) = \operatorname{sign}(z)\sqrt{|z|}, let εi\varepsilon_i be a draw per input and εj\varepsilon_j a draw per output, and set

εjiw=f(εj)f(εi),εjb=f(εj).\varepsilon^{w}_{ji} = f(\varepsilon_j) f(\varepsilon_i), \qquad \varepsilon^{b}_j = f(\varepsilon_j).

For a layer with pp inputs and qq outputs this needs p+qp + q draws, not pqpq. The function ff keeps the noise from being too small when the draws are near zero.

Worked examples

Example
1. One weight, one input (tiny, by hand)

Take μ=0.5\mu = 0.5, σ=0.2\sigma = 0.2, x=2x = 2 and no bias.

  1. The noisy weight is w=0.5+0.2εw = 0.5 + 0.2\varepsilon.
  2. Draw ε=0\varepsilon = 0. Then w=0.5w = 0.5 and y=0.5⋅2=1.0y = 0.5 \cdot 2 = 1.0. This is the mean output.
  3. Draw ε=1\varepsilon = 1. Then w=0.7w = 0.7 and y=1.4y = 1.4.
  4. Draw ε=−1\varepsilon = -1. Then w=0.3w = 0.3 and y=0.6y = 0.6.
  5. Interpretation: each unit of noise moves the output by σx=0.4\sigma x = 0.4 in one direction or the other. The mean 1.01.0 sits between the two outcomes, and the noise is symmetric around it.
Example
2. Two actions and an exploration choice (the standard case)

A state has one input feature x=1x = 1. Two actions each have a single weight, with these learned values:

  • Left: μ=1.0\mu = 1.0, σ=0.5\sigma = 0.5.
  • Right: μ=0.8\mu = 0.8, σ=0.1\sigma = 0.1.
  1. With the noise switched off, the means give Qleft=1.0Q_\text{left} = 1.0 and Qright=0.8Q_\text{right} = 0.8. The greedy action is left.
  2. Draw a sample with εleft=−1\varepsilon_\text{left} = -1 and εright=+1\varepsilon_\text{right} = +1. Then Qleft=(1.0−0.5)⋅1=0.5Q_\text{left} = (1.0 - 0.5) \cdot 1 = 0.5 and Qright=(0.8+0.1)⋅1=0.9Q_\text{right} = (0.8 + 0.1) \cdot 1 = 0.9. The greedy action is right.
  3. Draw a second sample with εleft=+1\varepsilon_\text{left} = +1 and εright=−1\varepsilon_\text{right} = -1. Then Qleft=1.5Q_\text{left} = 1.5 and Qright=0.7Q_\text{right} = 0.7. The greedy action is left again.
  4. Interpretation: the action with the larger uncertainty, left with σ=0.5\sigma = 0.5, is tried more often, while right with σ=0.1\sigma = 0.1 is almost always its mean value. The agent explores in proportion to what it does not know. A fixed epsilon rule would pick random actions regardless of how uncertain each one is.
Example
3. A realistic noisy output layer (the factorised form)

A small output layer maps a 2-number input to 2 outputs. The layer has μw=(1001)\mu^{w} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, μb=(0,0)\mu^{b} = (0, 0), and σw=σb=0.5\sigma^{w} = \sigma^{b} = 0.5 everywhere. The input is x=(2,3)x = (2, 3). The noise draws are εi=(0.25,−4)\varepsilon_i = (0.25, -4) for the two inputs and εj=(1,−1)\varepsilon_j = (1, -1) for the two outputs.

  1. Compute the input factors: f(0.25)=0.25=0.5f(0.25) = \sqrt{0.25} = 0.5 and f(−4)=−4=−2f(-4) = -\sqrt{4} = -2.
  2. Compute the output factors: f(1)=1f(1) = 1 and f(−1)=−1f(-1) = -1.
  3. Build the weight noise, εjiw=f(εj)f(εi)\varepsilon^{w}_{ji} = f(\varepsilon_j) f(\varepsilon_i). Row 1 (factor 11) is (0.5,−2)(0.5, -2). Row 2 (factor −1-1) is (−0.5,2)(-0.5, 2).
  4. Build the noisy weights, w=μ+σεww = \mu + \sigma \varepsilon^{w}. Row 1 is (1+0.25,0−1)=(1.25,−1)(1 + 0.25, 0 - 1) = (1.25, -1). Row 2 is (0−0.25,1+1)=(−0.25,2)(0 - 0.25, 1 + 1) = (-0.25, 2).
  5. Build the noisy bias, σbf(εj)\sigma^{b} f(\varepsilon_j), which is (0.5,−0.5)(0.5, -0.5).
  6. Compute the outputs. Output 1 is 1.25⋅2+(−1)⋅3+0.5=0.01.25 \cdot 2 + (-1) \cdot 3 + 0.5 = 0.0. Output 2 is (−0.25)⋅2+2⋅3−0.5=5.0(-0.25) \cdot 2 + 2 \cdot 3 - 0.5 = 5.0.
  7. Interpretation: the sampled outputs are (0.0,5.0)(0.0, 5.0) and the means give (2,3)(2, 3). Here the noise is large compared with the means, so the sample is far from the mean. The agent would act greedily on 5.05.0 and choose output 2 for this sample.

Try it: with the noise switched off at evaluation, what are the two outputs for x=(2,3)x = (2, 3)?

Answer: (2,3)(2, 3). With the means alone, output 1 is 1⋅2+0⋅3+0=21 \cdot 2 + 0 \cdot 3 + 0 = 2, and output 2 is 0⋅2+1⋅3+0=30 \cdot 2 + 1 \cdot 3 + 0 = 3. The agent would then choose output 2, the same as the noisy sample, but for a different reason.

Common mistakes and tradeoffs

It is tempting to think a noisy network is just a network with dropout. In fact dropout switches neurons off at random to regularise, while the noise here is a learned scale on the weights, and the gradient controls it. The goal is exploration rather than preventing overfitting.

It is tempting to think the noise is the same as epsilon-greedy with a smaller number. In fact epsilon-greedy picks a random action with a fixed chance that never adapts. A noisy network's exploration depends on the state, because σ\sigma is learned and the spread of Q values depends on the input. Where the agent is sure, it explores little; where it is not sure, it explores more.

It is tempting to think the noise is resampled only once per episode. In practice it is resampled often, typically each step or each training update, because a noise draw that is held fixed for a long time gives correlated behaviour and loses the benefit.

It is tempting to think the noise should stay on at evaluation. In fact the usual practice is to use the means, so the reported score reflects the learned values rather than a random draw.

Use noisy networks when exploration is the bottleneck, especially with sparse rewards, and when you can afford roughly twice the parameters in the noisy layers, since each has a mean and a scale. Do not use them when a simple policy already explores enough, or when the network is small and epsilon-greedy is cheap and effective. Alternatives include entropy bonuses (see Maximum Entropy Reinforcement Learning), count-based bonuses, and curiosity signals.

History

Before 2017, the standard exploration in deep reinforcement learning was epsilon-greedy, used in the original DQN work. Its weakness on hard exploration problems was well known, and the common response was to add intrinsic rewards or to tune the schedule by hand.

Fortunato and colleagues proposed noisy networks in 2017, putting learned noise directly into the network weights and showing that it improved exploration on Atari games compared with epsilon-greedy. The factorised form was introduced to make the noise cheap to draw for large layers.

Later in 2017, the Rainbow paper combined noisy networks with several other DQN improvements and reported a combined agent that was stronger on the Atari suite than the parts alone. That combination made noisy layers a standard component in later value-based agents.

Recap

  • Exploration can come from the network itself: each weight is a learned mean plus learned noise.
  • Each step draws new noise, so the greedy action changes, and the gradient learns how large the noise should be.
  • The noisy layer replaces epsilon-greedy, and its exploration depends on the state and on what the agent is unsure about.
  • The factorised form needs only one draw per input and output, which keeps large layers cheap.
  • Next, read the Rainbow paper to see noisy networks combined with other DQN improvements.

Check yourself

QuestionA weight has mean μ=2\mu = 2 and scale σ=0.5\sigma = 0.5. The noise draw is ε=−2\varepsilon = -2. What weight is used for that step?Show answer
w=μ+σε=2+0.5⋅(−2)=2−1=1w = \mu + \sigma \varepsilon = 2 + 0.5 \cdot (-2) = 2 - 1 = 1.
QuestionA noisy layer has input x=3x = 3, weight mean μ=1.5\mu = 1.5, weight scale σ=0.2\sigma = 0.2 and no bias. The draw is ε=1\varepsilon = 1. What is the output?Show answer
The weight is 1.5+0.2⋅1=1.71.5 + 0.2 \cdot 1 = 1.7, so the output is 1.7⋅3=5.11.7 \cdot 3 = 5.1. The mean output would be 1.5⋅3=4.51.5 \cdot 3 = 4.5.
QuestionWhy does a noisy network explore more in states where it is uncertain, while epsilon-greedy explores equally everywhere?Show answer
The scale σ\sigma is learned by the gradient. Where the loss is sensitive to the weights and the agent has not learned good values, the gradient tends to keep the noise larger. Epsilon-greedy uses one fixed probability for all states, so it cannot adapt to uncertainty.
QuestionIn the factorised form, a layer has 4 inputs and 3 outputs. How many random draws does it need, and how many weights does it have?Show answer
It needs 4+3=74 + 3 = 7 draws, one per input and one per output. It has 4⋅3=124 \cdot 3 = 12 weights, plus 3 biases, and its noise is built from the 7 draws.

Sources