updating week 39

This commit is contained in:
mhjensen
2020-09-25 06:37:00 +02:00
parent 7d18cc5cf6
commit 1d3281d7a2
8 changed files with 60 additions and 24 deletions
+10 -4
View File
@@ -876,11 +876,17 @@ x = 2*np.random.rand(n,1)
y = 4+3*x+np.random.randn(n,1)
X = np.c_[np.ones((n,1)), x]
# Hessian matrix
H = (2.0/n)* X.T @ X
# Get the eigenvalues
EigValues, EigVectors = np.linalg.eig(H)
print(EigValues)
beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y
print(beta_linreg)
beta = np.random.randn(2,1)
eta = 0.1
eta = 1.0/np.max(EigValues)
Niterations = 1000
for iter in range(Niterations):
@@ -968,10 +974,10 @@ import sys
# the number of datapoints
n = 100
x = 2*np.random.rand(m,1)
y = 4+3*x+np.random.randn(m,1)
x = 2*np.random.rand(n,1)
y = 4+3*x+np.random.randn(n,1)
X = np.c_[np.ones((m,1)), x]
X = np.c_[np.ones((n,1)), x]
XT_X = X.T @ X
#Ridge parameter lambda