Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Todos with numerations to the first part #9

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/pegel_bonn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
day, month, year = ts_date.split(".")
hour, minute = ts_time.split(":")
datetime_list.append(datetime(int(year), int(month), int(day)))
if hour == " 04" or hour == " 05":
keep_indices.append(idx)

# 2.3.0
# uncomment to start in the year 2000.
# levels = levels[:-30_000:4]
# datetime_list = datetime_list[:-30_000:4]
Expand All @@ -37,3 +40,42 @@
plt.ylabel("Water level [cm]")
plt.title("Rhine water level in Bonn")
plt.show()

# 2.1 Regression

# 2.1.1 Set up the point matrix for n=2
# The corresponding function that you have implemented in Part 1 has already been imported and is ready to use!

# 2.1.2 Estimate the coefficients

# 2.1.3 Evaluate the straight line and plot your result

# 2.1.4 Calculate the data where the Rhine will be dried out



# 2.2 Fitting a higher-order Polynomial

# 2.2.1 Take a look at the datetime_stamps and scale the axis

# 2.2.2 Set up the point matrix with n=20

# 2.2.3 Compute the coefficients for the polynomial

# 2.2.4 Evaluate the polyomial

# 2.2.5 Plot the results



# 2.3 Regularization

# 2.3.0 Uncomment the lines of code above

# 2.3.1 Compute the SVD of the point-matrix for n=20

# 2.3.2 Compute the filter matrix

# 2.3.3 Estimate the coefficients by applying regularization

# 2.3.4 Plot the evaluated, regularized polynomial
58 changes: 55 additions & 3 deletions src/regularization.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,69 @@ def set_up_point_matrix(axis_x: np.ndarray, degree: int) -> np.ndarray:
np.ndarray: The polynomial point matrix A.
"""
mat_a = np.zeros((len(axis_x), degree))
# TODO implement me!
# TODO 1.1.1 implement me!
return mat_a


if __name__ == "__main__":
b_noise_p = pandas.read_csv("./data/noisy_signal.tab", header=None)
b_noise = np.asarray(b_noise_p)
b_noise = np.asarray(b_noise_p) # This is the artificial data we work with

x_axis = np.linspace(0, 1, num=len(b_noise))

plt.plot(x_axis, b_noise, ".", label="b_noise")
plt.show()

# TODO put your code here!
# TODO put your code for Part 1 here!

# 1.1 Regression

# 1.1.2 Create the point-matrix A for n=2

# 1.1.3 Calculate the estimated coefficients for the polynomial
# You can use np.linalg.pinv to compute the Pseudo-Inverse

# 1.1.4 Plot the original data as well as the estimated polynomial by evaluating it.



# 1.2 Higher order Polynomial

# 1.2.1 Create the point-matrix A for n=300

# 1.2.2 Calculate the estimated coefficients for the polynomial

# 1.2.3 Plot the original data as well as the estimated polynomial by evaluating it.



# 1.3 Regularization

# 1.3.1 Compute the SVD of A

# 1.3.2 Compute the filter matrix

# 1.3.3 Estimate the coefficients by applying regularization

# 1.3.4 Plot your results

#----------------------------------------------------------------------------------------#
# Optional Task 1.4 Model Complexity

# For every degree from 1 to 20:

# 1.4.1 Set up the point matrix for the current degree

# 1.4.2 Estimate the coefficients for the polynomial via the pseudoinverse

# 1.4.3 Compute the predictions by evaluating the estimated polynomial at the x-values

# 1.4.4 Compute the MSE between the predictions and the original b-values

# 1.4.5 Plot the MSE-error against the degree

# 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
# Estimate the optimal degree of polynomial and fit the polynomial with this new degree
# --> so perform the usual steps but only once with the optimal degree

# Plot the result
Loading