Skip to content

Instantly share code, notes, and snippets.

@dusenberrymw
Forked from sergeyf/mdn_harder_data.py
Created December 12, 2017 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dusenberrymw/7977713c95ef56391640f0a118fdc785 to your computer and use it in GitHub Desktop.
Save dusenberrymw/7977713c95ef56391640f0a118fdc785 to your computer and use it in GitHub Desktop.
import numpy as np
# the function
def f_of_x(X, w):
n,d = X.shape
X_dot_w = np.dot(X,w)
y = np.zeros(n)
# the inner product randomly goes through a sin
# or a cos
cos_flag = np.random.randn(n) < 0.0
sin_flag = ~cos_flag
y[cos_flag] = np.cos(X_dot_w[cos_flag])
y[sin_flag] = np.sin(X_dot_w[sin_flag])
return y
# generate some simulated data
n = 2500
d = 1
w = np.random.rand(d)
x_train = np.random.randn(n, d)
y_train = f_of_x(x_train, w)
x_test = np.random.randn(n, d)
y_test = f_of_x(x_test, w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment