-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlotHeuristic.py
More file actions
78 lines (65 loc) · 2.19 KB
/
PlotHeuristic.py
File metadata and controls
78 lines (65 loc) · 2.19 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import matplotlib.pyplot as plt
import numpy as np
import UtilsNetwork as Utils
from matplotlib import rc
import scipy
rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
rc('text', usetex=True)
SMALL_SIZE = 8
MEDIUM_SIZE = 12
BIGGER_SIZE = 14
#plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes
#plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
def func(x, eps, c):
return x + np.random.normal(c,eps,x.size)
def mpe(eps,c):
return (eps**4 + c**2)**0.5
np.random.seed(42)
x_vec = np.linspace(0,1, 100)
print(x_vec.size)
y_true = func(x_vec, 0,0)
print("Mean True:",np.mean(y_true))
print("Std True:",np.std(y_true))
plt.figure()
plt.grid(True, which="both",ls=":")
y_1 = func(x_vec, 0.01,0.01)
print("\n")
print("Mean 1:",np.mean(y_1))
print("Std 1:",np.std(y_1))
MPE = (np.mean((y_1 - y_true)**2))**0.5
print(MPE,mpe(0.01,0.01))
plt.scatter(x_vec, y_1, lw=1.5)
plt.plot(x_vec, func(x_vec, 0,0), color="k", ls="--")
plt.xlabel(r'True Values')
plt.ylabel(r'Predicted Values')
plt.savefig('../Report/Images/ideal.pdf', format='pdf')
plt.figure()
plt.grid(True, which="both",ls=":")
y_2 = func(x_vec, 0.2,0.01)
print("\n")
print("Mean 2:",np.mean(y_2))
print("Std 2:",np.std(y_2))
MPE = (np.mean((y_2 - y_true)**2))**0.5
print(MPE,mpe(0.2,0.01))
plt.scatter(x_vec, y_2,lw=1.5)
plt.plot(x_vec, func(x_vec, 0,0), color="k", ls="--")
plt.xlabel(r'True Values')
plt.ylabel(r'Predicted Values')
plt.savefig('../Report/Images/same_mean.pdf', format='pdf')
plt.figure()
plt.grid(True, which="both",ls=":")
y_3 = func(x_vec, 0.01,0.2)
print("\n")
print("Mean 3:",np.mean(y_3))
print("Std 3:",np.std(y_3))
MPE = (np.mean((y_3 - y_true)**2))**0.5
print(MPE,mpe(0.01,0.2))
plt.scatter(x_vec, y_3,lw=1.5)
plt.plot(x_vec, func(x_vec, 0,0), color="k", ls="--")
plt.xlabel(r'True Values')
plt.ylabel(r'Predicted Values')
plt.savefig('../Report/Images/same_std.pdf', format='pdf')
plt.show()