2

Neural Network Weight Initialization

Unsolved
Neural Networks

Difficulty: 4 | Problem written by hemdan219@gmail.com
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

 You are given the number of nodes in input layer x_nodes, a list of the number of nodes in each of two hidden layers h_nodes, and finally the number of nodes in the output layer y_nodes.

Your task is to initialize weight matrices for the three layers depending on the nodes of previous layer and the nodes of current layer. Don't worry about initializing a bias vector. The size of the 3 weight matrices in this small neural network is given by the following formula, where \(n^{[l]}\) is the number of nodes in layer \(l\).

\( Size \,of \,{w^{[l]}}={({n^{[l]}},{n^{[l-1]}})}\),

 

Use np.random.randn to initialize the weights.

Return a tuple containing the three weight matrices W1, W2, and W3.

Use np.random.seed(3) to initialize the random number generator to get the same expected output as our test cases.

 

 

Sample Input:
<class 'list'>
x_nodes: 3
h_nodes: [7, 4]
y_nodes: 1

Expected Output:
<class 'tuple'>
(array([[ 1.78862847, 0.43650985, 0.09649747], [-1.8634927 , -0.2773882 , -0.35475898], [-0.08274148, -0.62700068, -0.04381817], [-0.47721803, -1.31386475, 0.88462238], [ 0.88131804, 1.70957306, 0.05003364], [-0.40467741, -0.54535995, -1.54647732], [ 0.98236743, -1.10106763, -1.18504653]]), array([[-0.2056499 , 1.48614836, 0.23671627, -1.02378514, -0.7129932 , 0.62524497, -0.16051336], [-0.76883635, -0.23003072, 0.74505627, 1.97611078, -1.24412333, -0.62641691, -0.80376609], [-2.41908317, -0.92379202, -1.02387576, 1.12397796, -0.13191423, -1.62328545, 0.64667545], [-0.35627076, -1.74314104, -0.59664964, -0.58859438, -0.8738823 , 0.02971382, -2.24825777]]), array([[-0.26776186, 1.01318344, 0.85279784, 1.1081875 ]]))

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Ipsam eveniet repudiandae dolor ut voluptatibus qui nulla explicabo corrupti aliquam quia, necessitatibus quod praesentium omnis blanditiis voluptates fugiat sequi facere veniam quis ad, hic obcaecati modi quae minus deleniti? Suscipit dignissimos nobis nam, eius soluta consequuntur nisi dolor minus deserunt nihil quidem optio vitae. Necessitatibus nam minus facilis ratione, consequatur odit vitae distinctio doloremque impedit voluptates est veritatis natus aliquam, reprehenderit placeat illum natus cumque non?

Fugiat expedita voluptatibus suscipit consectetur quibusdam quisquam praesentium odit hic earum, officiis nostrum voluptates, alias repellendus commodi fugit in adipisci eos deleniti modi nisi?

Assumenda cum illum nulla doloremque non quos maxime reprehenderit odio?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)