def Part3(): actor = ['Alec Baldwin', 'Steve Carell'] Label = {'Alec Baldwin': -1, 'Steve Carell': 1} add = "/testing/" add_train = "/training/" x, y, theta = part3.set_creation(actor, Label, add_train) theta_p3 = part3.grad_descent(part3.f, part3.df, x, y, theta, 0.001, 20000) part3.test(theta_p3, Label, actor, add_train) print theta_p3.shape[0] x, y, theta = part3.set_creation(actor, Label, add_train) theta_p3 = part3.grad_descent(part3.f, part3.df, x, y, theta, 0.001, 20000) part3.test(theta_p3, Label, actor, add) #part 4 plt.imshow(theta_p3[1:].reshape((32, 32))) plt.show() x, y, theta = part5.set_creation_limited(actor, Label, 1) theta_p3 = part3.grad_descent(part3.f, part3.df, x, y, theta, 0.001, 20000) plt.imshow(theta_p3[1:].reshape((32, 32))) plt.show() x, y, theta = part3.set_creation(actor, Label, add) theta_p3 = part3.grad_descent(part3.f, part3.df, x, y, theta, 0.001, 3000) plt.imshow(theta_p3[1:].reshape((32, 32))) plt.show() theta_p3 = part3.grad_descent(part3.f, part3.df, x, y, theta, 0.001, 10) plt.imshow(theta_p3[1:].reshape((32, 32))) plt.show()
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: # convolve outputString = str(int(part0.test())) elif partIdx == 1: # gaussian outputString = str(int(part1.test())) elif partIdx == 2: # sharpen outputString = str(int(part2.test())) elif partIdx == 3: # median outputString = str(int(part3.test())) elif partIdx == 4: # theta and mag outputString = str(int(part4.test())) return outputString
conv_func = part0.convolve apply_filter(conv_func, box_filter(2), 'box2') else: print "Please test your code using part0.py prior to using this function." print "-"*15 + "part1" + "-"*15 t1 = part1.test() print "Unit test: {}".format(t1) if t1: apply_filter(conv_func, part1.make_gaussian(5,3), 'gaussian5_3') else: print "Please test your code using part1.py prior to using this function." print "-"*15 + "part2" + "-"*15 t2 = part2.test() print "Unit test: {}".format(t2) if t2: apply_filter(conv_func, part2.make_sharp(5,3), 'sharp5_3') else: print "Please test your code using part2.py prior to using this function." print "-"*15 + "part3" + "-"*15 t3 = part3.test() print "Unit test: {}".format(t3) if t3: apply_median(5) else: print "Please test your code using part3.py prior to using this function."
conv_func = signal.convolve2d if t0: conv_func = part0.convolve apply_filter(conv_func, box_filter(2), 'box2') else: print "Please test your code using part0.py prior to using this function." print "-" * 15 + "part1" + "-" * 15 t1 = part1.test() print "Unit test: {}".format(t1) if t1: apply_filter(conv_func, part1.make_gaussian(5, 3), 'gaussian5_3') else: print "Please test your code using part1.py prior to using this function." print "-" * 15 + "part2" + "-" * 15 t2 = part2.test() print "Unit test: {}".format(t2) if t2: apply_filter(conv_func, part2.make_sharp(5, 3), 'sharp5_3') else: print "Please test your code using part2.py prior to using this function." print "-" * 15 + "part3" + "-" * 15 t3 = part3.test() print "Unit test: {}".format(t3) if t3: apply_median(5) else: print "Please test your code using part3.py prior to using this function."