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:
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
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....
Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Plea...
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 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 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 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 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 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 = 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, ###...
I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...
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) 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...