summaryrefslogtreecommitdiffstats
path: root/hw1/main.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2015-09-23 10:28:42 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2015-09-23 10:29:24 -0400
commitfb90afefbf3e6d10164a4c1a496e71a688e600f0 (patch)
tree243770c9e9ce42833ba94a62a901c3f0525cad16 /hw1/main.py
parent33467ad66f8ff3000d157ab9ad0022cf96b2143a (diff)
downloadcs281-fb90afefbf3e6d10164a4c1a496e71a688e600f0.tar.gz
[hw1] Reporting results
Diffstat (limited to 'hw1/main.py')
-rw-r--r--hw1/main.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/hw1/main.py b/hw1/main.py
index 3813fa7..ae48050 100644
--- a/hw1/main.py
+++ b/hw1/main.py
@@ -53,11 +53,11 @@ def train_qr(X, y):
def log_posterior(w, X, y, sigma=1.0, tau=10):
return (1 / (2 * sigma) * np.linalg.norm(y - np.dot(X, w)) ** 2
- + 1 / (2 * tau) * np.linalg.norm(w) ** 2)
+ + tau / 2 * np.linalg.norm(w) ** 2)
def gradient(w, X, y, sigma=1.0, tau=10):
- return (- 1 / sigma * np.dot(X.T, y - np.dot(X, w)) + 1 / tau * w)
+ return (- 1 / sigma * np.dot(X.T, y - np.dot(X, w)) + tau * w)
def verify_gradient(eps=1e-10):
@@ -88,9 +88,7 @@ def train_lbfgs(X, y):
options={'maxiter': 100}).x
-def map_features(X, d):
- A = np.random.normal(0, 1, size=(d, X.shape[1]))
- b = np.random.uniform(0, 2 * pi, d)
+def map_features(A, b, X):
return np.cos(np.dot(A, X.T).T + b)
@@ -110,8 +108,10 @@ if __name__ == "__main__":
lqr = []
llbfgs = []
for d in [100, 200, 400, 600]:
- X = map_features(X_train, d)
- X_t = map_features(X_test, d)
+ A = np.random.normal(0, 1, size=(d, X_train.shape[1]))
+ b = np.random.uniform(0, 2 * pi, d)
+ X = map_features(A, b, X_train)
+ X_t = map_features(A, b, X_test)
t_start = time.time()
wqr = train_qr(X, y_train)