Week1 assignment: Why the std of the output is between 0.55 and 0.65?

Verify the generator block function

def test_gen_block(in_features, out_features, num_test=1000):
block = get_generator_block(in_features, out_features)

# Check the three parts
assert len(block) == 3
assert type(block[0]) == nn.Linear
assert type(block[1]) == nn.BatchNorm1d
assert type(block[2]) == nn.ReLU

# Check the output shape
test_input = torch.randn(num_test, in_features)
test_output = block(test_input)
assert tuple(test_output.shape) == (num_test, out_features)
**assert test_output.std() > 0.55**

** assert test_output.std() < 0.65**

test_gen_block(25, 12)
test_gen_block(15, 28)

I’m confused with the range

Hi @Sean_Zhou,
This is just a way to roughly check that the generator block function is producing expected results.
Since the input is a sample from the normal distribution (using torch.randn), then the output should have about the same standard deviation every time. I’m not sure if the test developer reasoned their way through to what the std() should be, but the easiest way would be to just run it (using their known-good code) and look at the results.

You can check for yourself by adding a print statement temporarily to print test_output.std() to see your results. Try running multiple times and see how consistent the value is. When I try it I get something close to .58 every time. The test checks for anything between 0.55 and 0.65 to allow a little wiggle room to account for variation due to the randomness of the input data.