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 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 2: def calculate_similarity_list(data_series, pattern).
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 2: def calculate_similarity_list(data_series, pattern), is described as:
I have completed the code for function 1 (def calculate_similarity)… and would like some help to complement this… my code for def calculate_similarity is as follows:
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
The seudo-code to start function 2 is as per below:
def calculate_similarity_list(data_series, pattern):
""" Calculate the similarity measures between all possible data segments
and the pattern.
The function calculates the similarity measures, using the
function 'calculate_similarity', of all possible data segments in a
data_series against a given pattern and returns the list of calculated
similarity values.
Parameters
----------
data_series : [float]
A list of float values representing a data series.
pattern : [float]
A list of float values representing the pattern.
Returns
-------
List of floats
The list of calculated similarity values.
"""
# Insert your code here.
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):
data_segment=[] #create empty data_segment
result=[] #create empty result list
if len(data_series) < len(pattern): #if length is not sufficient
then return insufficient
result.append('Insufficient Data')
else:
for i in range(0,len(data_series)-len(pattern)+1): #now take index
from 0 to starting index of last data_segment
for j in range(i,i+len(pattern)): #iterate through all the index of
data_segment
data_segment.append(data_series[j]) #now add elements one by one to
data_segment
result.append(calculate_similarity(data_segment,pattern)) #it adds
values one by one
data_segment.clear() #it clears the list
return result
#testing function 2
data_series=[-1,2,-2,3,41,38,22,10,-1,3]
pattern=[40,30,20,10]
print(calculate_similarity_list(data_series,pattern))
OUTPUT-
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 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...
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...
Here is the code given for this problem: **And please do this in Python** def mergesort(mlist): if len(mlist)<2: return mlist else: mid=len(mlist)//2 return merge(mergesort(mlist[:mid]),mergesort(mlist[mid:])) Problem 1 (30 points) stable merge sort Consider the following unsorted list of integers containing duplicates where the relative position of each duplicated integer in the unsorted list is noted as a subscript. For example, 1, is at a smaller index than 12. The subscript is ignored when comparing two values since it would not actually...
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...
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...
Python coding exercise: please include comments Goal #1: import financial data given into your program provided to you as a CSV formatted text file Use the following data for testing (the following is only a sample of the data; there are over 4000 rows of data): *Note: The data you will read in is linear by date (but, non-contiguous due to holidays and weekends,) reflecting a timeline of stock performance in chronological order; however your program should run through the...
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,...
PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the map referred to is pictured in the screenshot. Need help with these 4 tasks: Function 4: def is_map(map) : given a map (see screenshot), does it meet the following criteria? 1) it is a list of lists of values of type int; 2) it has at least one row and one column; 3) it’s rectangular (all sub-lists are same length); 4) only non-negative ints...
solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . . . 1"} with weight {w1·W2. . . . . ux) and value (n 2, .., nJ, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity In this question, we will consider two different ways to represent a solution to the...