Question

Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold)

Please do not use 'print' or 'input' statements.

Context of the assignment is:

In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below:

We need to consider the following cases:

Case 1 - It is possible that the given data series is shorter than the given pattern, in this case, we return "Insufficient data".

Case 2 - All the similarity measures are (strictly) less than the given threshold value. This means none of the segments is similar to the given pattern. In this case, we say the pattern is not present in the data series and return "Not detected". This is not the case for the example just outlined.

Case 3 - At least one similarity measure is greater than or equal to the given threshold value. This is the case for the example outlined. The similarity measure plot above shows that the fifth similarity measure is the largest. You can work out that the fifth similarity measure is computed by using the segment formed by the fifth (index 4) to eighth (index 7) data points of the data series. This procedure is therefore telling us that the segment consisting of fifth to eighth data points is most similar to the given pattern. Indeed, this is what we had found by using visual inspection earlier. We will identify the location of the pattern by using the first index of the segment that has the highest similarity measure.

I will need to implement the following four functions, each in a separate file (provided). For this question I’m looking at getting start on function 3: def pattern_search_max(data_series, pattern, threshold). Numpy can be used if needed.

The 4 functions will be:

def calculate_similarity(data_segment, pattern):

def calculate_similarity_list(data_series, pattern):

def pattern_search_max(data_series, pattern, threshold):

def pattern_search_multiple(data_series, pattern_width, threshold):

function 3: def pattern_search_max(data_series, pattern, threshold), is described as:

• The three possible outcomes are "Insufficient data", "Not detected" and the location of the pattern if the pattern is found in the data series. Here, the location of the pattern refers to the index of the highest similarity measure that is also greater than or equal to the given threshold value.
• The first parameter 'data_series' is a list of (float) values, the second parameter 'pattern' is a list of (float) values, and the third parameter 'threshold' is a (float) value. In this function, you need to use the function 'calculate_similarity_list'.

I have completed the code for function 1 (def calculate_similarity) and function 2 (def calculate_similarity_list)… and part of the pseudo-code for function 3, and would like some help to complement this… the code is as follows:

# function 1

data_segment = []

pattern = []

def calculate_similarity(data_segment, pattern):

if len(pattern) is not len(data_segment):

m='error'

else:

m=0

for z in range(0,len(data_segment)):

m = m + data_segment[z]*pattern[z]

return m

# function 2

def calculate_similarity_list(data_series, pattern):

output=[]

for y in range(len(data_series)-len(pattern)+1):

result=calculate_similarity(data_series[y:y+len(pattern)], pattern)

output.append(result)

return output

#function 3 - pseudo-code

def pattern_search_max(data_series, pattern, threshold):

""" Search for the highest similarity measure that is also greater than

or equal to the given threshold value and returns the index of that

value.

The function finds the index of the highest similarity value,

using the similarity_list returned by the function

'calculate_similarity_list'.

Parameters

----------

data_series : [float]

A list of float values representing a data series.

pattern : [float]

A list of float values representing the pattern.

threshold : [float]

A float value. Selected similarity measure needs to be greater than or

equal to the given threshold value.

Returns

-------

"Insufficient data" : [String]

If the given data_series is shorter than the given pattern.

"Not detected" : [String]

If all the similarity measures are (strictly) less than the given

threshold value.

float

Index of the highest similarity measure that is also greater than

or equal to the given threshold value.

"""

def pattern_search_max(data_series, pattern, threshold):

result = 0

if len(data_series) < len(pattern):

result = 'Insufficient data'

else:

for k in range(0,len(csl.calculate_similarity_list(data_series, pattern))-1):

if k >= threshold and k >result:

result = k

elif k < threshold:

result = 'Not detected'

return result

The pattern detection problem In this assignment, your goal is to write a python program to determine whether a given pattern appears in a data series, and it so, where it is located in the data series. This type of problems is science, engineering, medicine and science. There are many different types of patten detection problems, the setting of this assignment in radars. A radar transmits a pulse of a specific shape and waits for a pulse of similar shape to return, in order to determine the position of an is known as matched filtering and is widely used in communication systems. This means your mobile phones perform the same type of calculations that you wil be programming below objoct. The method describecd Learning objectives By completing this assignment, you will learn: 1. To apply programming concepts of variable declaration, constant declaration, assignment, selection and iteration (for loop) 2. To translate an algorithm described in a natural language to a computer language 3. To organize programs into smaller modules by using functions 4. To use good program style including comments, meaning variable names and others 5. To get a practice on software development, which includes incremental development, testing and debugging Algorithm for locating a pattern in a data series rs in the data series. In the following example, the pattern to be detected is a sequence of 4 numbers (see Fig 2) and the data serie contains 10 data points (see Fig 1) 22, 10, 1, 3 pattern (40, 30, 20, 10) Fig 2 Patterm Fig 1: Data Senies 50 se
h fig 1: Data Series Fig 2: Pattem 50 20 10 a0 If you compare these two figures, you can see that this pattern appears between 5th (at index4) to 8th (at index 7) data points of the data senies. Note that it is not an exact maich but a farly close one. Now you can spot the pattern using your eyes, let us see how an algorithm can do i Since the given pattern has 4 data points, we will take a segment of 4 consecutive data points from the data series at a time and compute a simlarity measure. The similarity measure shoud have the property that if a segment of the data series is similar to the given pattern, then the simlarity measure of that segment is large, and vice versa Hence, if we can compute the simlarity measures of all possible segments, then we can identify the segment that is most similar to the given pattern. We wll now provide more details and the frst segment, which is formed by the first 4 data points of the data series. In terms of the two lists The algorithm begins with computing the similarity measure between the given pattern above, the similarity measure for the first segment is data serieste)'pattern(e] . data series(1) patternt)+ data, series 21 patternt2) data seriestal pattern(3) Atfer tis, we compute the simlarity measure between the given patrn and the second segment, which is formed by the second to fith data points of the the similarity measure for this segment is data, series (4]'pattern(3) ern(2) data series[11 patternte] + data series(21 pattern[11 data series([3) patt We then do the same with the segment formed by the third to sixth data points(the third segment), gving a similiarity measure equals to terntt) data,series(41'oatten2) data seriest51'patternt) d data,series12) patternte) data series(3]"pa the smaarity measure for the last possible segment, which isformed by the 7th to 10th data port. The Ilwing-re·mlary list for the abon and a plot

Here's your #function 3 working as mentioned...

def pattern_search_max(data_series, pattern, threshold):

result = -1 #Stores the index of the segment which results in highest similarity

prev_max_value = -1 #Stores the highest similarity till now

if len(data_series) < len(pattern): #Not enough data

result = 'Insufficient data'

else:

similarity_list = calculate_similarity_list(data_series, pattern) #Returns a list containing all the similarity values for every segment

for i in range(0,len(similarity_list)):

if similarity_list[i] >= threshold and similarity_list[i] > prev_max_value: #If similarity is greater than threshold and also greater than the previous similarity obtained then store the current index as result and update prev_max_value

result = i

prev_max_value = similarity_list[i];

if result == -1: After the loop ends if result is still -1 then it is clear that none of the obtained similarity surpasses the threshold hence pattern is not detected

result = 'Not detected'

return result

#HOPE IT HELPS....

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
• ### Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignme...

Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...

• ### Coding for Python – don’t need it to be complex: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is locate...

Coding for Python – don’t need it to be complex: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. This type of problem is common in many health disciplines. For example, identifying treatment pathways. The goal is to detect whether a certain pattern appears in the data series. In the following example, the pattern to be...

• ### I have to follow functions to perform: Function 1: def calculate_similarity(data_segment, pattern): The aim of this func...

I have to follow functions to perform: Function 1: def calculate_similarity(data_segment, pattern): The aim of this function is to calculate the similarity measure between one data segment and the pattern. The first parameter 'data_segment' is a list of (float) values, and the second parameter 'pattern' is also a list of (float) values. The function calculates the similarity measure between the given data segment and pattern and returns the calculated similarity value (float), as described earlier in this assignment outline. The...

• ### python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you...

python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you are given only accepts two number parameters and produces a float value. It is your job to figure out what mathematical operation the function you are given is performing by passing it many different parameters. The possible operations the function can perform are: add, subtract, multiply, and divide. The given function will only perform a single operation, it will not change after consecutive invocations....

• ### Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of...

Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plot the points to see the structure. Please complete the following function: def sierpinski (po, v, f, inum) The four arguments are ·po the initial point. You may assume this is the origin, i.e., po = [0, 0] . v:...

• ### I really need help with this python programming assignment Program Requirements For part 2, i need...

I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n):   lst = []   for i in range(1,n+1):     val = float(input('Enter float '+str(i)+': '))     lst.append(val)   return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...

• ### # Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sV...

# Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sVal + str(tree.getRootVal()) sVal = sVal + printexp(tree.getRightChild())+')' return sVal #### Functions and classes to help with Homework 6 #### You should not make any changes to the functions and classes in this file, #### but you should understand what they do and how they work. import sys ### This function will be re-defined in hw6.py. However, it is needed for ExpTree, ###...

• ### please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each...

please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available...

• ### Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word)...

Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word) To run the function modify() defined above, we make the following call: result = modify('course', 's') Find and fix the errors in the function definition, lines (1) to (4), such that after the call is executed: • Variable result has the value 'courses' • 'new word is courses' is printed out. For each error found and fixed, you must indicate the following: • line...