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 function returns "Error" if 'data_segment' and 'pattern' have different lengths.
Function 2: def calculate_similarity_list(data_series, pattern), is described as:
The aim of this function is to calculate the similarity measures between all possible data segments and the pattern.
The first parameter 'data_series' is a list of (float) values, and the second parameter 'pattern' is also a list of (float) values. The function calculates the similarity measures, using the above function 'calculate_similarity', of all possible data segments in a sequence, and returns the list of calculated similarity values.
I have the following code for this. My first function tests fine, but my second function is hitting an issue:
![data_segment [] pattern def calculate_similarity(data_segment, pattern): if len(pattern) is not len (data_segment): m- error](http://img.homeworklib.com/images/fc04971b-ecc9-4b81-9830-836578192d10.png?x-oss-process=image/resize,w_560)
The test series I have, and the expected answer, I should get is below:
data_series = [-1, 2, -2, 3, 41, 38, 22, 10, -1, 3]
pattern = [40, 30, 20, 10]
print(calculate_similarity_list(data_series,pattern))
# expected_answer = [56, 34, -1.02, 219.34, -123.1, 179.8]
But I get:
![In [8]: def calculate_similarity_list(data_series, pattern): data-segment [] #create empty data-segment results[] #create emp](http://img.homeworklib.com/images/a029ef51-03d4-4456-a83c-6aa34ca3b9fc.png?x-oss-process=image/resize,w_560)
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
# Test function 1
data_segment = [-1, 2, -2, 3]
data_segment = [float(x) for x in data_segment]
pattern = [40, 30, 20, 10]
pattern = [float(x) for x in pattern]
print(calculate_similarity(data_segment,pattern))
# expected_answer = 10
# answer = 10
def calculate_similarity_list(data_series, pattern):
data_segment = [] # create empty data_segment
result = [] # create empty result list
if len(data_series) < len(pattern):
result.append('Insufficient
Data')
else:
for i in range(0,len(data_series) -
len(pattern) + 1):
for j in
range(i,i+len(pattern)):
data_segment.append(data_series[j])
# there seems to be indentation error in this line, it
was wriiten inside for loop, size of data_segment was always 1
which was not equal to size of pattern hence always
error
result.append(calculate_similarity(data_segment,pattern))
data_segment.clear()
return result
data_series = [-1, 2, -2, 3, 41, 38, 22, 10, -1, 3]
data_series = [float(x) for x in data_series]
pattern = [40, 30, 20, 10]
pattern = [float(x) for x in pattern]
print(calculate_similarity_list(data_series,pattern))
# expected_answer = [56, 34, -1.02, 219.34, -123.1, 179.8]
I am still not able to get the expected answer, please work out and tell how did you got this expected answer
I am getting [10.0, 490.0, 1210.0, 2330.0, 3320.0, 2370.0, 1190.0]
which you can verify:
(-1 * 40) + (2*30) + (-2*20) + (3*10) = 10
(2*40) + (-2 * 30) + (3*20) + (41*10) = 490 and so on
I have to follow functions to perform: Function 1: def calculate_similarity(data_segment, pattern): The aim of this func...
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...
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...
2. Consider the following function # listOfNumbers is a list of only numbers # def processList(listOfNumbers): result = [] for i in listOfNumbers: if i<0 == 0: result.append(i*i) else: result.append((i*i)+1) return result First, study and test processList(listOfNumbers) to determine what it does Then rewrite its body so that it accomplishes the same task with a one-line list comprehension. Thus, the resulting function will have exactly two lines, the def line and a return line containing a list comprehension expression. 3....
BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the highest odd value in the list (consumes a list of numbers and returns a number). Use the provided helper function is_odd (that consumes a single number and returns a boolean indicating whether it is true or false). Do not change the helper function is odd. Call your maximum_odd function on your favorite list of numbers Console Feedback: Instructor Feedback You cannot use the builtin...
this is the function and here's what I did for this
function but there is an error showing saying nonetype does not
have type len() because math.ceil function (we cannot import any
math..) for this function in python, if you could help me with this
code.
thanks
gerer grodpugu def slice_list(1st: List(Any) ni int) -> List[List[Any]]: Return a list containing slices of <st> in order. Each slice is a List of size <n> containing the next <n> elements in <tst>....
2D Lists + File I/O In a comma-separated input file named results.txt, you have been given the following information that records the weekly (movie) box office sales for 5 movies. A sample input file will include the following. The movie’s title is listed first, then its sales (in million dollars) for 7 days are listed. Avengers,169.1,125.8,101.7,40.5,38.2,24.2,55.7 Shazam!,8.6,14.1,8.2,7.3,31.4,44.2,26.8 Breakthrough,14.8,16.1,18.0,18.9,19.8,21.8,24.6 The Best of Enemies,4.7,5.4,5.8,6.1,6.7,7.6,8.1 Dumbo,9.9,14.8,9.0,7.9,40.6,52.5,36.3 Write a complete Python program that includes code to do the following: read in the data from...
Copy the following Python fuction discussed in class into your file: from random import * def makeRandomList(size, bound): a = [] for i in range(size): a.append(randint(0, bound)) return a a. Rename the function sumList as meanList and modify it so that it finds the average of the list. The average is the sum divided by the size (len) of the list. Make sure that the function doesn't give you an error when it is called on an empty list. The...
[Python] I have the following function that removes all non-numerical characters from a string: def remove_non_numeric(s): seq_type= type(s) return seq_type().join(filter(seq_type.isdigit, s)) And I need help implementing it into this function: def list_only_numbers( a_list ) : # Create a new empty list. # Using a loop (or a list comprehension) # 1) call remove_non_numeric with a list element # 2) if the return value is not the empty string, convert # the string to either int or float (if it contains...
Determine the Big-O value for the following functions. The valid Big-O options are: 'O(1)' 'O(N)' 'O(LOG2(N))' 'O(N * LOG2(N))' 'O(N^2)' 'O(inf)' # This is Big-O of infinity def function_one(list_): for pass_ in range(len(list_) - 1, 0, -1): for i in range(pass_): if list_[i] > list_[i+1]: temp = list_[i] list_[i] = list_[i+1] list_[i+1] = temp def function_two(list_): if len(list_) > 1: midpoint_index = len(list_) // 2 left_half = list_[:midpoint_index] right_half = list_[midpoint_index:] function_two(left_half) function_two(right_half) left_half_pos = 0 right_half_pos = 0 new_position...