From fb90afefbf3e6d10164a4c1a496e71a688e600f0 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 23 Sep 2015 10:28:42 -0400 Subject: [hw1] Reporting results --- hw1/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'hw1/main.py') 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) -- cgit v1.2.3-70-g09d2