编程代写|Module 2A: Assignment

这是一个编程代写的案例,包含三个Task

You are a recent hire who works at a start-up AI weather image company. Your new job requires several tasks to support the different teams of the company. Your first task is to write an algorithm that can find a portion of pixels within a single colour space. For example, it may be useful to identify one colour of pixels versus another, as in black and white photographs. In addition, the new business wants to implement an AI knowledge-based system to help customers with some of the terminology of AI. Some of the terminology is simple, i.e. names and years of famous AI events, but others need to be more detailed. Lastly, the business has been receiving weather data, so your task is to analyse weather data and form predictions.

If successful, the company will put your applications in production for customers. You will therefore need to provide detailed comments in the code explaining the steps you have taken to design your solution. As deliverables, you will complete the following three (3) parts:

Parts

  1. Programming Part 1: Write a programme that implements the flood fill algorithm, and iden- tifies and changes the marked pixels.
  2. Programming Part 2: Write a programme that accesses an AI knowledge base to search for facts based on the user’s input.
  3. Programming Part 3: Write a programme that specifies the level of confidence in weather prediction.

0.1.4 Instructions:

  1. Complete all three parts of the assignments by writing the Python codes.
  2. Run your codes to ensure that the required outputs are delivered.
  3. Submit the assignment for grading and to get feedback.

0.1.5 Submission:

Click on the submit button on the top right after you run the code and all three parts are complete.

1 Programming Part 1: Complete the flood fill algorithm

Write a programme that implements the flood fill algorithm, and identifies and changes the marked pixels. Furthermore, blank pixels are ignored.

1.0.1 Assessment task:

In this part, you’ll write the code that implements the flood fill algorithm and identifies and changes the marked pixels. Furthermore, blank pixels are ignored. To do this, you’ll use any breadth-first search algorithm. The code is partially written below.

1.0.2 Marks:

This part is of 10 Marks. This part is divided into three assessments (1 mark, 4 marks, 5 marks).

1.0.3 Instructions:

1. Write your Python code in place of “your code here” placeholder below. 2. Run your code by clicking on ’run’ cell in the toolbar before you submit. 3. You will get the feedback once you submit the assignment.

Step 1: Create a Node A node represents the x and y position of a pixel and it’s neighbours.

In [2]: class Node:
def __init__(self, x, y):

                self.x = x
                self.y = y
                self.neighbours = list()

Step 2: Create an Image The image with 0 and 1 data, the 0 represents the black pixels and the 1 represents the white pixels.

In [3]: image = [
[1,0,0,0,0,1,1],
[1,1,0,1,0,1,0],
[0,1,1,1,0,1,0],

]

Step 3: Implement the flood fill algorithm

Write the flood fill algorithm using breadth first

[0,1,1,1,1,1,0],
[0,1,1,0,1,0,0],
[0,1,1,0,1,0,0],
[0,1,1,1,1,1,1],

search.
The flood fill algorithm is an algorithm used determine the area connected to a given point in

an image that has a similar color. It starts from a specified seed point and floods outwards. Variables of interest:
The explored variable is a set, meaning that only unique values can be inserted into the data structure.
The queue variable is a list, but treated as a queue, meaning that the element removed from the queue was the first element added.

In [4]: class Graph: explored = set()

def floodFill(self, image, x, y, pixel): start = Node(x, y)

queue = list()
queue.append(start)
# Remember to add the x and y coordinates of newly discovered nodes to the expl

                ###
                ### YOUR CODE HERE
                ###
                # Return the modified image represented as a 2D array of numbers

return image

def neighbours(self, image, x, y, currentNode): U=y-1

D=y+1 L=x-1 R=x+1

# An edge is valid if the pixel is newly discovered, i.e. an edge is created wh
                # Write the neighbours function to find the neighbours in four directions for a
                # Append a valid Node to the neighbours of the currentNode
 # Remember to do boundary checking
                ###
                ### YOUR CODE HERE
                ###
                # Return the current node's (the pixel in question) neighbours, not always a ma

return currentNode.neighbours

Step 4: Definition of the start function Drives the graph and executes the flood fill algorithm.

In [5]: def start():

            # Sample image represented as 2D array of numbers

graph = Graph() print(graph.floodFill(image, 2, 2, 2)) # DO NOT REMOVE THE RETURN STATEMENT! return graph

Step 5: Call the start function By calling the start function, the function returns the graph and its properties.

This is useful to debug your algorithm.

In [6]: graph = start()

In [7]: ###
### AUTOGRADER TEST – DO NOT REMOVE ###

In [8]: ###
### AUTOGRADER TEST – DO NOT REMOVE ###

In [9]: ###
### AUTOGRADER TEST – DO NOT REMOVE ###

1.1 Programming Part 2: Create an AI History/Definition knowledge-based system

1.1.1 Assessment task:

Write a programme that accesses an AI knowledge base to search for facts based on the user’s input. There are 4 steps involved, you will complete the code for steps 1 and 4 only.

1.1.2 Marks:

This part is worth 10 Marks. This part is divided into three assessments (3 marks, 3 marks, 4 marks).

1.1.3 Instructions:

1. Write your Python code in place of “your code here” placeholder below. 2. Run your code by clicking on ’run’ cell in the toolbar before you submit. 3. You will get the feedback once you submit the assignment.

Step 1 Read through the AI text book for this course and gather facts for the AI knowledge-based system.

  1. Write at least five about either the history or provide definition in regards to Artificial Intel- ligence.
  2. At least one fact needs to integer number, at least one fact needs to string and at least one fact needs to a list.
  3. One fact needs to be defined as ’turing-ai-publish-year’ i.e. what year did Alan Turing pub- lished his seminal paper (Check module 1).

In [1]: # What you need to do
# 1. Write at least five about either the history or provide definitions in regards to # 2. At least one fact needs to be an integer number, at least one fact needs to be a s # 3. One fact needs to be defined as ‘turing-ai-publish-year’ i.e. what year did Alan T # (Check module 1)

facts = { ###

            ### YOUR CODE HERE

###

}

Step 2

Applications runs only while the running variable is ’true’ which is written below.

In [2]: running = True
Step 3 The below code delivers a friendly message to the user by printing ’Hi, I’m an AI His-

tory/Definition Knowledge based system’.

In [3]: print(“Hi, I’m an AI History/Definition Knowledge based system\n”)

Step 4 Write the code to a.

Ask the user to enter his/her facts that may or may not be in the facts (the system should be able to handle inquiries that are not in the facts database). b. After getting the user-input, write the code to match the facts with the knowledge base that was defined above for three steps 1. c. Inform the user about the identified fact and report back the findings.