Homework 2 SOLUTIONS(40pts) CMSC 421 - Intro to Artificial Intelligence Neural Networks 1. Consider the function f (x, y) = (x + 20)2 + 2(y − 10)2 . (a) Determine the gradient (with respect to x and y) of f . Answer: ∆f (x, y) = (2x + 40, 4y − 40) (b) Starting at (0,0), run the gradient descent algorithm BY HAND for three iterations, with a step size of 1. What is the “best guess” for the minimum of f at this point, and what are the corresponding x and y coordinates? As always, show your work as you would in a math class. Answer: This one depends on how you interpreted the step size. All you needed to do was multiply the step size by the negative of the gradient, and shift the guess by that much. Since the step size is 1, we can skip the multiplication and just subtract the gradient from the point: • Step 1: ∆f (x, y) = (2(0) + 40, 4(0) − 40) = (40, −40). So, our new point is (-40, 40). • Step 2: ∆f (x, y) = (2(−40) + 40, 4(40) − 40) = (−40, 120). So, our new point is (0,-80). • Step 3: ∆f (x, y) = (2(0) + 40, 4(−80) − 40) = (40, −360). So, our new point is (-40,280). If you misinterpreted the question as wanting you to make steps of a fixed size, then calculating the answer would be significantly complicated, and we won’t go through the steps here. This method would always be guaranteed to get us within (step size/2) of a local minimum if one exists. However, in general it takes a lot more time and resources to get there. (c) Determine (analytically, as in the full and proper way using calculus - even if the answer looks obvious to you) the actual minimum value of f , along with the corresponding x and y coordinates. Answer: 1 Relative minima occur at critical points, this function has only one critical point in (-20, 10). There are various ways to check whether this is the minimum or maximum; an easy one in this case is to just realize that the function value at this point is 0, and the function can never be negative (since it is a sum of positive multiples of squares), so therefore (-20, 10) must be the minimum. (d) How far off was the algorithm (compute the Euclidean distance)? If you ran it for more iterations, would it be able to do better? Why or why not? Answer: p √ 2 2 The √ algorithm was off by ((−20) − (−40)) + (10 − 280) = 73300 = 10 733. If we ran it for more iterations, we would not do any better, as the y-coordinate would just keep bouncing to larger and larger magnitudes. To make it improve with each iteration, we would need to reduce the learning rate - the jumps are too large right now. 2 2. Draw a feedforward neural network that simulates: (a) ...an OR gate. Answer: p ----- q ----- --------------| | | | 1 | | | | | |-------| 1 | ----> output | | | | 1 | | | | | --------------- (b) ...an IMPLIES (P → Q) gate. Answer: The key insight here is that (P → Q) is equivalent to (¬P ∨ Q), read “(Not P) OR (Q)”. p ----- q ----- --------------| | | | -1 | | | | | |-------| 0 | ----> output | | | | 1 | | | | | --------------- 3 3. Consider the following feedforward neural network, with inputs a1 , a2 , and a3 : a_1 ----- a_2 ----- a_3 ----- ----------------------------| | | | | | | 1 | | | | | | | | | | | |-------| 2 | ------ | 1 | | | | | | | | | 1 | | | | | | | | |-------| 2 | ----> output --------------| | | --------------| | | | | | | 1 | | | 1 | 1 | ------ | | | | | | | | | ----------------------------- Draw a table listing the 8 possible combinations of inputs, plus whether or not the network as a whole fires for each one. Your table should have 4 columns (one for each input indicating whether it is firing or not, and one for the output) and 8 rows. Each entry should be either a 0 (not firing) or a 1 (firing). Answer: a1 a2 a3 output 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 4 4. Consider the following recurrent neural network: From time 0 onward, Unit a has a constant stream of power (1s) coming in. The inputs to Unit b and Unit c come from the set of units, and change over time. Assume that sending a signal along a single pathway takes 1 time step. 5 (a) Draw a table with the firing status of the three units over the first 8 time steps. Your table should have 3 columns, one for each unit, and 8 rows, one for each time step (labeled 0 through 7). The columns should be populated with either 0 (not firing) or 1 (firing). Answer: 0 1 2 3 4 5 6 7 Unit a Unit b Unit c 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 (b) Draw the same table, except for a slightly modified network where the output from Unit b is additionally piped back into Unit a, with a weight of -1. (The rest of the network is left unchanged - Unit a still has the stream of incoming 1s, and Unit b is still also piping output to Unit c.) Answer: 0 1 2 3 4 5 6 7 Unit a Unit b Unit c 1 0 0 1 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 1 6
© Copyright 2026 Paperzz