-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevaluation.py
44 lines (34 loc) · 1.17 KB
/
evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
############# UTILS ##############
def execute(fn_str, v0):
"""Function string must take in specific variable names v0 as input and result as output."""
ll = locals()
exec(fn_str, globals(), ll)
return ll["v0"]
def test(fn_str, input_array, test_array, n=100):
output_array = []
input_array = input_array[:n]
test_array = test_array[:n]
for v0 in input_array:
result = execute(fn_str, v0)
# print(result)
output_array.append(result)
# print(output_array)
error = np.sum(np.absolute(np.subtract(output_array, test_array)))
return output_array, error
def test_loop(fn_arr, input_array, test_array, n=100):
error_arr = []
input_array = input_array[:n]
test_array = test_array[:n]
for fn_str in fn_arr:
_, error = test(fn_str, input_array, test_array, n=n)
error_arr.append(error)
return error_arr
############# TEST SEQUENCES ##################
n = 100
index = [i for i in range(n)]
increment_one = [i for i in range(n)]
increment_two = [i*2 for i in range(n)]
fib = [0,1]
for i in range(n-2):
fib.append(fib[i] + fib[i+1])