Question

In: Computer Science

Problem You have developed an application for the task of registering crop information and have now...

Problem

You have developed an application for the task of registering crop information and have now been given crop data for analysis. The crop data includes the (x, y) coordinates of a robotic weed scanner (or unmanned ground vehicle (UGV) ) as it moves through a crop. Your task is to develop a console based representation of the movement patterns of the robotic scanner. Along side coordinates, the robot has also reported weed classification results for each (x, y) coordinate. The weed identification algorithms is using a lot of resources and for this reason graphics will be avoided in place of a console representation.

The robot is programmed to move on a grid and has an algorithm that converts GPS coordinates into a grid based system. In this scenario the robot will start moving at location (0, 0) and can move 1 space at a time in the x and y dimensions. That is, it can only increment x and/or y by 1 at each step. You will not need to implement this part, a text based data file will be provided to you. Location (0, 0) will be set to the top left hand corner and the grid will be set to a fixed width and height of 10 x 10 units. The text file will contain coordinates on each line with a 3 integer classification result (x, y, R1, R2, R3).  The result will require processing through a single artificial neuron based classifier, the neuron will contain 3 weights to match the 3 integers of the result.

This calculation through the neuron can be expressed:

Class = Round(R1 X W1 + R2 X W2 + R3 X W3)

The calculation should produce a result between 0 and 1, rounding will then produce 1 when the number is greater than 0.5 and 0 if it is below, for this you can use pythons inbuilt round function. Class 1 in this case will be a weed and class 0 will be no weed detected. The round function is being used in place of a step based activation function, typically depicted as g(.).

To complete this task, you will need to develop three functions that process and display the results in a console based grid. The first function will take a file name and return a 10x10 list of lists containing and representing the values from each line of the text file (x, y, R1, R2, R3). This function will be called read_file (described below) and will take 1 parameter (the file name). The result values (R1, R2, R3) will need to be stored as a list as well, this creates what is essentially a list of lists of lists. While this does sound complex, it can be created by appending the list results at each 2 dimensional index of a 2 dimensional list, which can be initialised as an empty list for each potential location in a 10x10 grid. The index will be the x and y values, that is, the first 2 values from each line of the text file.

Example, for a single set of values (1, 1, 4, 9, 1):

coord_results[x][y] = [R1, R2, R3]

or

coord_results[1][1] = [4,9,1]

Where coord_results is a 10x10 list of lists (or 2 dimensional list).

Parameter name Description
file_name String text name of the data file

The second function will be called classify and will take the 3 result values and multiply them by their associated weight value. Using 3 iterations of a loop the values can be added together and rounded to produce a classification result. This function will take two parameters, a 3 float weight list and a 3 integer result. After the calculation the rounded result can be returned as an integer.

Parameter name Description
weights A float list containing 3 weight values
result An integer list containing an individual set of 3 result values

The third function will be called display_results and this function will display the text based grid in the console. A text data file and the expected output is depicted below. The function will print 1 line of the grid at a time in a loop and will require a nested loop to loop through all possible locations in the grid (all x and all y). Inside the nested loops you will need to check a set of conditions. If the index (x,y) has an empty list (meaning the robotic scanner did not pass over it) two spaces will be drawn. If the classify function returns 1 on the result for the coordinate an ' x' will be drawn, otherwise a full stop will be drawn (' .').

Parameter name Description
coord_results A list of lists containing the (x, y, R1, R2, R3) for each line of the text data file
weights A float list containing the 3 weight values

The three weight values that you will need to store in your application are provided below, these weights have been determined using a machine learning method to produce accurate classification.

An example data file is provided below with results displayed.

Note that program specifications are not always clear. If you are uncertain about any aspect, you are typically better off asking than making assumptions. Please use the appropriate discussion forum to ask for clarification, if required.

Example Interactions

Given the following list of weights:

0.03
0.04
0.03

Given the following text file (attached below - crop1.dat):

0 0 5 4 7
1 1 4 9 1
1 2 3 2 7
1 3 6 4 6
2 4 8 2 1
3 5 3 7 2 
4 6 5 7 1 
4 7 6 2 1
5 8 7 2 7
6 9 9 8 6
7 9 1 1 1
8 9 6 2 4
9 9 1 2 8
9 8 6 8 6
8 7 4 5 0
7 6 5 8 6
7 5 8 2 1
7 4 3 2 5
8 3 8 1 3
9 2 1 7 1

Your display output should display the following output.

 x                   
   x . x             
         .           
           .         
             . .     
                 .   
                   x 
         . . x     . 
       .       .   . 
     .           x . 

Solutions

Expert Solution

Screenshot

Program

#Function to create grid from file
def read_file(filename):
    #Create 10*10 grid
    grid = [[0 for _ in range(10)] for _ in range(10)]
    #File open
    file=open(filename)
    #Loop through each line
    for line in file:
        #Split each line
        fields=line.split(' ')
        #Get x and y coordinate in the grid
        x=int(fields[0])
        y=int(fields[1])
        #Result list
        lst=[]
        lst.append(int(fields[2]))
        lst.append(int(fields[3]))
        lst.append(int(fields[4]))
        #Add into grid
        grid[x][y]=lst
    #Return result co-orddinates
    return grid
  
#Function to classify
def classify(weights,results):
    #Variable for calculation
    sum=0
    #Loop through for each value
    for i in range(len(weights)):
        #Equation calculation
        sum+=weights[i]*results[i]
    #Return rounded result
    return round(sum)
#Function to display resulting grid
def display_results(grid,weights):
    #Loop through grid
    for i in range(len(grid)):
        for j in range(len(grid[i])):
            #Check empty grid
            if(grid[i][j]!=0):
                #Otherwise check classify result and display
                if(classify(weights,grid[i][j])==1):
                    print('X',end=' ')
                else:
                     print('.',end=' ')
            #The print empty space
            else:
                print(' ',end=' ')
        print()
#Main function
def main():
    #Initialize weight list
    weights=[0.03,0.04,0.03]
    #Call function to get file data and generated grid
    grid=read_file('crop1.dat')
    #Display grid
    display_results(grid,weights)
#Program start
main()

----------------------------------------------------------------------------

Output

X
X . X
        .
          .
            . .
                .
                  X
        . . X     .
      .       .   .
    .           X .


Related Solutions

You have received the following three payment options for a software application you have developed to...
You have received the following three payment options for a software application you have developed to sell: Option 1 You will receive $1,000,000 now plus $200,000 from year 6 through 15. Also, if the software application did over $100 million in cumulative sales by the end of year 15, you will receive an additional $3,000,000. There is a 70 percent probability this would happen. Option 2 You will receive thirty percent of the buyer’s gross profit on the product for...
You have received the following three payment options for a software application you have developed to...
You have received the following three payment options for a software application you have developed to sell: Option 1 You will receive $1,000,000 now plus $200,000 from year 6 through 15. Also, if the software application did over $100 million in cumulative sales by the end of year 15, you will receive an additional $3,000,000. There is a 70 percent probability this would happen. Option 2 You will receive thirty percent of the buyer’s gross profit on the product for...
Now that you have completed your readings, your task is to assess the impact of sexually...
Now that you have completed your readings, your task is to assess the impact of sexually explicit materials on human sexual behavior. You will need to analyze the following questions, presenting a 2-4 paragraph response for each question: 1. There is generally less violence in sexually oriented material than in mainstream movies and TV crime shows. Why are censorship efforts directed more toward sexually explicit nonviolent material than toward nonsexual violent material? 2. Research has found 82% of students viewing...
Now that you have completed your readings, your task is to assess the impact of sexually...
Now that you have completed your readings, your task is to assess the impact of sexually explicit materials on human sexual behavior. You will need to analyze the following questions, presenting a 2-4 paragraph response for each question: 1. There is generally less violence in sexually oriented material than in mainstream movies and TV crime shows. Why are censorship efforts directed more toward sexually explicit nonviolent material than toward nonsexual violent material? 2. Research has found 82% of students viewing...
Your task is to find the value of a company stock. You have the following information:...
Your task is to find the value of a company stock. You have the following information: a) Investors expect 5 EUR dividend next year. b) Dividends are expected to stay constant for the next four years. c) However, dividends are expected to start growing 5% a year starting from year 5. d) Expected return from investments with comparable risk is 15%. Question: 1. Based on information above, what is the fundamentally justified price of a stock? 2. You observe that...
Your task is to find the value of a company stock. You have the following information:...
Your task is to find the value of a company stock. You have the following information: a) Investors expect 10 EUR dividend next week. Buying stock today entitles you to receive that dividend b) Dividends are expected to stay constant for the next three years. c) However, dividends are expected to start growing 3% a year starting from year 4. d) Expected return from investments with comparable risk is 13%. Question: 1. Based on information above, what is the fundamentally...
You will write a Java Application program to perform the task of generating a calendar for...
You will write a Java Application program to perform the task of generating a calendar for the year 2020. You are required to modularize your code, i.e. break your code into different modules for different tasks in the calendar and use method calls to execute the different modules in your program. Your required to use arrays, ArrayList, methods, classes, inheritance, control structures like "if else", switch, compound expressions, etc. where applicable in your program. Your program should be interactive and...
USING EXCEL Now your task is to plot the cumulative probability density function with the information...
USING EXCEL Now your task is to plot the cumulative probability density function with the information given in number 2. First, open Worksheet #3. Then enter “=” in cell A17 of your new worksheet and then click on cell A17 of your second worksheet and hit return. Then copy cell A17 down the A column as before.               Next, you’re to compute the cumulative probabilities for x = 0, 1, 2, …. 20, beginning in cell B17 and ending in...
You are analyzing the following two projects and have developed the following information. Project A |...
You are analyzing the following two projects and have developed the following information. Project A | Project B Year | Cash flow | Cash flow 0 | -$50,000 | -$50,000 1 | $31,000 | $42,000 2 | $26,000 | $21,000 3 | $27,000 | $18,000 5. What is the crossover rate of the two projects? 6. Project A and B are mutually exclusive. Which project(s) should be chosen if the required return is 8%? Why? 7. Project A and B...
You have been given the task of evaluating and recommending a viable accounting information system for...
You have been given the task of evaluating and recommending a viable accounting information system for the accounting and financial data of your company. As you begin to research this system, you realize that many departments are involved in the information system. You decide that selecting a team to assist you with your research would be the most beneficial approach for the company. This module, you begin your course project by selecting a team to assist you in finding an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT