-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
64 lines (46 loc) · 1.47 KB
/
utils.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import math
import pandas as pd
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import pickle
def load_dataset(args):
f = open("Dataset/" + args.robotModel + ".pkl","rb")
data = pickle.load(f)
f.close()
if args.isRotation:
W = data[:,4:]
else:
W = data[:,4:7]
if args.robotModel == "Static":
minTension = 5
maxTension = 15
else:
minTension = 310
maxTension = 340
T = data[:,:4]
T = normalize_tension(T,minTension,maxTension)
T_train,T_test,W_train,W_test = train_test_split(T,W,test_size=0.15,random_state=0)
return T_train,T_test,W_train,W_test
def cost(y_test,y_pred):
'''
Calculates error of the model
'''
error = (y_test-y_pred)/y_test
error = np.sum(abs(error))/(y_test.shape[0]*y_test.shape[1])*100
return error
def rmse(y_test,y_pred):
error = np.sum((y_test-y_pred)**2)
error = error/(y_test.shape[0]*y_test.shape[1])
error = math.sqrt(error)
return error
def errorMagnitude(y_true,y_pred):
minMag = min([min(abs(i)) for i in y_true-y_pred])
maxMag = max([max(abs(i)) for i in y_true-y_pred])
return (minMag,maxMag)
def normalize_tension(tension,minTension,maxTension):
z = (tension - minTension)/(maxTension-minTension)
return z
def denormalize_tension(tension,minTension,maxTension):
z = tension*(maxTension-minTension) + minTension
return z