@@ -24,17 +24,69 @@ def set_up_point_matrix(axis_x: np.ndarray, degree: int) -> np.ndarray:
24
24
np.ndarray: The polynomial point matrix A.
25
25
"""
26
26
mat_a = np .zeros ((len (axis_x ), degree ))
27
- # TODO implement me!
27
+ # TODO 1.1.1 implement me!
28
28
return mat_a
29
29
30
30
31
31
if __name__ == "__main__" :
32
32
b_noise_p = pandas .read_csv ("./data/noisy_signal.tab" , header = None )
33
- b_noise = np .asarray (b_noise_p )
33
+ b_noise = np .asarray (b_noise_p ) # This is the artificial data we work with
34
34
35
35
x_axis = np .linspace (0 , 1 , num = len (b_noise ))
36
36
37
37
plt .plot (x_axis , b_noise , "." , label = "b_noise" )
38
38
plt .show ()
39
39
40
- # TODO put your code here!
40
+ # TODO put your code for Part 1 here!
41
+
42
+ # 1.1 Regression
43
+
44
+ # 1.1.2 Create the point-matrix A for n=2
45
+
46
+ # 1.1.3 Calculate the estimated coefficients for the polynomial
47
+ # You can use np.linalg.pinv to compute the Pseudo-Inverse
48
+
49
+ # 1.1.4 Plot the original data as well as the estimated polynomial by evaluating it.
50
+
51
+
52
+
53
+ # 1.2 Higher order Polynomial
54
+
55
+ # 1.2.1 Create the point-matrix A for n=300
56
+
57
+ # 1.2.2 Calculate the estimated coefficients for the polynomial
58
+
59
+ # 1.2.3 Plot the original data as well as the estimated polynomial by evaluating it.
60
+
61
+
62
+
63
+ # 1.3 Regularization
64
+
65
+ # 1.3.1 Compute the SVD of A
66
+
67
+ # 1.3.2 Compute the filter matrix
68
+
69
+ # 1.3.3 Estimate the coefficients by applying regularization
70
+
71
+ # 1.3.4 Plot your results
72
+
73
+ #----------------------------------------------------------------------------------------#
74
+ # Optional Task 1.4 Model Complexity
75
+
76
+ # For every degree from 1 to 20:
77
+
78
+ # 1.4.1 Set up the point matrix for the current degree
79
+
80
+ # 1.4.2 Estimate the coefficients for the polynomial via the pseudoinverse
81
+
82
+ # 1.4.3 Compute the predictions by evaluating the estimated polynomial at the x-values
83
+
84
+ # 1.4.4 Compute the MSE between the predictions and the original b-values
85
+
86
+ # 1.4.5 Plot the MSE-error against the degree
87
+
88
+ # 1.4.6 Take a look at the graph with all 20 MSE's and see if there is a link between degree and MSE
89
+ # Estimate the optimal degree of polynomial and fit the polynomial with this new degree
90
+ # --> so perform the usual steps but only once with the optimal degree
91
+
92
+ # Plot the result
0 commit comments