Question: I wrote a Python code for this project scope please answer these questions with very detailed answers! This Report is very formal; it is meant
I wrote a Python code for this project scope please answer these questions with very detailed answers! This Report is very formal; it is meant to present the design of your agent and your observations on its performance and relationship to human cognition. Your Project Report will also be graded more strictly as well. Your Final Project Report should answer the following questions. They should be answered separately; we want to see a description of your agent's process, andthensee that description applied to selected problems. * How does your agent work? * What problems does your agent solve successfully? Select 3 (or more) problems, ideally with significant differences, that your agent solves correctly and describe your agent's reasoning process in each problem. * Where does your agent struggle? Select 2 (or more) problems that your agent does not solve correctly and describe the breakdown in your agent's reasoning process in each problem. * How would you characterize your overall approach to designing your agent? For example, is your agent described by an ever-expanding suite of heuristics it chooses from? Did you throw out one approach altogether and start over with a new one? * Compare the way(s) your final agent approaches the problems and the way(s) you, a human (we assume) would approach the problems. Does your agent take a similar/the same approach? Why or why not? Tip:Remember, we want to see how you put the content of this class into action when designing your agent. You don't need to use the principles and methods from the lectures precisely, but we want to see your knowledge of the content reflected in your terminology and your reflection. ******* SCOPE OF PROJECT******** The project is to create an AI agent that can pass a human intelligence test. You'll download a code package that contains the boilerplate necessary to run an agent you design against a set of problems inspired by theRaven's Progressive Matricestest of intelligence. Within it, you'll implement the Agent.py file to take in a problem and return an answer. There are four sets of problems for your agent to answer: B, C, D, and E. Each set contains four types of problems:Basic, Test,Challenge, and Raven's. You'll be able to see the Basic and Challenge problems while designing your agent, and your grade will be based on your agent's answers to the Basic and Test problems. The milestones throughout the semester will carry you through tackling more and more advanced problems: for Milestone A, you'll just familiarize yourself with the submission process and data structures. For Milestone B, you'll target the first set of problems, the relatively easy 2x2 problems from Set B. For Milestone C, you'll move on to the second set of problems, the more challenging 3x3 problems from Set C. For Milestone DE, you'll look at the more difficult Set D and Set E problems, building toward the final deliverable a bit later. One goal of Knowledge-Based Artificial Intelligence is to create human-like, human-level intelligence, and to use that to reflect on how humans actually think. If this is the goal of the field, then what better way to evaluate intelligence of an agent than by having it take the same intelligence tests that humans take? There are numerous tests of human intelligence, but one of the most reliable and commonly-used is Raven's Progressive Matrices. Raven's Progressive Matrices, or RPM, are visual analogy problems where the test-taker is given a matrix of figures and asked to select the figure that completes the matrix. In these projects, you will design agents that will address RPM-inspired problems such as the ones above. The goal of this project is to authentically experience the overall goals of knowledge-based AI: to design an agent with human-like, human-level intelligence; to test that agent against a set of authentic problems; and to use that agent's performance to reflect on what we believe about human cognition. As such, you might not use every topic covered in KBAI on the projects; the topics covered give a bottom-up view of the topics and principles KBAI, while the project gives a top-down view of the goals and concepts of KBAI. The full Raven's Progressive Matrices test consists of 60 visual analogy problems divided into five sets: A, B, C, D, and E. Set A is comprised of 12simple pattern-matching problemswhich we won't cover in these projects. Set B is comprised of 12 2x2 matrix problems, such as the first image shown above. Sets C, D, and E are each comprised of 12 3x3 matrix problems, such as the second image shown above. Problems are named with their set followed by their number, such as problem B-05 or C-11. The sets are of roughly ascending difficulty. For copyright reasons, we cannot provide the real Raven's Progressive Matrices test to everyone. Instead, we'll be giving you sets of problems ??? which we call "Basic" problems ??? inspired by the real RPM to use to develop your agent. Your agent will be evaluated based on how well it performs on these "Basic" problems, as well as a parallel set of "Test" problems that you will not see while designing your agent. These Test problems are directly analogous to the Basic problems; running against the two sets provides a check for generality and overfitting. Your agents will also run against the real RPM as well as a set of Challenge problems, but neither of these will be factored into your grade. Overall, by the end of the semester, your agent will answer 192 problems. More on the specific problems that your agent will complete are in the sections that follow. Each problem set (that is, Set B, Set C, Set D, and Set E) consists of 48 problems: 12Basic, 12 Test, 12 Raven's, and 12Challenge. Only Basic and Test problems will be used in determining your grade. The Raven's problems are run for authenticity and analysis, but are not used in calculating your grade. In designing your agent, you will have access to the Basic and Challenge problems; you may run your agent locally to check its performance on these problems. You will not have access to the Test or Raven's problems while designing and testing your agent: when you upload your agent to Gradescope, you will see how well it performs on those problems, but you will not see the details of the problems themselves. Challenge and Raven's problems are not part of your grade. Note that the Challenge problems will often be used to expose your agent to extra properties and shapes seen on the real Raven's problems that are not covered in the Basic and Test problems. The problems themselves generally ascend in difficulty from set to set (although many people reflect that Set E is a bit easier than Set D. The permitted libraries for this term's project are: * The Python image processing library Pillow (version 10.4.0). For installation instructions on Pillow. * The Numpy library (2.0.1 at time of writing). For installation instructions on numpy. * OpenCV (4.10.0, opencv-contrib-python-headless (4.10.0.84 at the time of writing)). **************************** MY CODE *************************************************************************** from PIL import Image import numpy as np from itertools import product import copy import logging from time import time from random import random TOLERANCE = .02 # 20% needed for problem 6 IMAGE_INTENSITY = 1 OBJECT_THRESHOLD = 20 UNCHANGED_W = 0 FILLED_W = 1 ROTATED_W = 2 DELETED_W = 10 ADDED_W = 10 FILLED_W = 3 DB_LEVEL = "WARNING" # create logger logger = logging.getLogger('agent') logger.setLevel(DB_LEVEL) #create console handler and set level ch = logging.StreamHandler() ch.setLevel(DB_LEVEL) formatter = logging.Formatter('%(levelname)s - %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) class UFarray: def __init__(self): # Array which holds label -> set equivalences self.P = [] # Name of the next label, when one is created self.label = 0 def makeLabel(self): r = self.label self.label += 1 self.P.append(r) return r # Makes all nodes "in the path of node i" point to root def setRoot(self, i, root): while self.P[i] rootj: root = rootj self.setRoot(j, root) self.setRoot(i, root) def flatten(self): for i in range(1, len(self.P)): self.P[i] = self.P[self.P[i]] def flattenL(self): k = 1 for i in range(1, len(self.P)): if self.P[i] 0 and image[x, y-1] == 1: labels[x, y] = labels[(x, y-1)] elif x+1 0 and image[x+1, y-1] == 1: c = labels[(x+1, y-1)] labels[x, y] = c if x > 0 and image[x-1, y-1] == 1: a = labels[(x-1, y-1)] uf.union(c, a) elif x > 0 and image[x-1, y] == 1: d = labels[(x-1, y)] uf.union(c, d) elif x > 0 and y > 0 and image[x-1, y-1] == 1: labels[x, y] = labels[(x-1, y-1)] elif x > 0 and image[x-1, y] == 1: labels[x, y] = labels[(x-1, y)] else: labels[x, y] = uf.makeLabel() uf.flatten() for (i, j) in labels: # Name of the label the current point belongs to label = uf.find(labels[(i, j)]) output[i, j] = label return output def to_image_array(filename): image = Image.open(filename).convert("L") #opens image, converts to single channel grayscale im_data = np.asarray(image, dtype=np.int32).T binary = np.zeros(im_data.shape) binary[np.where(im_data 128)] = 0 return binary def difference(a, b): if np.sum(a) != 0: diff = (np.sum(abs(a - b))) / np.sum(a) rolls = [np.roll(a, 1, 0), np.roll(a, -1, 0), np.roll(a, 1, 1), np.roll(a, -1, 1)] diffs = [(np.sum(abs(i - b))) / np.sum(i) for i in rolls ] logger.debug("Diff: " + str(diff)) logger.debug("Rolls: " + str(diffs)) for i in diffs: if i 0.03: logger.warning("Shapes the same with difference: " + str(diff)) pass return "UNCHANGED" else: return -1 def object_rotated(a, b): c = copy.copy(a) pre_diff = difference(a,b) for i in range(1,4): c = np.rot90(c) post_diff = difference(c, b) if abs(pre_diff - post_diff) > 0.05: if i == 3: return str("ROTATED_90") else: return str("ROTATED_" + str(i *90)) return -1 def object_filled(a, b): # Calculate the difference in the number of pixels diff = np.sum(b.pixels) - np.sum(a.pixels) # Check if the difference suggests "filling" within tolerance if 0 1 else "none" def get_net(self): net = {"ab": [], "bc": [], "ac": []} if len(self.nodes) == 3: if len(self.nodes[0]) > 10 or len(self.nodes[1]) > 10 or len(self.nodes[2]) > 10: return net for a in self.nodes[0]: for b in self.nodes[1]: if a.transform == "not matched" and b.transform == "not matched": if 0.95 2: diff.append(difference(self.images[1], self.images[2])) diff.append(difference(self.images[0], self.images[2])) return diff def get_black_ratio(self): ratio = [] if np.sum(self.images[1]) == 0: ratio.append(np.sum(self.images[0])) else: ratio.append(np.sum(self.images[0]) / np.sum(self.images[1])) if len(self.images) > 2 and np.sum(self.images[2]) != 0: ratio.append(np.sum(self.images[1]) / np.sum(self.images[2])) ratio.append(np.sum(self.images[0]) / np.sum(self.images[2])) else: ratio.append(np.sum(self.images[1])) ratio.append(np.sum(self.images[0])) return ratio def is_transformable(self): transformable = [] for i in range(len(self.blackratio)): if 0.95 2: diff.append(len(self.nodes[2]) - len(self.nodes[1])) diff.append(len(self.nodes[2]) - len(self.nodes[0])) return diff def check_simple_transform(self): length = len(self.transformable) simple = [-1, -1, -1] if length == 3 else [-1, -1] if length == 2: if self.transformable[0]: if simple[0] == -1: simple[0] = object_unchanged(self.images[0], self.images[1]) if simple[0] == -1: simple[0] = object_flipud(self.images[0], self.images[1]) if simple[0] == -1: simple[0] = object_fliplr(self.images[0], self.images[1]) if simple[0] == -1: simple[0] = object_rotated(self.images[0], self.images[1]) return simple for i in range(len(simple)): if self.transformable[i]: if simple[i] == -1: simple[i] = object_unchanged(self.images[i], self.images[(i+1)%length]) if simple[i] == -1: simple[i] = object_flipud(self.images[i], self.images[(i+1)%length]) if simple[i] == -1: simple[i] = object_fliplr(self.images[i], self.images[(i+1)%length]) if simple[i] == -1: simple[i] = object_rotated(self.images[i], self.images[(i+1)%length]) return simple def check_and_or_xor(self): length = len(self.images) operator = [-1, -1, -1] if length == 3 else [-1, -1] if length == 2: return "none" else: and_img = self.images[0] + self.images[1] and_img -= IMAGE_INTENSITY if difference(and_img, self.images[2]) IMAGE_INTENSITY)] = IMAGE_INTENSITY if difference(or_img, self.images[2]) IMAGE_INTENSITY)] = 0 if difference(xor_img, self.images[2]) 0: logger.warning("Found an object with " + str(np.sum(pixels)) + "pixels, passed") pass else: node = Node(pixels, "none", "not matched", 0, "Node_" + str(i)) this_figure.attr["Nodes"].append(node) # test_image = Image.fromarray(tmp) # test_image.show() #logger.debug("Figure " + str(figure_name) + " has " + str(len(this_figure.attr["Nodes"])) + " nodes") # uncolor component images this_figure.attr["Image"][np.where(this_figure.attr["Image"] > 1)] = IMAGE_INTENSITY # method that sets objects frame values def match(self, a, b, transform): if transform == "DELETED": a.transform = transform elif transform == "ADDED": b.transform = transform else: a.transform = transform a.match = b.name b.match = a.name b.transform = transform def match_nodes(self, fig_a, fig_b): print("Entered match_nodes") print("Frame: " + str(fig_a.name)) print("Frame: " + str(fig_b.name)) for a in fig_a.frame["Nodes"]: for b in fig_b.frame["Nodes"]: if a.match == "none": a.match_weight = 0 if b.match == "none": b.match_weight = 0 while True: transform = "no transform" if (a.match_weight and b.match_weight) == UNCHANGED_W: transform = object_unchanged(a, b) if transform == "UNCHANGED": self.match(a, b, transform) break else: a.match_weight += 1 b.match_weight += 1 elif (a.match_weight len(fig_b.frame["Nodes"])) and a.match == "none": a.transform = "DELETED" elif (len(fig_a.frame["Nodes"]) conf: answer = key conf = confidence[key] if DB_LEVEL == "DEBUG" or DB_LEVEL == "INFO": problem.frames["AB"].print_frame() problem.frames["C" + str(answer)].print_frame() problem.frames["AC"].print_frame() problem.frames["B" + str(answer)].print_frame() print(confidence) if conf conf: answer = key conf = confidence[key] if DB_LEVEL == "DEBUG" or DB_LEVEL == "INFO": problem.frames["ABC"].print_frame() problem.frames["DEF"].print_frame() problem.frames["GH" + str(answer)].print_frame() problem.frames["ADG"].print_frame() problem.frames["BEH"].print_frame() problem.frames["CF" + str(answer)].print_frame() problem.frames["BFG"].print_frame() problem.frames["CDH"].print_frame() problem.frames["AE" + str(answer)].print_frame() problem.frames["GH1"].print_frame() print(confidence) if conf
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
