Question: need help asap due in 3 hours Problem 1 will get you familiar with several ways to build and use higher order functions, In this

Problem 1 will get you familiar with several ways to build and use higher order functions, In this problem, we ask you to fill in the code for a number of missing functions in problem..py : 1. add_map: This takes in a function, fun, and a list, t, as its arguments and returns a list, which consists of applying fun then adding 1 to each element of the input kist, L. 2. conpose_nap: This takes in two functions, fund and fun2, and a list, t, as its arguments and returns a list, which corisists of applying funz then funz to each element of the input list, L. Note that you must apply the functions in that order: call funt first, then fon2 on the output of fund for each element in the input list L. 3. compose: This takes in two functions, fun1 and fun2, and returns a new function, ret_fun . The new function takes in a single argument, 1 , then calls fun2 followed by fun1 on that argument, returning the result. Note again that the order matters. Expected return type for compse is a function and not a volue. 4. repeater : This takes in a function, fun and an integet, num_repeats, and retums a new function, ret_fun. The new function takes in an input x and calls fun on it rum_repeats times fin other words, you call fun on the. output of caling fun on the output of calling fun _ on the input, repeated as many times as nun reptats). Expected refurn type for repeater is a function and not o volue. 3:26 AM [f([a,b,c]),f([b,c,d]),f([c,d,+]),f([d,e,f]),f([e,f,b])] Note two things: 1. The length of the output list is smaller than the length of the input list. If the input list is of length k, the output list will be of length k - iddth 1, where width is the width of the stencil that f applies. 2. You can think of a stencil as a generalization of map that uses neighboring elements to compute the output instead of just the element itself. If f has a window of width 1 , the cutput is basically like using map. We will ask you to write a function for applying stencils that takes in an input list, a stencil function, and a third parameter that telis you how wide the stencil function is, in the case shown above, the stencil function uses a width of 3 to slide over the list [a,b,c,d,e,t,8]. Filter, Cross-correlation and Convolution Given a filer of length k that specifies a list of k numbers (for a 1-D box filter), when applied to a input signal, computes its result by multiplying the first element of the filter by the first element of the input, the second element of the filter by the second element of the input, and so on, and then adding alf the results together to output one single value, In the signal processing literature, a filter is a signal that when applied to a target signal, removes some unwanted components or features from the target signal. So if you have a filter (list), say b, of size 3 with elements b[e], b[1]. b[2] and you slide it over the list [a, b, c. d, e, f,81, the expected output would be: [b[]a+b[1]b+b[2]c, b[]b+b[1]c+b[2]d, b[]c+b[1]d+b[2]+e, b[]d+b[1]+=+b[2]+f, b[b]++b[1]++b[2]+g] In one dimension (1-D), applying a filter in this way (shown above) computes the (discrete) cross-correlation of the signal in the input list with the filter. This is a measure of similarity between the signal and the filter. Additionally, the convolution operation in 1-D is very similar to the cross-correlation operation but has a slight variation. In the convolution operation, the filter is first flipped and then applied to the input signaf, In other words, convolution is simply a cross-correlation on the input signal with a flipped version of the given filter. S0, if you have a fiter with elements b[0],b[1],b[2] and you perform a convolution operation on the list {a,b, c, d,e,f,2], you are basically sliding over the list with a flipped version of the filter, hence, the output you get would be: [b[2]a+b[1]b+b[e]c,b[2]b+b[1]+c+b[0]d,b[2]c+b[1]d+b[e]e1b[2]d+b[1]c+b[e]f,b[2]e+b[1]f+b[e]b] Convolution conveys how the shape of signal is modified by the filter. In two dimensions, fiters can be used to perform image-processing tacks like blurring and edge detection. These types of fiters are also one of the kny steps in deep neural networks that operate on images lthey form the core of the "convolution" layers): In the second part of Problem 2, we will ask you to write a function that, when given a list of filter elements, creates a stenell function from those elements. Finally, coming to the point, we ask you to fill in the two functions in problen2.py 1. stencil (data, f, width) : This function takes in a list, data, a function, f, and an int, width, and retums a list. This function returns an output list of length kidth+1, the result of applying the stencil function f to the input list data Finally, coming to the point, we ask you to fill in the two functions in problen2, py : 1. stencil (data, f, wiath) : This function takes in a list, dota, a function, f, and an int, width, and returns a list. This function retums an output list of length k-wadth+1, the result of applying the stencil function f to the input list data 2. create_box (box) : This function accepts a list, box, and returns two outputs: a new function and a width (int). The width is the length of the box (the number of elements that the filter looks at). The new function is a stencil function that operates on items from an input list and applies a convolution operation to them as described above. The function should check at the beginning. if the length in the input parameter is the same as the length of box. If not, the foliowing error should be printed: calisng box filter with the wrong length Iist. Expected length of list should be n. where n is the length of box. For example if ne?, the printed waming should be: calling box tilter with the arong length list. Expected length of list should be 7. after the print statement return 0 . Moreover, the comments under ereate box () in problem2.py provide further explanation on what create_boxf(box) is supposed to do
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
