Skip to content

Instantly share code, notes, and snippets.

@syadlowsky
Created November 30, 2018 22:53
Show Gist options
  • Save syadlowsky/dd1d95e1754f3760f3d989e36c7c1e70 to your computer and use it in GitHub Desktop.
Save syadlowsky/dd1d95e1754f3760f3d989e36c7c1e70 to your computer and use it in GitHub Desktop.
SIGMA = args.sigma
NUM_RAND_FEATURES = args.num_rand_features
data_hdf5 = h5py.File(args.filename,'r+')
d = data_hdf5['train']['x'][0].shape[0]
n = len(data_hdf5['train']['x'])
train_y = np.array(data_hdf5['train']['t'])
features = np.array(data_hdf5['train']['x'])
scaler_raw = preprocessing.StandardScaler().fit(features)
features = scaler_raw.transform(features)
rand_featurizer = np.random.randn(d, NUM_RAND_FEATURES)
rand_offsetter = 2*np.pi*np.random.rand(NUM_RAND_FEATURES)
print(np.histogram(np.abs(SIGMA * features.dot(rand_featurizer))))
features = np.sin(SIGMA * features.dot(rand_featurizer) + rand_offsetter[np.newaxis,:])
train_x = features
print(train_y.shape)
soln = train_x.T.dot(scipy.linalg.solve(train_x.dot(train_x.T), train_y, sym_pos=True))
print(np.mean(np.abs(train_x.dot(soln) - train_y)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment